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:
# 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: loops.
j. Loop # goto Loop. The label Loop lets us identify which assembly instruction should be executed after the branch. The label could be anything, as long as the MIPS assembler doeesn't misinterpret it as an instruction.
%g0 is unique: It always contains 0 and can never be changed. %g1 to %g4 are volatile across calls; they may be used between calls. %l0 to %l7 May be freely used; they are unaffected by deeper calls. These are also the caller's out registers; they are unaffected by deeper calls.
You don't set j ($t0) to zero before the loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With