Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere else.
int f2(int x, int y) {
int i, z = 0;
for (i = x; i <= y; i++)
z = z + f1(i, 5);
return z;
}
So the code after converting into MIPS assembly language is
f2:
addiu $sp,$sp,-40
sw $31,36($sp)
sw $fp,32($sp)
move $fp,$sp
sw $4,40($fp)
sw $5,44($fp)
sw $0,28($fp)
lw $2,40($fp)
nop
sw $2,24($fp)
b $L2
nop
$L3:
li $5,5 # 0x5
lw $4,24($fp)
jal f1
nop
move $3,$2
lw $2,28($fp)
nop
addu $2,$2,$3
sw $2,28($fp)
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
$L2:
lw $3,24($fp)
lw $2,44($fp)
nop
slt $2,$2,$3
beq $2,$0,$L3
nop
lw $2,28($fp)
move $sp,$fp
lw $31,36($sp)
lw $fp,32($sp)
addiu $sp,$sp,40
j $31
nop
Get Answers For Free
Most questions answered within 1 hours.