Addition and Subtraction Instructions
The following table lists some addition and subtraction instructions.
They are with the R-type format and include:
| Signed Addition & Subtraction |
Addition & Subtraction without Overflow |
add rd, rs, rt # rd: destination register
sub rd, rs, rt # rs: 1st source register
neg rd, rs # rt: 2nd source register
|
addu rd, rs, rt
subu rd, rs, rt
|
The addition performs the 2’s complement operation between the two source registers (
rs and
rt), and places the result in the destination
rd.
-
add rd, rs, rt # add with overflow
-
Computes the two’s complement sum of two signed values.
It adds the contents of
rs to the contents of rt, or it can add the contents of rs to the immediate value.
Add (with overflow) puts the result in the destination register.
When the result cannot be extended as a 32-bit number, the machine signals an overflow exception.
add (register)
|
add (immediate)
|
Integer 7 to Char '7'
|
.data
X: .byte 10
Y: .word -20
.text
lb $t0, X
lw $t1, Y
add $a0, $t0, $t1
li $v0, 1
syscall
|
.data
X: .byte 10
.text
lb $t0, X
add $a0, $t0, -20
li $v0, 1
syscall
|
|
| Output |
Output |
Output |
7 ('7')
|
Take your time (don’t hurry) on the exam.
You don’t get a bonus for finishing quickly.
|