I need to translate this C code to MIPS assembly. Here is the C code:
int tmp = 0;
for (int j = 0; j < 15; ++j)
tmp = tmp * 2 + 3
This is my MIPS assembly code. Is it a correct translation? If you see any mistakes I would really like to know.
# tmp = $v0
# j = $t0
.globl main
main:
li $v0,0
loop:
bgt $t0,15,exit
addi $t0,$t0,1
mul $t1,$v0,2
add $v0,$t1, 3
j loop
exit:
Your loop goes from 0 to 14, so your bgt instruction should be: bgt $t0,14,exit
I think.
.