Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-1 The ALU.

Similar presentations


Presentation on theme: "Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-1 The ALU."— Presentation transcript:

1 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-1 The ALU l ALU includes combinational logic. – Combinational logic  a change in inputs directly causes a change in output, after a characteristic delay. – Different from sequential logic which only changes on the clock. l Two major components of combinational logic are – multiplexors & decoders. 0123456701234567 c 3 X 8 multiplexor s1 s2 0123456701234567 DECODER 012012 3 X 8 Decoder

2 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-2 Basic ALU l The basic ALU provides the basic logical and arithmetic functions: AND, OR plus addition. l Subtraction in 2's complement  invert +1. l Shift, multiplication and division are usually outside the basic ALU. Logical operations 1 bit logical unit for AND/OR operations select (AND or OR) result 0101 MUX abab

3 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-3 abC in sumC out 00000 00110 01010 01101 10010 10101 11001 11111 inputs outputs sum = (a  b  C in ) + (a  b  C in ) + (a  b  C in ) + (a  b  C in ) = a + b + C in C out = (b  C in ) + (a  C in ) + (a  b) = ((a + b)  C in ) + (a  b) abab C out C in Adder hardware for C out in 2 layers 1 bit FULL adder (3,2) ab C in C out sum Carry in Carry out

4 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-4 Full Adder from Half Adders Half adder Full adder from 2 half adders + or gate abab Cout sum Cin abab Cout sum

5 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-5 1 bit simple ALU for logical / arithmetic operations abab select result 012012 + 2 Cin Cout 1 Bit Simple ALU

6 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-6 Enhanced for subtraction abab select result 012012 + 2 Cin Cout invert 1's complement 2's complement: use Cin = 1 subtraction: a + b + 1 = a + (b + 1) = a + (-b) = a - b 0101 1 Bit Enhanced ALU

7 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-7 Ripple Carry Type Adder l To produce a 32 bit result, we connect 32 single bit units together. l This type of ALU adder is called a ripple adder –Carry bits are generated in sequence. –Bit 31 result and Cout is not correct until it receives Cin from previous unit, which is not correct until it receives Cin from its previous unit, etc. –Total operation time is proportional to word size (here 32). a0 b0 result 0 Cin Cout Cin ALU0 Cout Cin ALU1 Cout Cin ALU2 Cout Cin ALU31 Cout...... a1 b1 a2 b2 a31 b31 result 1 result 2 result 31...... operation = invert + select 32 bit ADDER with ripple carry: 3

8 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-8 Multiplication and Division l Multiplication is done by doing shifts and additions. l Multiplying two (unsigned) numbers of n bits each results in a product of 2n bits. Example: 0110 x 0011 (6x3) At start, product = 00000000 looking at each bit of the multiplier 0110, from right to left: 0: product unchanged: 00000000, shift multiplicand left: 00110 1: add multiplicand to product: 00000000 + 00110 = 00000110, shift multiplicand left: 001100 1: add multiplicand to product: 00000110 + 001100 = 00010010, shift multiplicand left: 0011000 0: product unchanged: 00010010 = 18 10 shift multiplicand left: 00110000

9 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-9 Main difficulty arises when signed numbers are involved. Naive approach: convert both operands to positive numbers, multiply, then calculate separately the sign of the product and convert if necessary. A better approach: Booth’s Algorithm. Booth’s idea: if during the scan of the multiplier, we observe a sequence of 1’s, we can replace it first by subtracting the multiplicand (instead of adding it to the product) and later, add the multiplicand, after seeing the last 1 of the sequence. Multiplying Signed Numbers

10 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-10 0110 x 0011 (6x3) This can be done by (8-2)x3 as well, or (1000 - 0010) x 0011 (using 8 bit words) At start, product = 00000000 looking at each bit of the multiplier 0110, from right to left: 0: product unchanged: 00000000, shift multiplicand left: 00110 1: start of a sequence: subtract multiplicand from product: 00000000 - 00110 = 11111010, shift multiplicand left: 001100 1: middle of sequence, product unchanged: 11111010, shift multiplicand left: 0011000 0: end of sequence: add multiplicand to product: 11111010 + 0011000 = 00010010 = 18 10 shift multiplicand left: 00110000 Example

11 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-11 1100 x 0011 (-4x3) At start, product = 00000000 looking at each bit of the multiplier 1100, from right to left: 0: product unchanged: 00000000, shift multiplicand left: 00110 0: product unchanged: 00000000, shift multiplicand left: 001100 1: start of a sequence: subtract multiplicand from product: 00000000 - 001100 = 11110100, shift multiplicand left: 0011000 1: middle of sequence, product unchanged: 11110100, shift multiplicand left: 00110000 The result is 11110100=-12 10 Yet another example

