Computer Architecture: ALU (2) - Integer Arithmetic
Computer Architecture: ALU (2) - Integer Arithmetic
INSTITUT FR INFORMATIK
COMPUTER ARCHITECTURE
Lecture 11
CA - XI - ALU(2) - 1
- Sign & Magnitude (awkward +,-) - 1's complement (better). Requires a correct cycle
S t +1 = S t + C n
- 2's complement is awkward externally, but is the best hardware representation for addition and subtraction
CA - XI - ALU(2) - 3
a) 2's Complement Addition (1) Modulo Arithmetic Positive Numbers Negative Numbers 2's complement In general 2's complement 7 + 4 = 11 -7 + (-4) = -11 (9 + 12) = 21 which is -11 in signed decimal notation (X + Y) mod 2n (9+12) mod 16 = 5 which is also 11 in decimal no change
Add 2's complement using adder as in the figure. 2 n 1 <N < + 2 n 1 Ignore carry-out bit and you have a correct answer. (2) Numbers outside the expected range cause an arithmetic overflow. b) Subtraction Subtraction is the same as performing addition of a complement. 7-4=3 is equivalent 7+12=19 in 2's complement which is 3 after ignoring the carry.
CA - XI - ALU(2) - 4
OVERFLOW
cn = 1, X + Y 2n Overflow is only possible when both operands have the same sign. Overflow occurs when the sign of S does not agree with the signs of X and Y, i.e., when the signs of X and Y are the same.
Detection method is to set a flag (V). Interrupts are sometimes allowed to occur on arithmetic overflow.
CA - XI - ALU(2) - 5
MULTIPLICATION
"PAPER AND PENCIL METHOD"
1 x 1 1 1 1 0 0 0 0 1 1 0 1 1 0 0 0 1 Partial Product 0 (PP0) PP 1 PP 2 PP 3 q3 0 p7 p6 p5 p4 p3 q2 0 1 0 1 0 0 1 1 1 0 1 1 (13) Multiplicand M (11) Multiplier Q
1 1 1 0
PP4 = product
CA - XI - ALU(2) - 6
j
q
Carry-out
A Sum
Carry-in
CA - XI - ALU(2) - 7
Multiplier Q C
an-1 a0 qn-1 q0 1 ADD 0 NO ADD
n-bit adder
ADD/NO ADD
Control sequencer
mn-1
m0
Multiplicand M
CA - XI - ALU(2) - 8
MULTIPLICATION EXAMPLE
M 1 1 0 1 0 C 0 0 1 0 0 0 1 0 0 0 0 0 A 1 1 0 1 0 1 1 0 0 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 1 0 1 1 Q 1 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1
Initial configuration
Fourth cycle
CA - XI - ALU(2) - 9
0 1
R ... ...
A(0) Q(7)
M(0) 0
Q(7)
OUTBUS OUTBUS
A Q(0:n-1)
No
Q(7)
C1
C9
Data bus
Control unit
ASL R0 ROL RI
R2 MULTIPLICAND M
CA - XI - ALU(2) - 12
SOFTWARE MULTIPLICATION
CLR R0 Clear register R0 MOV #-16.,R3 Set register R3 to -16 use as cycle counter mloop: ASL R0 ASL (Arithmetic Shift Left) instruction shifts contents of R0 (low-order half of partial product) left one bit. MSB of R0 is shifted into C bit. LSB of R0 is set to 0 ROL (Rotate Left) instruction rotates contents of R1 and the C bit by one bit position. Old contents of C is moved into LSB of R1, old contents of MSB of R1 is moved into C. The combination of ASL and ROL have thus shifted the (R1, R0) pair left one bit position, placing the old MSB of R1 into C. BCC ADD noadd R2,R0 The multiplier bit to be checked (first qn-1, then qn-, etc.) is now in C, and the instruction BCC causes a branch around the add operation if C is 0. If C=1, multiplicand in R2 is added into the low-order end of the partial product in R0. Any carry-out that goes into C must be added to the high-order half of the partial product. This is done by the ADC which adds contents of C to the LSB position of R1. Note that this process will never damage the unused portion of the multiplier in R1 because the very first time that (R1, R0) is shifted left, a = is placed in the LSB position of R1, creating enough space for any later encroachment by the partial product. Counter is incremented and BNE (Branch if Not Equal to 0) instruction does branch back to mloop as long 16 cycles are not completed.
CA - XI - ALU(2) - 13
ROL R1
ADC R1
Labels
CA - XI - ALU(2) - 14
BOOTHS ALGORITHM
1. Booth's algorithm is a powerful direct algorithm to perform signed-number multiplication. The algorithm is based on the fact that any binary number can be represented by the sum and difference of other binary numbers. Using a signed binary notation we can represent a multiplier in a unique scheme with the possibility of fewer add cycles for a given multiplier. 2.a. Examples of the scheme are shown (a positive Multiplier and a negative Multiplier). The first example shows how zero's may be skipped over for faster implementation. b. Figure illustrates how the Booth recordings are accomplished and next figure illustrates the transition recording table. c. Also a flow chart and a table show, respectively, the use of the algorithm for multiplication of 2's complement numbers. d. The speed of the algorithm depends upon the bit savings if any that the Booth algorithm will generate. Figure illustrates the worst, normal and good case for a 16 bit number. e. The algorithm accomplishes the following Uniform treatment of positive and negative numbers. Achieves efficiency in the number of summands in some cases (data dependent). 3. It would be desirable to use the Booth technique in some way that removed some of the data dependence.
CA - XI - ALU(2) - 15
1 0 0 1 1 (-13) x 0 1 0 1 1 (+11) 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 1 0 1 1 1 0 0 0 1 (-143) Sign extension of negative multiplicand 0 1 0 1 1 0 1 (+45) 0 0 +1 +1 +1 +1 0 (+30) 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 1 0 (+1350) 0 1 0 1 1 0 1 0 +1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 0 0 1 1 (2's compl. of multiplicand) 0 .......................................................................... 0 0 ....................................................................0 0 ............................................................0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 1 0 Normal and Booth multiplication schemes.
CA - XI - ALU(2) - 17
Version of multiplicand selected by bit i 0 0 0xM 0 1 +1 x M 1 0 -1 x M 1 1 0xM Booth multiplier recoding table.
CA - XI - ALU(2) - 18
0 1 1 0 1 1 1 0 1 0
(+13) (- 6)
0 1 1 0 1 0 -1+1 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 1 0 0 0 0 1 1 1 0 1 1 1 0 (-78)
Sign extension
1 1 1 0 1 1 0 0 1 0
BIT-PAIR
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 +1-1 +1 -1 +1 -1 +1 -1 +1 -1 +1 -1 +1 -1 +1 -1 bad 0 -1 0 0 +1 -1 +1 0 -1 +1 0 0 0 -1 0 0 normal 0 0 0 +1 0 0 0 0 -1 0 0 0 +1 0 0 -1 good Booth-recorded multipliers Sign extension Implied 0 to right of LSB 1 1 1 0 1 0 0 0 0 -1 +1 -1 0 0 -1 -2 Example of bit pair recording derived from Booth recording Multipl. bit-pair Multiplier bit on the right Multiplicand selected at Spi i+1 i i-1 0 0 0 0xM 0 0 1 +1 x M 0 1 0 +1 x M 0 1 1 +2 x M 1 0 0 -2 x M 1 0 1 -1 x M 1 1 0 -1 x M 1 1 1 0xM Table of multiplicand selection decisions
CA - XI - ALU(2) - 20
Q(0:n-1)
multiplier
Q(n-1) = 0 and Q(n) = 1? COUNT COUNT + 1 A A(0) A(0) A(1:n-1),Q(0:n) A(0:n-1),Q(0:n-1) Yes A+M
No
No
No
OUTBUS
Q(0:n-2)
Stop CA - XI - ALU(2) - 21
M 0.010
A 0.010 0.010 1.110 1.111 1.111 0.010 0.001 0.000 0.010 1.110
Q 10110
Comments
Subtract M 1.110 01011 10101 10101 11010 11010 Shift A,Q No addition nor subtraction Shift A,Q Add M Shift A,Q Subtract M
CA - XI - ALU(2) - 22
Addition
800 ns
16x16
100 ns 230 ns 70 ns 40 ns 30 ns
CA - XI - ALU(2) - 24