In converting the below code to MIPS, while saving the value to memory, I don't know what should I do. In the Foo function, Zoo is called(when returning the output).
Here is the full code:
int Foo(int[] n, int m)
{
n[m] -= m;
m++;
return Zoo(m, n);
}
int Zoo(int m, int[] n)
{
m++;
return n[m];
}
This is the MIPS code, which I have written for this question.
Foo:
addi $sp, $sp, -12
sw $a0, 0($sp)
sw $a1, 4($sp)
sw $ra, 8($sp)
sll $t0, $a1, 2 # 4 * m
add $t1, $t0, $a0
lw $t2, 0($t1) # n[m]
sub $t3, $t2, $a1
sw $t3, $t1($a0) # here is the problem
addi $a1, $a1, 1
jal Zoo
lw $a0m 0($sp)
lw $a1, 4($sp)
lw $ra, 8($sp)
addi $spm $sp, 12
jr $ra # ??
Zoo:
addi $a0, $a0, 1
sll $t0, $a0, 2
add $t1, $t0, $a1
lw $t2, 0($t1)
add $v0, $t2, $zero # ??
jr $ra # ??
I think there are more problems with my code. But the main question is about setting offset in sw instruction. I will be grateful for your help in how to make it correct.