Visualizing 2s Comp. Addition P72 Figure 2.19 NegOver TAddalu, v) PosOver
11 Visualizing 2’s Comp. Addition P72 Figure 2.19 -8 -6 -4 -2 0 2 4 6 -8 -6 -4 -2 0 2 4 6 -8 -6 -4 -2 0 2 4 6 8 TAdd4 (u , v) u v PosOver NegOver
Detecting Tadd Overflow P71 Task Given s ADdu, v 2w1 PosOver Determine if s Addu, v claim Overflow iff either: uV<0.s≥0( NegOver) uv≥0,s<0( PosOver) ovf=(u<O==0)&&(u<O!=sO) legover 12
12 Detecting Tadd Overflow P71 • Task – Given s = TAddw(u , v) – Determine if s = Addw(u , v) • Claim – Overflow iff either: • u, v < 0, s 0 (NegOver) • u, v 0, s < 0 (PosOver) – ovf = (u<0 == v<0) && (u<0 != s<0); 0 2 w –1 2 w–1 PosOver NegOver
Mathematical Properties of TAdd Two's Complement Under TAdd forms a Grou Closed, Commutative, Associative, o is additive identity Every element has additive inverse l:≠TMim Let TCompw(u P73(2.13) TMin u=TMin, TAddwu, TCompw(u))=0
13 Mathematical Properties of TAdd • Two’s Complement Under TAdd Forms a Group – Closed, Commutative, Associative, 0 is additive identity – Every element has additive inverse • Let • TAddw(u , TCompw (u )) = 0 TCompw(u) = −u u TMinw TMinw u = TMinw P73 (2.13)
Mathematical Properties of TAdd Isomorphic algebra to UAdd TAdd(u,V)=∪2T( UAdd(T2∪(u),T2∪(v) Since both have identical bit patterns T2U(TAddwu, v)=UAddwt2U(u), T2U(n)) Isomorphic:同构
14 Mathematical Properties of TAdd • Isomorphic Algebra to UAdd – TAddw (u , v) = U2T (UAddw(T2U(u ), T2U(v))) • Since both have identical bit patterns – T2U(TAddw (u , v)) = UAddw(T2U(u ), T2U(v)) Isomorphic:同构
Negating with Complement Increment P73 In C -~X+1==-X Complement Observation wx+x==1111.111 ==-1 x囗回口 +~x四四回 1西 wx:Complement 15
15 Negating with Complement & Increment P73 • In C – ~x + 1 == -x • Complement – Observation: ~x + x == 1111…111 == -1 x 1 0 0 1 1 1 0 1 + ~x 0 1 1 0 0 0 1 0 -1 1 1 1 1 1 1 1 1 ~x:Complement