Fixed Point Arithmetic
Dec. 2002
Presented by Fore June
Author of Windows Fan, Linux Fan

Copyrighted by Fore June, All rights reserved

Fixed-point Arithmetic

Appendix 2 1s and 2s complement relation relation

X = bk . . . b1 b0 . b-1 b-2 .... b-m

Let X = 1s complement of X

X = bk . . . b1 b0 . b-1 b-2 .... b-m

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

-X = X + 0 ... 0.0 ... 0 1

So

X + (-X) = 0

By similar argumenet, we can have

V(X) + V(-X) = 0     by discarding carry bk+1
Or
V(-X) = -V(X)

Note: In Windsp instructions,

NOT ~ 1s complement
NEG ~ 2s complement ( operates on register MR only )
Example
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 )