Reputation: 61512
I am trying to turn this C code:
if (op == '+') {
acc += val;
}
into MIPS, and I can't figure out what is causing the address out of range error
#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
Any help would be appreciated.
Upvotes: 0
Views: 2324
Reputation: 25873
lbu $t1, '+'
'+' is not a valid address. You probably meant
li $t1, '+'
Anyway remember that any decent C compiler will convert C to MIPS for you.
Upvotes: 3