I am working on a problem for my homework. I have to convert this C++ Code: int multiply(int x, int y) { int product=0; if(x>y) for(int i=0;ix) for(int i=0;i
I am working on a problem for my homework. I have to convert this C++ Code:
int multiply(int x, int y)
{
int product=0;
if(x>y)
for(int i=0;i<y;i++)
product+=x;
if(y>x)
for(int i=0;i<x;i++)
product+=y;
return product;
}
I have received the MIPS Code of:
multiply(int, int):
daddiu $sp,$sp,-48
sd $fp,40($sp)
move $fp,$sp
move $3,$4
move $2,$5
sll $3,$3,0
sw $3,16($fp)
sll $2,$2,0
sw $2,20($fp)
sw $0,0($fp)
lw $3,16($fp)
lw $2,20($fp)
slt $2,$2,$3
beq $2,$0,.L2
nop
sw $0,4($fp)
b .L3
nop
.L4:
lw $3,0($fp)
lw $2,16($fp)
addu $2,$3,$2
sw $2,0($fp)
lw $2,4($fp)
addiu $2,$2,1
sw $2,4($fp)
.L3:
lw $3,4($fp)
lw $2,20($fp)
slt $2,$3,$2
bne $2,$0,.L4
nop
.L2:
lw $3,20($fp)
lw $2,16($fp)
slt $2,$2,$3
beq $2,$0,.L5
nop
sw $0,8($fp)
b .L6
nop
.L7:
lw $3,0($fp)
lw $2,20($fp)
addu $2,$3,$2
sw $2,0($fp)
lw $2,8($fp)
addiu $2,$2,1
sw $2,8($fp)
.L6:
lw $3,8($fp)
lw $2,16($fp)
slt $2,$3,$2
bne $2,$0,.L7
nop
.L5:
lw $2,0($fp)
move $sp,$fp
ld $fp,40($sp)
daddiu $sp,$sp,48
jr $31
nop
I continue to receive an error in my program QTSpim stating:
syntax error on line 1 of file
multiply(int, int):
^
How do I go about fixing this issue in my code?
Step by step
Solved in 3 steps with 3 images