ADD ADD
Purpose |
perform arithmetic addition |
Format |
opcode add.rx, sum.mx 2 operand opcode addl.rx, add2.rx, sum.wx 3 operand |
Operation |
sum ßsum + add; 2 operand sum ß add1 + add2; 3 operand |
Condition codes |
N ß sum LSS 0; Z ß sum EQL 0; Vßoverflow; C ß carry from most significant bit (integer); C ß 0 (floating); |
Exceptions |
Integer overflow Floating overflow Floating underflow Reserved operand |
Opcodes |
80 ADDB2 Add Byte 2 Operand 81 ADDB3 Add Byte 3 Operand A0 ADDW2 Add Word 2 Operand Al ADDW3 Add Word 3 Operand C0 ADDL2 Add Long 2 Operand C1 ADDL3 Add Long 3 Operand 40 ADDF2 Add Floating 2 Operand 41 ADDF3 Add Floating 3 Operand 60 ADDD2 Add Double 2 Operand 61 ADDD3 Add Double 3 Operand |
Description |
In 2 operand format, the addend operand is added to the sum operand and the sum operand is replaced by the result. In 3 operand format, the addend 1 operand is added to the addend 2 operand and the sum operand is replaced by the result. In floating point format, the result is rounded. |
Notes |
1. Integer overflow occurs if the input operands to the add have the same sign and the result has the opposite sign. On overflow, the sum operand is replaced by the low order bits of the true result. 2. On a floating reserved operand fault, the sum operand is unaffected and the condition codes are unpredictable. 3. On floating underflow, the sum operand is replaced by 0. 4. On floating overflow, the sum operand is replaced by an operand of all bits 0 except for a sign bit of 1 (a reserved operand). N ß1; Z ß 0; V ß 1; and C ß 0. |
Example 1
The following program puts the value 3 in R1 and 4 in R2, and then sums it and prints the result. At the end of this program, R2 is 7.
.text
main: .word 0
movl $3, r1
movl $4, r2
addl2 r1, r2
pushl r2
pushal format
calls $2, .printf
pushl $0
calls $1, .exit
.data
format: .asciz "R2 is %d"
Example 2
The following program puts the value 3 in R1 and 4 in R2, and then sums it and puts the value in R3. We then print the content of R3.
.text
main: .word 0
movl $3, r1
movl $4, r2
addl3 r1, r2, r3
pushl r3
pushal format
calls $2, .printf
pushl $0
calls $1, .exit
.data
format: .asciz "R3 is %d"
Example 3
This example comes to present the changes of the flags during calls to add opcode.
.text
main: .word 0
movb $0x7C, r0
addb2 $1, r0 # N = 0, V = 0
addb2 $1, r0
addb2 $1, r0
addb2 $1, r0 # N = 1, V = 1
addl2 $1, r0 # N = 0, V = 0
addb2 $1, r0 # N = 1, V = 0
addb2 $1, r0
addb2 $1, r0
movb $0xFD, r0
addb2 $1, r0 # N = 1
addb2 $1, r0
addb2 $1, r0 # Z = 1, C = 1
addb2 $1, r0
pushl $0
calls $1, .exit
Example 4
Another flags example:
.text
main: .word 0
movb $0x7C, r0
addb3 $-1, $1, r0 # Z = 1, C = 1
pushl $0
calls $1, .exit