CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17...
Transcript of CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17...
![Page 1: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/1.jpg)
CSC258 Week 6
1
![Page 2: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/2.jpg)
Announcements
§ Next weekú Reading week! ú No lecture, no lab
§ Week after reading weekú Monday: midtermú Lectures as normalú No lab
2
![Page 3: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/3.jpg)
Midterm Time & Location
Monday, February 24, 7:10-8:40 p.m.Locations:
• IB-120 (UTORID A-M)• MN-1210 (UTORID N-Z)No aids permitted.
Bring your TCard to scan.
3
![Page 4: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/4.jpg)
Study Tips
1. Review lectures (especially quizzes) from W1-W6
• Do some of the recommended exercises
2. Review what you did for labs1-5
3. Practice (timed) with a past test
• Example posted on course web page
4. Post questions on the discussion board or visit office hours
4
![Page 5: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/5.jpg)
Pre-test Office Hours
5
Larry Zhang
Tuesday, Feb 18, 5 - 6 PMThursday, Feb 20, 11 AM -12:30 PMMonday, Feb 24, 1 - 3 PM
Andrew Petersen
Wednesday, Feb 19, 10 AM - 12 PMFriday, Feb 21, 1 - 3 PMMonday, Feb 24, 10 AM - 12 PM
![Page 6: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/6.jpg)
Lab 5 Tip
In simulation or on the board, I’m getting indeterminate output values all the time. What can I do?
§ Add a RESET signal which ANDs with the inputs of the flip-flops, so when RESET is 0, the inputs are forced set to 0.
§ Use the pre-made D-flip-flop in Logisim
6
![Page 7: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/7.jpg)
7
Circuit Timing
![Page 8: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/8.jpg)
Timing
§ So far, we have been worried about whether a circuit is functionally correct.
§ Now let’s think about the delay within a circuit.
§ Key concept: latencyú propagation delayú contamination delay
8
![Page 9: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/9.jpg)
Delay Example
§ We measure the interval between the two “50% points” of the changing signals
9
![Page 10: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/10.jpg)
Propagation & Contamination Delay
§ Propagation delay: the maximum time from when an input changes until the output or outputs reach their final value.
§ Contamination delay: the minimum time from when an input changes until any output starts to change its value.
10
![Page 11: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/11.jpg)
Propagation & Contamination Delay
§ Propagation delay: the delay from inputs received until answer ready.
§ Contamination delay: theamount of time we have before the output is corrupted (unusable).
11
![Page 12: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/12.jpg)
Given a circuit diagram,calculate its propagation delay and contamination delay
12
![Page 13: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/13.jpg)
Need to know
§ The propagation and contamination delay of each logic gate used
§ Wire delay is generally ignored ormodeled in a simplified way
13
Gate t_pd(propagation)
t_cd(contamination)
2-input AND 100 picoseconds 60 picoseconds
2-input OR 120 picoseconds 40 picoseconds
![Page 14: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/14.jpg)
Calculate Propagation Delay
§ Find the critical path (path with the largest number of gates)§ then sum up the propagation delay of all the gates on the
critical path§ 100 + 120 + 100 = 320 picoseconds
14
Gate t_pd t_cd
2-input AND 100 ps 60 ps
2-input OR 120 ps 40 ps
![Page 15: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/15.jpg)
Calculate Contamination Delay
§ Find the short path (path with the smallest number of gates)§ then sum up the contamination delay of all the gates on the
short path§ 60 picoseconds
15
Gate t_pd t_cd
2-input AND 100 ps 60 ps
2-input OR 120 ps 40 ps
![Page 16: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/16.jpg)
Knowing how to calculate delays allows us to compare designs by speed for particular technologies .
This allows us to design circuits that are fast.
16
![Page 17: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/17.jpg)
WE = 1
WE
A Y
A Y
WE = 0
A Y
WE A Y
0 X Z
1 0 0
1 1 1
17
Quick intro: Tri-state buffer
![Page 18: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/18.jpg)
Example: fast 4-1 mux
18
two different 4-1 muxes
![Page 19: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/19.jpg)
Example: fast 4-1 mux
19
• We care about the propagation delays of the two circuits.• it tells us “how soon
can I get the answer”• More specifically, we care
about the D-to-Y delay and S-to-Y delay because D and S may arrive at different time.
![Page 20: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/20.jpg)
§ D-to-Y propagation delay:§ 2 x TRISTATE_AY = 100
§ S-to-Y propagation delay§ TRISTATE_ENY + TRISTATE_AY§ = 35 + 50 = 85
20
![Page 21: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/21.jpg)
§ D-to-Y propagation delay:§ TRISTATE_AY = 50
§ S-to-Y propagation delay§ NOT + AND2 + TRISTATE_ENY § = 30 + 60 + 35 = 125
21
![Page 22: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/22.jpg)
Analysis result
§ Circuit 1 propagation:ú D-to-Y: 100 psú S-to-Y: 85 ps
§ Circuit 2 propagationú D-to-Y: 50 psú S-to-Y: 125 ps
§ Which circuit is faster?ú What if D and S arrive at the same time?ú What if D arrives earlier than S?ú What if S arrives earlier than D?
22
![Page 23: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/23.jpg)
Delays: the lower/higher, the better?
§ Propagation delay, typically, should be upper-bounded.ú shorter propagation means getting
answer fasterú How to make it lower?ú shorten the critical path
§ Contamination delay, typically, should be lower-boundedú want to reliably sample the value
before change.ú How to make it longer?ú add buffers to the short path
23
![Page 24: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/24.jpg)
New Topic:
Processor Components
24
![Page 25: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/25.jpg)
Using what we have learned so far (combinational logic, devices, sequential circuits, FSMs), how do we build a processor?
25
![Page 26: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/26.jpg)
Microprocessors
§ So far, we’ve been talkingabout making devices,such as adders, countersand registers.
§ The ultimate goal is tomake a microprocessor, which is a digital device that processes input, can store values and produces output, according to a set of on-board instructions.
26
![Page 27: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/27.jpg)
Read reg 1
Read reg 2
Write reg
Write data
Read data 1
Read data 2
Registers
ALU result
ZeroA
BALU
0
1
0123
4
A
B
Instruction [31-26]
Instruction Register
Instruction [25-21]
Instruction [20-16]
Instruction [15-0] 0
1
0
1Memory data
register
Memory data
Memory
Address
Write data
ALU Out
012Shift left 2
0
1
PC
PCWriteCond
PCWrite
IorD
MemRead
MemWrite
MemtoReg
IRWrite
PCSourceALUOp
ALUSrcB
ALUSrcA
RegWrite
RegDstOpcode
ControlUnit
Shift left 2Sign extend
The Final Destination
27
![Page 28: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/28.jpg)
Deconstructing Processors
§ Processors aren’t so bad when you consider them piece by piece:
Storage Thing
Arithmetic Thing
Controller Thing
28
![Page 29: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/29.jpg)
Microprocessors
§ These devices are acombination of theunits that we’vediscussed so far:ú Registers to store values.ú Adders and shifters to process data.ú Finite state machines to control the process.
§ Microprocessors are the basis of all computing since the 1970’s and can be found in nearly every sort of electronics.
29
![Page 30: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/30.jpg)
aka: the Arithmetic Logic Unit (ALU)
The “Arithmetic Thing”
30
![Page 31: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/31.jpg)
We are here
Assembly Language
ProcessorsFinite State Machines
Arithmetic Logic Units
Devices Flip-flops
Circuits
Gates
Transistors
31
![Page 32: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/32.jpg)
Arithmetic Logic Unit
§ The first microprocessorapplications were calculators.ú Recall the unit on adders and
subtractors.ú These are part of a larger
structure called the arithmetic logic unit (ALU).
§ This larger structure is responsible for the processing of all data values in a basic CPU.
32
![Page 33: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/33.jpg)
ALU inputs§ The ALU performs all of
the arithmetic operationscovered in this course sofar, and logical operationsas well (AND, OR, NOT, etc.)ú A and B are the operandsú The select bits (S) indicate which operation is
being performed (S2 is a mode select bit, indicating whether the ALU is in arithmetic or logic mode).
ú The carry bit Cin is used in operations such as incrementing an input value or the overall result.
A B
G
Cin,S VCNZ
33
![Page 34: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/34.jpg)
ALU outputs
§ In addition to the inputsignals, there are outputsignals V, C, N & Z whichindicate special conditionsin the arithmetic result:ú V: overflow condition
The result of the operation could not be stored in the n bits of G, meaning that the result is incorrect.
ú C: carry-out bitú N: Negative indicatorú Z: Zero-condition indicator
A B
G
Cin,S VCNZ
34
![Page 35: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/35.jpg)
The “A” of ALU§ To understand how the ALU does all of these operations,
let’s start with the arithmetic side.§ Fundamentally, this side is made of an adder / subtractor
unit, which we’ve seen already:
CinFA
X0
Y0
S0
FA
X1
Y1
S1
C1FA
X2
Y2
S2
C2FA
X3
Y3
S3
C3Cout
Sub
35
![Page 36: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/36.jpg)
ALU block diagram§ In addition to data inputs and outputs, this circuit
also has: ú outputs indicating the different conditions,ú inputs specifying the operation to perform (similar to Sub).
n-bit ALU
A0A1…An
B0B1…Bn
...
...
G0G1…Gn
...
Data input A
Data input B
Data output G
CinS0
S2S1
Carry input
Operation &Mode select
Cout Carry outputOverflow indicatorNegative indicatorZero indicator
V
NZ
36
![Page 37: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/37.jpg)
Arithmetic components
§ In addition to addition and subtraction, many more operations can be performed by manipulating what is added to input B, as shown in the diagram above.
B inputlogic
n-bit paralleladder
A
B
Cin
S0S1
G
G = X + Y + Cin
Cout
X
Y
n
nn
n
37
![Page 38: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/38.jpg)
Arithmetic operations
§ If the input logic circuit on the left sends B straight through to the adder, result is G = A+B
§ What if Bwas replaced by all ones instead?ú Result of addition operation: G = A-1
§ What if Bwas replaced by B?ú Result of addition operation: G = A-B-1
§ And what if Bwas replaced by all zeroes?ú Result is: G = A. (Not interesting, but useful!)
à Instead of a Sub signal, the operation you want is signaled using the select bits S0 & S1.
38
![Page 39: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/39.jpg)
Operation selection
§ This is a good start! But something is missing…§ What about the carry bit?
Select bits Y
inputResult Operation
S1 S0
0 0 All 0s G = A Transfer
0 1 B G = A+B Addition
1 0 B G = A+B Subtraction - 1
1 1 All 1s G = A-1 Decrement
39
![Page 40: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/40.jpg)
Full operation selection
§ Based on the values on the select bits and the carry bit, we can perform any number of basic arithmetic operations by manipulating what value is added to A.
Select Input Operation
S1 S0 Y Cin=0 Cin=1
0 0 All 0s G = A (transfer) G = A+1 (increment)
0 1 B G = A+B (add) G = A+B+1
1 0 B G = A+B G = A+B+1 (subtract)
1 1 All 1s G = A-1 (decrement) G = A (transfer)
40
![Page 41: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/41.jpg)
The “L” of ALU§ We also want a circuit
that can performlogical operations,in addition toarithmetic ones.
§ How do we tellwhich operationto perform?ú Another select bit!
§ If S2 = 1, then logic circuit block is activated.§ Multiplexer is used to determine which block
(logical or arithmetic) goes to the output.
4-to-1mux
A
B
S0S1
G
1
0
3
2
41
![Page 42: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/42.jpg)
Single ALU Stage
Logiccircuit
S0S1
Gi
S0S1
AiBi
AiBi Arithmetic
circuitS0S1
AiBi
CiCi+1Ci
0
1
S2
VNZ
Gi
Gi
42
![Page 43: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/43.jpg)
Multiplication
43
![Page 44: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/44.jpg)
What about multiplication?
§ Multiplication (and division) operations are always more complicated than other arithmetic (addition, subtraction) or logical (AND, OR) operations.
§ Three major ways that multiplication can be implemented in circuitry:ú Layered rows of adder units.ú An adder/shifter circuitú Booth’s Algorithm
44
![Page 45: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/45.jpg)
Multiplication
§ Multiplier circuits canbe constructed asan array of addercircuits.
§ This can get expensive as the size of the operands grows.
§ Is there an alternative to this circuit?
45
![Page 46: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/46.jpg)
Multiplication
§ Revisiting grade 3 math…
123x 456
12 3x 456
1368
1 2 3x 456
1368912
1 23x 456
1368912456
123x 456
1368912456
56088
46
![Page 47: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/47.jpg)
Multiplication
§ And now, in binary…
101x 110
10 1x 110
110
1 0 1x 110
110000
1 01x 110
110000110
101x 110
110000110
11110
47
![Page 48: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/48.jpg)
Observations
§ Calculation flowú Multiply by 1 bit of multiplierú Add to sum and shift sumú Shift multiplier by 1 bitú Repeat the above
§ What is “multiply by 1 bit of binary”?ú 10101 x 1 ?ú 10101 x 0 ?ú It’s an AND!
48
101x 110
110000110
11110
![Page 49: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/49.jpg)
Accumulator circuits§ What if you could perform each stage of the
multiplication operation, one after the other?ú This circuit would only
need a single row ofadders and a coupleof shift registers.
Adder
Register R
Shift Left 1
Shift Left 1
Register Y
Register X
1xn AND
49
101x 110
110000110
11110
![Page 50: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/50.jpg)
Make it more efficient
Think about 258 x 9999§ Multiply by 9, add to sum, shift, multiply by 9, add to sum, shift,
multiple by 9, add to sum, shift, multiply by 9, add to sum.
§ 258 x 9999 = 258 x (10000 - 1) = 258 x 10000 – 258§ Just shift 258, becomes 2580000, then do 2580000 – 258§ More efficient!
50
![Page 51: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/51.jpg)
Efficient Multiplication: Booth’s Algorithm
§ Take advantage of circuits where shifting is cheaper than adding, or where space is at a premium.ú when multiplying by certain values (e.g. 99), it can be easier to think
of this operation as a difference between two products.
§ Consider the shortcut method when multiplying a given decimal value X by 9999:ú X*9999 = X*10000 – X*1
§ Now consider the equivalent problem in binary:ú X*001111 = X*010000 – X*1
§ More details: https://en.wikipedia.org/wiki/Booth%27s_multiplication_algorithm
51
![Page 52: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/52.jpg)
Reflections on Multiplication
§ Multiplication isn’t as common an operation as addition or subtractio, but occurs enough that its implementation is handled in the hardware.
§ Most common multiplication and division operations are powers of 2. For this, the shift register is used instead of the multiplier circuit.
ú e.g., x * 8 is implemented as x << 3
52
![Page 53: CSC258 Week 6258/files/andrew/lec06-ALU.pdf · Announcements §Next week úReading ... 1 1 1 17 Quick intro: Tri-state buffer. Example: fast 4-1 mux 18 two different 4-1 muxes. Example:](https://reader034.fdocuments.net/reader034/viewer/2022042223/5eca56b0c38f4e40c93e9b33/html5/thumbnails/53.jpg)
Storage Thing
Arithmetic Thing
Controller Thing
53
Next