Мне нужно реализовать функцию PrintReverse, используя соглашение о вызовах MIPS.Это будет выполняться с использованием SPIM на терминале.Остальная часть моего кода работает, я просто запутался в том, как добраться до конца массива, чтобы запустить мой цикл, а также реализовать его, используя соглашение о вызовах MIPS.
The PrintReverse function is within a larger program and takes two arguments:
1. The address of an array of word-long (four byte) signed integers, held in $a0.
2. The length of the array as an unsigned integer, held in $a1.
The function should print any given array in reverse order.
(Code should work with any other valid (non-empty) array of any size)
Translated to C++ code:
for (int x = arrayLen; x >= 0; x--)
{
print(myArray[x]);
print("\n");
}
PrintReverse:
# $a0 stores the address of the array, $a1 stores the length of the array
loop:
#loop condition --- NEED HELP
slt $t3, $t0, $a1
bne $t3, $zero, end_loop #jump out
#move to last value --- NEED HELP
sll $t5, $t0, 16
add $t6, $t5, $t4
lw $t7, 0($t6)
# print it out, with a newline
li $v0, 1
move $a0, $t7
syscall
li $v0, 4
la $a0, newline
syscall
#sub by 1
addi $t0, $t0, -1
#restart loop condition
j loop
end_loop:
jr $ra