Lec 4
Lec 4
2
2. What is ALU?
ALU
2.What is ALU?
2.1 Arithmetic
Logic Unit
Diagram
2.2 The ALU
Fig: CPU
Fig: Motherboard
3
2. What is ALU?
• Performs set of arithmetic operations and set of logic
operations
2.What is ALU? • Multi operation combinational logic circuit.
2.1 Arithmetic
Logic Unit
• It has a number of selection lines to select particular
Diagram operation in the unit.
2.2 The ALU
4
2.1 Arithmetic Logic Unit diagram
2.What is ALU?
2.1 Arithmetic
Logic Unit
Diagram
2.2 The ALU Value 1 = 4
ALU Result = 9
Value 2 = 5
Operation = ADD
5
2.2 The ALU
Switch
• A function unit containing the Function Unit
2.What is ALU?
2.1 Arithmetic logic blocks that simultaneously 1 bit ALU
1 bit
7
3.1 ALU 3.2 ALU Decoder & Output Selection
Arithmetic and
Logic Functions
3.2 ALU • Controller takes an instruction
Decoder and
Output • Logic is used so that only one of the logic operation
Selection outputs reaches the result output.
3.3 ALU
Instruction Output to ‘switch’
Decoder
Binary
Instruction Decoder
Ctrl
8
3.1 ALU 3.3. ALU Instruction Decoder
Arithmetic and
Logic Functions • The decoder is a combinatorial Instruction Output
3.2 ALU logic circuit(CLC) Inst1 Inst2 ctrl1 ctrl2 ctrl3 ctrl4
Decoder and • The circuit in which, at any time output 0 0 1 0 0 0
Output
Selection is only depends upon inputs only is 0 1 0 1 0 0
1 1 0 0 0 1
Instruction
Decoder
• It converts binary information from
‘n’ i/p lines to a maximum of 2n o/p lines
• Multiple output
lines, ctrl1 to clrl4
• Only one of the output lines is ‘on’ for each
instruction
• ‘n’ instruction lines = 2n control lines.
Hence size of decoder is n* 2n
9
3.1 ALU 3.3 ALU Instruction Decoder (Contd.)
Arithmetic and
Logic Functions
3.2 ALU
Decoder and
• From the truth table, we can design a logic Inst
Output circuit. 1
Inst
ctrl
1
2
Selection • Boolean expression for o/p is: ctrl
3.3 ALU 2
Instruction ctrl1=Inst1’Inst2’, ctrl2=Inst1’Inst2,
Decoder ctrl
ctrl3=Inst1Inst2’ and ctrl4=Inst1Inst2 3
11
5. Half Adder (HA)
4. ALU Output
Multiplexor
• Two bit adder circuit x s
HA
5. Half Adder • Number of inputs = 2 (x and y ‘say’) y c
(HA) • Number of outputs= 2 (sum and carry)
6.Full Adder
For example:
(FA)
0 0 1 1 Input Output
+0 +1 +0 +1 x y Sum(s) Carry(c)
0 0 0 0
0 1 1 10
0 1 1 0
1 0 1 0
sum 1 1 0 1
carry
12
5. Half Adder (Contd…)
4. ALU Output
Multiplexor
• Boolean expression for • Logic diagram
5. Half Adder half adder output from
(HA) truth table is as; (x⊕y)
6.Full Adder x
Sum(s)= Sum
(FA) y
x’y+xy’
=(x⊕y)
Carry(c)=xy xy
Carry
13
6. Full Adder (FA)
4. ALU Output
Multiplexor
• Three bit adder circuit • Block diagram
5. Half Adder • Number of input= 3(x,y
(HA) and cin ) s x s
x
6.Full Adder • Number of output =2(sum HA-1
c y
HA-2
c
(FA) and carry) y
14
6.1 Logic circuit diagram of FA
6.Full Adder
(FA)
6.1 Logic x⊕y (x⊕y⊕ cin)
x
circuit diagram
y
of FA
(x⊕y) cin
xy
xy
cin
15
7. ALU Components: Contd.
Function Unit/ALU Logic
Multiplexer(MUX)
Operations Multiplexor
7. ALU A AND
Components: B
Contd. OR
8.Multi Bit
XOR Output
ALU
9.Subtraction
Full Adder Addition
Circuit
Carry in Carry out
Inst1 ctrl1
Inst2
ctrl2
ctrl3
ctrl4
Decoder Decoder 16
8. Multi Bit ALU Carry out(C)
A2
7. ALU • Connect multiple single R2
B2
Components: bit ALUs together Carry out to carry
Contd. in
Instruction
s Carry in
17
9. Subtraction
8.Multi Bit • Subtraction can be done by adding A to the 2’s complement form
ALU of B.
9.Subtraction • S = A+(2’s Complement of B)
10. Add/
Subtract Circuit =A+(1’s complement of B+1)
=A+(B’+1)
• The rule to convert B to –B in 2’s complement form is:
• Invert each bit (using NOT gates).
• Add 1.
18
10. Add / Subtract Circuit
9.Subtraction • Both addition and subtraction circuits
10. Add/ can be combined into a single circuit
Subtract
Circuit by using Controlled Inversion.
11. Controlled • A Control input determines whether
Inversion
the circuit adds or subtracts.
19
11. Controlled Inversion
10. Add/ • Consider the following truth table:
Subtract Circuit • Input Control will be the CONTROL.
11. Controlled • Input B is the Data.
Inversion
12.Circuit for
Add/ Subtract
Unit Input Control Input B Output F
0 0 0
Output F=B=
0 1 1 B
1 0 1 Output F=B’
1 1 0 NOT B
20
11. Controlled Inversion (Contd.)
10. Add/ • When Control = 0
Subtract Circuit • Then
11. Controlled
Inversion • When Control = 1
12.Circuit for • Then
Add/ Subtract
Unit
• This is the truth table for XOR
4-bit adder
F=B= B
Add/ 0 0 0
Subtract Unit 0 1 1 Output
13. Control of F=B’
the Add/ 1 0 1
NOT B
Subtract Unit 1 1 0
0/1
22
13. Control of the Add / Subtract Unit
12.Circuit for • The Control determines the operation:
Add/ Subtract
Unit
• Control = 0 : Addition
13. Control of • Carry-in is 0 .
the Add/ • Output is A plus B plus 0.
Subtract Unit
14. Summary
• Control = 1 : Subtraction
• Carry-in is 1.
• Output is A plus ( inverse of B plus 1).
• which is A plus (-B).
23
14. Summary
• ALU
13. Control of • Functions, controlling and multiplexing.
the Add/
Subtract Unit
• Controlled inversion and subtraction.
14. Summary
24