12 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-12 Scan the multiplier from right to left, observing, at each step, both the current bit and the previous bit: 1. Depending on (current, previous) bits: 00 : Middle of a string of 0’s: do no arithmetic operation. 10 : Beginning of a string of 1’s: subtract multiplicand. 11 : Middle of a string of 1’s: do no arithmetic operation. 01 : End of a string of 1’s: add multiplicand. 2. Shift multiplicand to the left. Booth's Algorithm

13 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-13 Why does Booth’s Algorithm work ? Let a and b be signed integer numbers of n bits each. Redefine step 1 of Booth’s algorithm (see previous page): 0  (a i, a i-1 ) = 00 or 11  no arithmetic operation. a i-1 - a i = 1  (a i, a i-1 ) = 01  add multiplicand. -1  (a i, a i-1 ) = 10  subtract multiplicand. Calculate now the product a x b, according to Booth’s algorithm: a x b =(a -1 - a 0 ) x 2 0 x b + a -1 = 0 +(a 0 - a 1 ) x 2 1 x b + +(a 1 - a 2 ) x 2 2 x b +... +(a n-3 - a n-2 ) x 2 n-2 x b + +(a n-2 - a n-1 ) x 2 n-1 x b = -a n-1 x 2 n-1 x b +  a i x 2 i x b = = b x (-a n-1 x 2 n-1 + a i x 2 i ) = a x b {

14 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-14 Implementing multiplication due to Booth’s Algorithm: Multiplicand Control 32 bits 64 bits Shift right write 32 bit ALU bit 0 (rightmost) At start, the multiplier occupies the right half of the product. The left half of the product is full with zeros. At each step, the control verifies the right most bit of the multiplier and decides whether to add the multiplicand to the product, to subtract it from, or just to shift the product right (instead of shifting the multiplicand to the left). The shifts are signed extended. At the end, the multiplier is out of the product register and the product contains the result. Hardware for Multiplication Product

15 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-15 Division l Division is done by doing shifts and subtractions. l Dividing a number of 2n bits by a number of n bits results in a quotient of up to 2n bits and a remainder of up to n bits. Example: 01001010 : 1000 (74:8) 1001 Quotient 01001010 1000 Divisor 1000 10 101 1010 1000 10 Remainder Dividend

16 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-16 Division Algorithm At start, the n bits divisor is shifted to the left, while n 0’s are added to its right. This way the dividend and the divisor are 2n bits long. At each step (repeating the following n+1 times), subtract the divisor from the dividend. if the result is non-negative, shift the quotient left and place a 1 in the new place. else shift the quotient left and place a 0 in the new place. restore the dividend by adding the divisor to it. shift the divisor to the right. Note: the above algorithm assumes a quotient of no more than n+1 bits long. Otherwise, at initialization, we should shift the divisor left until its MSB is 1.

17 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-17 Implementing division: Divisor Control 32 bits 64 bits Shift left write At start, the dividend occupies the right half of the remainder register. The left half of the reminder register is full with zeros. Shift reminder left 1 position. At each step, the control subtracts the divisor from the left half of the remainder register, putting there the result. If the remainder is negative, it restores it. Then, instead of shifting the divisor to the right, it shifts the remainder to the left and inserts 0 or 1, according to the sign of the remainder. 0 if the sign bit is 1 and 1 if the sign bit is 0. At the end, the remainder register contains the quotient in its right half and the remainder in its left half. Hardware for Division bit 63 (sign) Remainder 32 bit ALU quotient

18 Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-18 The above algorithm and implementation deals only with positive numbers. If negative numbers are involved, the sign of the quotient is set to MINUS if the divisor and the dividend are of different signs. The sign of the remainder, though, is more difficult to set. Follow the rule: Dividend = Quotient x Divisor + Remainder Example: +7/+2 = +3(+1) since +7 = +2*(+3)+1 +7/-2 = -3(+1) since +7 = -2*(-3)+1 -7/+2 = -3(-1) since -7 = +2*(-3)-1 -7/-2 = +3(-1) since -7 = -2*(+3)-1 Conclusion: the sign of the remainder is set according to the sign of the dividend. Dividing Signed Numbers


Download ppt "Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-1 The ALU."

Similar presentations


Ads by Google