Binary Arithmetic



Binary Division



Unsigned Binary Division: algorithm

(A - R) / B = Q
  1. Q = R = 0
  2. compute B' = B shifted to the left until the most significant bit is 1.
  3. looplab: if A < B then R = A and we are done.
  4. Q = Q * 2
  5. if A >= B' then:
  6. shift B' to the right (logical shift).
  7. return to step "looplab".



Unsigned Binary Division: example

130 / 11: A = 10000010, B = 00001011
A B' A >= B' Q
10000010 10110000 f 00000000
10000010 01011000 t 00000001
00101010 00101100 f 00000010
00101010 00010110 t 00000101
00010100 00001011 t 00001011
00001001 00000101 -- 00001011
Q = 00001011 = 11[10], R = 00001001 = 9[10]



Nonrestoring division



Nonrestoring Division: example

130 / 11: A = 10000010, B = 00001011
A B' A - B' or Q
A + B'
10000010 10110000 11010010 00000000
11010010 01011000 00101010 00000001
00101010 00101100 11111110 00000010
11111110 00010110 00010100 00000101
00010100 00001011 00001001 00001011
Q = 00001011 = 11[10], R = 00001001 = 9[10]



SPARC Division



Intel Division



Extended Precision Arithmetic



Extended Precision Addition



Extended Precision Subtraction

Alternative: complement and add (to complement, do the 1's complement, then use extended-precision addition to add 1)



Extended Precision Multiplication



Extended Precision Division



Project