The following code is in MIPS. How would it be converted into RISC-V?
main:
la $t0, Array # Copy the base address of your array into $t1
add $t0, $t0, 40 # 4 bytes per int * 10 ints = 40 bytes
outterLoop: # Used to determine when we are done iterating over the Array
add $t1, $0, $0 # $t1 holds a flag
la $a0, Array # Set $a0 to the base address of the Array
innerLoop: # The inner loop will iterate
lw $t2, 0($a0) # sets $t0 to the current element in array
lw $t3, 4($a0) # sets $t1 to the next element in array
slt $t5, $t2, $t3 # $t5 = 1 if $t0 < $t1
beq $t5, $0, continue
add $t1, $0, 1
sw $t2, 4($a0)
sw $t3, 0($a0)
continue:
addi $a0, $a0, 4
bne $a0, $t0, innerLoop
bne $t1, $0, outterLoop RISC-V program :-
.text
.global main
main:
push {r4-r10, lr}
mov r1, #10
outterLoop:
mov r10, #0
sub r1, #1 @ Decrement Counter for loop
ldr r0, =Array
mov r4, #1
innerLoop:
ldr r5, [r0]
ldr r7, [r0, #4]
cmp r5, r7
ble continue
strgt r7, [r0]
strgt r5, [r0, #4]
add r10, #1
continue:
add r0, #4
cmp r4, r1
add r4, #1
blt innerLoop
cmp r10, #0
bne outterLoop
exit:
pop {r4-r10, lr}
mov r0, #0
bx lr
The following code is in MIPS. How would it be converted into RISC-V? main: la $t0,...