Fixed-point Arithmetic
Appendix 2 1s and 2s complement relation relation
Let X = 1s complement of X
bi + bi = 1
Then
| X + X | = | bk . . . b1 b0 . b-1 b-2 .... b-m | |
| + | |||
| bk . . . b1 b0 . b-1 b-2 .... b-m | |||
| = | 1 1 ... 1.11 ... 1 |
Thus
| X + X + 0 ... 0.0 ... 0 1 | = | 1 1 ... 1.11 ... 1 + 0 ... 0.0 ... 0 1 |
| = | 0 0 ... 0.00 ... 0 | |
| = | 0 ( discard the carry ) |
But 2s complement of X is
So
By similar argumenet, we can have
Note: In Windsp instructions,
MOVEX Gr0, #-2H ;FFFEH NOT Gr0 ;1s complement ADD Gr0, #1 ;2s complement ( Gr0 = 2 ) MRa = 0 MOVEX MRa0, #8 ;MRa = 00 0000 0008 hex NEG ( MRa ) ;2s complement MRa = FF FFFF FFF8 hex ( = -8 )