我要将这样的C代码翻译成MIPS:
int call(int arg)
{
return foo(arg+10) + bar(arg) + baz(one(), two(arg-1), arg);
}
我的MIPS实施是:
.data
.text
.globl callMany
callMany:
add $s1, $a0,$zero
addi $a0, $a0, 10
jal foo
add $s0, $v0, $zero #s0 = foo(arg+10)
add $a0, $s1, $zero
jal bar
add $s0, $s0, $v0 #s0 = foo(arg+10)+bar(arg)
addiu $sp, $sp, -8
jal one
sw $v0, 0($sp) #save one()
addi $a0, $s1, -1
jal two
sw $v0, 4($sp) #save two(arg-1)
lw $a0, 0($sp)
lw $a1, 4($sp)
addiu $sp, $sp, 8
add $a2, $s1, $zero
jal baz
add $s0, $s0, $v0 # Runtime exception at 0x004009d0: arithmetic overflow
add $v0, $s0, $zero
jr $ra
我不知道为什么我有错误:
add $s0, $s0, $v0 # Runtime exception at 0x004009d0: arithmetic overflow
因为我在这行代码中所做的是:
s0 = foo(arg+10) + bar(arg) + (the return value of baz)
有什么想法吗?