我正在尝试转换此C代码:
if (op == '+') {
acc += val;
}
进入MIPS,我无法弄清楚是什么导致地址超出范围错误
#reads user input for the op
li $v0, 12 # system call number for operator
syscall # reads the integer
sw $v0, op # stores the user input in op
lw $t0, op # stores op in $t0
lbu $t1, '+' # stores '+' in $t1
# "if" statement
bne $t0, $t1, Else # branches if op is not equal to +
lw $t2, acc # stores acc in $t2
lw $t3, val # stores val in $t3
add $t2, $t2, $t3 # adds $t2 and $t3 and stores the sum in $t2
任何帮助都将不胜感激。
答案 0 :(得分:3)
lbu $t1, '+'
'+'不是有效地址。你可能意味着
li $t1, '+'
无论如何要记住任何体面的C编译器都会为你将C转换为MIPS。