SPRUI30H November 2015 – May 2024 DRA745 , DRA746 , DRA750 , DRA756
Signed Addition of Two Register Values
ADD src1, src2, dst
Functional unit = D
16 bit
15 | 13 | 12 | 10 | 9 | 7 | 6 | 0 |
dst | src2 | src1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
3 | 3 | 3 | opcode |
Signed addition of src1 with src2 and store result to dst.
CSR[2]EQ = (dst == 0)
CSR[5]C = {carry out} from (src2 + src1)
CSR[7]V = {overflow} from (src2 + src1)
Note that the carry (CSR[5]C) and overflow (CSR[7]V) bits are relevant to unsigned and signed operations, respectively. Appropriate bits are checked depending on if the operands are represented (or, interpreted) as unsigned or signed numbers.
The status of the CSR[5]C bit is used to synthesize multiword (wider) addition. To synthesize a multiword addition, subsequent instructions use the CSR[5]C bit as a carry in operand, performing a normal addition if CSR[5]C == 0 and adding one more than usual if CSR[5]C == 1.
For example, if register pairs R0/R1 and R2/R3 hold 64-bit values (where R0 and R2 hold the least-significant words), the following instructions leave the 64-bit sum in the register pair R4/R5:
ADD R2, R0, R4 ; R4=R2+R0, sets CSR[C]
MVC CSR, R6 ; leaves CSR[C] untouched
EXTU 5, 5, R6, R6 ; if (CSR[C]) R6=0x1 else R6=0x0
ADD R3, R1, R5 ; R5=R3+R1
ADD R5, R6, R5 ; R5=R5+1 if CSR[C] was set, else R5=R5
Note that the above example needs appropriate modification in order to generate correct carry/overflow applicable for the total 64-bit result.
dst = src2 + src1