Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Electrical and Computer Engineering

Computer Organization and Architecture


CSE 332
Credits – 3

Prerequisites : CSE 231 Digital Logic


Design

1
LESSON 3, SESSION 1
Arithmetic & Logic Unit – PART 2

Source:
https://sites.google.com/site/neuro11school/lect
From Lesson 2 -
•ALU Design
• Designing a Simple 1-bit ALU

3
Incorporating Subtraction, NOR and NAND
ALU

4
ALU Control

• Plan to control ALU: main control sends a 2-bit control field (A and B invert)
to the ALU control. Based on them and a function field (from MIPS)
instruction the ALU control generates the 3-bit ALU operation.

ALU control Function

Binvert Ainvert Function 000 and


0 0 add 001 or
010 add
1 0 sub 110 sub
111 slt
2

3
Ainvert To
Main Binvert ALU
ALU ALU
Control Control
control
input ALUop

??
MIPS Instruction
function field, Fx
Implementation: ALU Control Block
Ainvert
Binvert
TT for ALU Control: 3
ALU Ctrl

Fx
Inputs Outputs
ALUOp Funct field, Fx Operation
Binvert Ainvert F5 F4 F3 F2 F1 F0
0 0 0 0 010 (add)
1 0 X 0 110 (sub)
1 1 X 0 011 (nand)
1 1 X 1 100 (nor)
0 0 0 1 000 (and)
0 0 1 0 001 (or)
0 0 1 1 111 (SLT)

Truth table for ALU control bits

Classwork 1: Develop ALU control logic and circuit using k-map (4 marks)?

Homework 1: Develop ALU control logic and circuit using QM method (4 marks)?
Implementation: ALU Control Block
Ainvert
Binvert
TT for ALU Control: 3
ALU Ctrl

Fx
Inputs Outputs
ALUOp Funct field, Fx Operation
Binvert Ainvert F5 F4 F3 F2 F1 F0
0 0 0 0 010 (add)
1 0 X 0 110 (sub)
1 1 X 0 011 (nand)
1 1 X 1 100 (nor)
0 0 0 1 000 (and)
0 0 1 0 001 (or)
0 0 1 1 111 (SLT)

Truth table for ALU control bits

Classwork 1: Develop ALU control logic and circuit using k-map (4 marks)?

Homework 1: Develop ALU control logic and circuit using QM method (4 marks)?
Implementation: ALU Control Block
Ainvert
Binvert
TT for ALU Control: 3
ALU Ctrl

Fx
Inputs Outputs
ALUOp Funct field, Fx Operation
Binvert Ainvert F5 F4 F3 F2 F1 F0
0 0 0 0 010 (add)
1 0 X 0 110 (sub)
1 1 X 0 011 (nand)
1 1 X 1 100 (nor)
0 0 0 1 000 (and)
0 0 1 0 001 (or)
0 0 1 1 111 (SLT)

Truth table for ALU control bits

Classwork 1: Develop ALU control logic and circuit using k-map (4 marks)?

Homework 1: Develop ALU control logic and circuit using QM method (4 marks)?
Complete Implementation: ALU Control Block
ALUOp Funct field Operation
ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0
0 0 X X X X X X 010
0* 1 X X X X X X 110 *Typo in text
1 X X X 0 0 0 0 010 Fig. 5.15: if it is X
1 X X X 0 0 1 0 110 then there is potential
conflict between
1 X X X 0 1 0 0 000 line 2 and lines 3-7!
1 X X X 0 1 0 1 001
1 X X X 1 0 1 0 111
Truth table for ALU control bits

ALUOp
ALU control block
ALUOp0
ALUOp1

Operation2
F3
Operation
F2 Operation1
F (5– 0)
F1
Operation0
F0

ALU control logic


Quiz 1

• 3rd July 2021

• Syllabus L1, L2 & L3

Introduction
10
END OF LESSON 3 SESSION 1

11
LESSON 3, SESSION 2
Arithmetic & Logic Unit – PART 2

Source:
https://sites.google.com/site/neuro11school/lect
Multiplication

Multiplicand 421
Multiplying two 3-digit numbers A and B
Multiplier x 123
1263
842 n partial products, where B is n digits long
+ 421
51783 n - 1 additions

In Binary... 6x5
110
Each partial product is either: x 101
110 (A*1) or 000 (A*0)
110
000
+ 110 Equals 30
Note: Product may take as many
as two times the number of bits! 11110
14
Multiply

 Key observations:
Multiplicand 1000
 m bits x n bits = m+n bit product Multiplier 1001
(m+n bits required to represent all possible products) x 1000
 There are only two possibilities in every
0000
steps 0000
If multiplier bit = 1 1000
 copy multiplicand (1 x multiplicand) Product 01001000
If multiplier bit = 0

place 0 (0 x multiplicand)
 Need an adder unit (use ALU?) to add
Multiply Q - Can you write an algorithm ?
 In text, C, Java, flow chart whatever

 Lets consider this example. Multiplicand 1000


AND
For this, we need Multiplier x1001
 Multiplicand Register – 8 bits 1000
 Multiplier Register – 4 bits 0000
 Product register – 8 bits
ADD
0000
 ALU – 8 bit (N=8) 1000
Product 01001000
N=21=m+n
m=21/2 =10.5 =11 m=4, n=4 ; m+n=8
n =11
Shift-add Multiplier Start

Algorithm Multiplier0 = 1 1. Test Multiplier0 = 0


Multiplier0

1a. Add multiplicand to product and


place the result in Product register

2. Shift the Multiplicand register left 1 bit

3. Shift the Multiplier register right 1 bit

No: < 32 repetitions


32nd repetition?

Yes: 32 repetitions

Done
Shift-add Multiplier
Observations on Multiply

• 1 step per clock cycle ⇒ nearly 100 clock cycles to multiply two
32-bit numbers
• Half the bits in the multiplicand register always 0
⇒ 64-bit adder is wasted
• 0’s inserted to right as multiplicand is shifted left
⇒ least significant bits of product never
change once formed

• Intuition: instead of shifting multiplicand to left, shift product to right…


Multiplication AND

• Fast Multiplication (32 bits)

– Use 31 32-bit adders to compute the partial

products

– One input is the multiplicand ANDed with a

multiplier, and the other is the partial product from

previous step.
ADD
– Question?

Show the multiplication tree to compute 5 X 3.

Assume unsigned numbers represented using 3

bits and we have 4-bit ALU.

20
Divide by 2N using shift register
A/ 2N
A =10101110
ALS1 =01011100 =A/2
ALS2 =10111000=A/4

Introduction
21
END OF LESSON 3

Introduction
22
Final reminder on Quiz 1

• 3rd July 2021

• Syllabus L1, L2 & L3

Introduction
23

You might also like