CSE 332 L3 - 16 & 18 July 2020 PDF

You might also like

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
Recap from Lesson 2 -
•ALU Design
• Designing a Simple 1-bit ALU

2
Incorporating NOR and NAND

3
Recap from Lesson 2 -

4
Recap from Lesson 2 -

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

Source:
https://sites.google.com/site/neuro11school/lect
ALU Control

• Plan to control ALU: main control sends a 2-bit control field (A and B invert)
to the ALU control. Based on ALUOp and funct field of instruction the ALU
control generates the 3-bit ALU control field

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

??
MIPS Instruction
function field, Fx
Implementation: ALU Control Block
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 (nand)
1 1 X 0 (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

ALU control logic?


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

• 23rd July 2020

• Syllabus L1, L2 & L3

Introduction
11
LESSON 3, SESSION 3
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
13
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


For this, we need Multiplier x1001
 Multiplicand Register – 8 bit 1000
 Multiplier Register – 4 bit 0000
 Product register – 8 bit 0000
 ALU – 8 bit 1000
Product 01001000
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

• Fast Multiplication

– 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.

– Question?

Show the multiplication tree to compute 5 X 3.

Assume unsigned numbers represented using 3

bits and we have 4-bit ALU.

19
Divide by 2N using shift register

Introduction
20
Quiz 1

• 23rd July 2020

• Syllabus L1, L2 & L3

Introduction
21
END OF LESSON 3

Introduction
22

You might also like