Professional Documents
Culture Documents
Computer Architecture: Trần Trọng Hiếu
Computer Architecture: Trần Trọng Hiếu
8/7/2019 1
Fundamentals
8/7/2019 2
Boolean Algebra
8/7/2019 3
Digital Representation
5V 5V 1 1
0V 0V 0 0
8/7/2019 4
Analog Voltage Waveform Digital Voltage Waveform
Digital Processing
⚫ Combine “1”s and “0”s in different ways
⚫ To generate more “1”s and “0”s
⚫ This is finally what a computer really does
⚫ Need a well defined mechanism
⚫ Ease design & development of circuits
⚫ Boolean Algebra
⚫ Mathematical framework for processing “1”s & “0”s
⚫ Based on simple, scalable primitive operations
▪ Easy to realize using basic hardware components
⚫ Scales to reason about complex operations
⚫ Leads to information processing
▪ When combined with suitable interpretations
8/7/2019 5
Axioms of Boolean Algebra
⚫ Two Boolean constants
⚫ “1” or “true”
⚫ “0” or “false”
⚫ Boolean variables
⚫ An unknown Boolean value
⚫ Can be “1” or “0” (but not both at the same time)
⚫ 3 primary Operators
⚫ NOT (unary operator)
⚫ AND (Binary operator)
⚫
8/7/2019 OR (Binary operator) 6
Truth Table
8/7/2019 7
NOT Operator
A A
0 1
1 0
8/7/2019 8
AND Operator
⚫ AND operator
⚫ Binary operator: Uses 2 operands
⚫ Result is a “1” only if both operands are “1”
⚫ AND operation is represented as AB or A•B
⚫ Where A and B are two Boolean variables
⚫ AND is described by the following truth table:
A B A•B
0 0 0
0 1 0
1 0 0
1 1 1
8/7/2019 9
OR Operator
⚫ OR operator
⚫ Binary operator: Uses 2 operands
⚫ Result is a “1” if any one of the operand is a “1”
⚫ OR operation is represented as A+B
⚫ Where A and B are two Boolean variables
⚫ OR is described by the following truth table:
A B A+B
0 0 0
0 1 1
1 0 1
1 1 1
8/7/2019 10
Exercises
8/7/2019 11
Boolean Expression
⚫ Combination of operands & operators
⚫ Examples
⚫ A+A
⚫ (A+B)•1
⚫ (A•0)+(B•0)
⚫ A•1+B•1
⚫ Operator precedence
⚫ Inner most parentheses
⚫ NOT
⚫ AND
⚫ OR
8/7/2019 12
Boolean Equations & Truth
Tables
⚫ Illustrate Truth Table for A+B•C
A B C B•C A+B•C
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
8/7/2019 1 1 1 13
Laws of Boolean Algebra
⚫ Identity law
⚫ A+0=A
⚫ A•1=A
⚫ A=A
⚫ Zero and One laws
⚫ A+1=1
⚫ A•0=0
⚫ Inverse laws
⚫ A+A=1
⚫ A•A=0
⚫ Idempotent law: AA=A A+A=A
8/7/2019 14
Laws of Boolean Algebra
(Contd.)
⚫ Given Boolean variables A, B, & C
⚫ Commutative laws
⚫ A+B=B+A
⚫ A•B=B• A
⚫ Associative laws
⚫ A + (B + C) = (A + B) + C
⚫ A • (B • C) = (A • B) • C
⚫ Distributive laws
⚫ A • (B + C) = (A • B) + (A • C)
⚫ DeMorgan’s laws
⚫ (A • B) = A + B
8/7/2019 ⚫ (A+B) = A • B 15
Verification of Laws (1)
A A+0
0 0
1 1
8/7/2019 16
Verification of Laws (2)
⚫ Distributive law
⚫ A • (B + C) = (A • B) + (A • C)
A B C A•(B+C) (A•B)+(A•C)
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
8/7/2019 17
1 1 1
More Boolean Operators
⚫ Other commonly used Boolean Operators
⚫ Convenient when implementing logic operations using
electronic components
⚫ NAND
⚫ (A•B)
⚫ NOR
⚫ (A+B)
8/7/2019 18
English to Logic Conversion
⚫ Straightforward strategy
⚫ Use common sense
⚫ Identify independent clauses
⚫ Look for “and” & “or” clauses in sentences
⚫ Identify primary inputs
⚫ Work logic out for each independent clause
⚫ Connect them back together
⚫ Optimize the final equation
⚫ We will not deal with optimizations in this course
⚫ Verify using Truth Table
8/7/2019 19
Example 1
⚫ Output is 1 only if the two primary inputs are
zero
⚫ Let the primary inputs be A and B
⚫ Output is 1 in the following cases
⚫ A=0 & B=0 => A • B
⚫ The above equation can be rewritten as:
⚫ (A+B)
8/7/2019 20
Example 2
⚫ Output is 1 only if the two primary inputs are
different
⚫ Let the inputs be A and B
⚫ Output is 1 in the following cases
⚫ A=0, B=1 => A•B
⚫ A=1, B=0 => A•B
⚫ Combining the above two cases gives:
⚫ (A•B)+(A•B)
⚫ This operation is called Exclusive-OR or XOR
▪ It is frequently used
▪ Represented as A + B
8/7/2019 21
Truth Table for XOR
A B A+B
0 0 0
0 1 1
1 0 1
1 1 0
8/7/2019 22
Digital Logic Circuits
8/7/2019 23
Basic transitor gates
⚫ Interconnected set of Transistors called Circuits
⚫ Transistors are Electronic Switches
⚫ Turn “On” or “Off”
▪ Depending on input voltages
⚫ Used to implement Boolean expressions Transistor
8/7/2019 25
Expression construction
A
C
B
(A•B)+C
8/7/2019 26
Logic Gates
8/7/2019 27
Basic Gates
⚫ Corresponding to basic operations in Boolean
Algebra
⚫ NOT Gate Output
A A
⚫ XOR
A AB
B
8/7/2019 29
Equations to Circuits
⚫ Convert Boolean equations to Logic Circuits
⚫ Logic circuits drawn on paper are often also called
Schematics
⚫ Straightforward process
⚫ Convert each operator to a Logic Gate
⚫ Suitably connect inputs and output
⚫ Pay attention to crossing lines versus connected lines
A A A
B B A
No relationship
⚫ Label all inputs No
andrelationship
outputs These two lines/wires
between
8/7/2019
A & B. between A & B. This are the same! 30
is preferred!
Example 1
There are a few aspects to consider when using
⚫ A•B•C•D the shortcut version:
1. All gates must be the same
⚫ (A•B)•(C•D) 2. Input to output transformation must be
straightforward
A A•B
A
B A•B•C•D B A•B•C•D
C
C
D
D C•D
⚫ Solution
⚫ O = (A•C)+(B•C)
A A•C
O=(A•C)+(B•C)
C
B
B•C
S1 S2 S3 O
0 0 0 A
Draw
0 0 1 B
the
0 1 0 C circuit?
0 1 1 D
1 0 0 E
8/7/2019 34
Logic Circuit for Selector
A
C O
8/7/2019
S1 S2 S3 35
Multiplexer (Mux)
•••
Multiplexer
⚫ Such that 2k >= N
⚫ 1 output line •••
K select
lines
8/7/2019 36
De-Multiplexer (DeMux)
•••
NxK
1 Input N Outputs
•••
De-Multiplexer
8/7/2019 37
De-Multiplexer Logic Circuit
⚫ 1 X 4 De-Multiplexer
A•S1•S2
A•S1•S2
A•S1•S2
A•S1•S2
8/7/2019 S1 S2 38
Decoder Logic Circuit
⚫ A sample decoder
S1•S2
S1•S2
S1•S2
S1•S2
8/7/2019 S1 S2 39
Timing
⚫ Gates take time to work
⚫ Outputs don’t stabilize for some time
⚫ Stabilization time is usually in nanoseconds
⚫ Gate delays compound in circuits
⚫ Final output is not ready until all gates are stable
⚫ Propagation delay
▪ Time taken for changes at the input to propagate to
output
⚫ Typically, the longest path from input to output
⚫ This is often called the “critical path” in a circuit
8/7/2019 40
Example
A A•B
2ns
B A•B•C•D
2ns
C
2ns
D C•D
8/7/2019 41
Timing Diagrams
8/7/2019 42
Timing Diagram Example
A A•B
2ns
B A•B•C
2ns
C
A.B
A.B.C
8/7/2019 44
Clock Example
⚫ Clocked I/O
⚫ Minimum clock period = 4ns
⚫ Maximum Frequency = 1/4ns = 250 MHz
A
2ns A•B•C
Clock 2ns
2ns
B
4 ns
8/7/2019 45
Bus clock example
⚫ A computer with
⚫ 64 bit data bus
⚫ A read/write operation on RAM takes 4 cycles
8/7/2019 46
Triggering
⚫ Clocks transitions are used in different ways
⚫ Level triggering
⚫ When clock is in a given state
⚫ Edge triggering
⚫ Raising edge triggered
▪ When the clock is in transition from 0 → 1
⚫ Falling edge triggered
▪ When the clock is in transition from 1 → 0
Rising Falling
edge Clock edge
8/7/2019 47
Latches
⚫ Latches maintain state
⚫ Can be set to a specific value
⚫ Output of latches does not change even after
Inputs change to 0!
⚫ Fundamental units for storage
⚫ Building blocks for memory
⚫ Latches always store data when the clock is
at a fixed level
⚫ Hence they are also called as level triggered
device
8/7/2019 48
Set-Reset (SR) Latch
S
Q
Q
R
S R Q
0 0 No change
1 0 1
0 1 0
8/7/2019 1 1 Unstable 49
Clocked S-R Latch
S Q
Clock /
Enable
Q
R
8/7/2019 50
D-Latch
D Q
Clock /
Enable
Q
8/7/2019 51
D-Flip Flop
⚫ An edge triggered D-Latch is a D-Flip Flop
D Q
Clock
CK CK
D Q D Q
CK CK
8/7/2019 54
Sequential Logic Circuits
8/7/2019 56
Circuit to read a Bit
4 X 2 Multiplexer
8/7/2019 57
Circuit to write a Bit
⚫ Given 4 Flip Flops, develop a logic circuit to
select and change data in a given Flip Flop.
Input D Q
2X4 CK
Clock to trigger one of the D Q
De-
D FFs to store the input bit CK
Mux
D Q
CK
D Q
CK
Select Lines
8/7/2019 58
Word
⚫ A fixed number of D-Flip Flops
⚫ Usually powers of 2 (2, 4, 8, 16, 32, 64)
⚫ Operate as a single unit
⚫ Store/Read n-bits at a time
D0 D1 D2 D3
D Q D Q D Q D Q
CK CK CK CK
Q0 Q1 Q2 Q3
8/7/2019 59
Random Access Memory
(RAM)
⚫ RAM is the common form of main memory that is used to
store data and programs in modern computers.
⚫ It is typically designed as a collection of flip flops as shown in
the previous slide
⚫ However fabrication technology is different to reduce cost and
improve transistor densities
⚫ Terminology:
⚫ Lines that carry input or output data are referred to as data lines
or data bus
⚫ The select lines associated with the Mux and DeMux are called
the address bus
▪ The selection data is called address
▪ In programming terminology it is called a pointer or a reference.
8/7/2019 60
Abstract Notation for Memory
Address Bus carries bits for
Selection lines (Mux & De-
Mux). These bits are called
Uni-directional Addresses!
Address Bus
8 Memory Note the relationship
(RAM) between the Memory
configuration and the
Enable (EN) Size of each Slot
number of lines in the
X Address and Data
Read/Write (RD) Logic Number of Slots Buses.
16
(16 x 256)
Bi-directional
Data Bus
8/7/2019 61
Number Representation
8/7/2019 62
Its all 1s and 0s!
8/7/2019 63
Magic of Interpretation
⚫ The key is interpretation
⚫ Different sequence of 1s and 0s are assumed to
convey different meanings to different devices
⚫ Example: What does bits 1011 imply
⚫ Letter “A” on the keyboard
⚫ A number (11) to the CPU
⚫ Color red to the video card
⚫ Music note F# to the sound card
⚫ Sector number 11 to the hard disk drive
8/7/2019 64
Standards
⚫ Interpretations can be problematic
⚫ Different interpretations can lead to confusion
⚫ Problems with portability & interoperability
⚫ Solution: Standards
⚫ Standard ways to represent data
⚫ Different data types need different standards
▪ Integers have different representation versus floating point
numbers
▪ Numbers have different representation than characters and
strings
⚫ Depending on needs
8/7/2019
⚫ Efficiency of hardware implementation 65
Integer representation
Example binary
22 21 20
number: 1 0 1
8/7/2019 69
Unsigned Decimal to Unsigned
Binary Conversion
⚫ Performed through successive division by 2
⚫ Until quotient becomes 1
⚫ Writing remainders in reverse order
⚫ Example convert 510 to binary
Remainder
2 5
2 2 1
1 0
510 = 1012
8/7/2019 70
Example 2
⚫ Convert 12 to binary
2 12
2 6 0
2 3 0
1 1
1210 = 11002
8/7/2019 71
Fixed Size Representation
8/7/2019 72
Example
⚫ Represent 1210 as a 8-bit binary number
⚫ Solution:
⚫ Convert 1210 to binary which is 11002
⚫ Now 11002 as 8-bit number = 000011002
▪ Padding 4 leading 0s to make it 8-bits wide
⚫ Represent 3910 as a 5-bit binary number
⚫ Solution:
⚫ Convert 3910 to binary which is 1001112
▪ Cannot fit 6-bits into 5-bits position!
⚫ Drop left-most digits as necessary
▪ Result = 001112
8/7/2019 73
Binary to Decimal Conversion
⚫ Multiply by powers of 2 and add
⚫ Powers of 2 increase from left to right!
⚫ Example: Convert 1102 to decimal
22 21 20
1 1 0
Decimal = (1*22) + (1*21) + (0*20)
= 4 + 2 + 0 =6
1102 = 610
8/7/2019 74
Binary to Decimal Conversion
(Example 2)
⚫ Example if K = 8
⚫ With 8 bits, maximum number = 28-1 = 255
8/7/2019 77
Octal representation
1 2
8310 = 1238
8/7/2019 79
Octal to Decimal Conversion
8/7/2019 80
Octal to Binary Conversion
8/7/2019 82
Hexadecimal Representation
8/7/2019 83
Motivation for Hex
⚫ Primarily for display purposes
⚫ Originally intended for 7-segment displays
8/7/2019 84
Decimal to Hex Conversion
2 D (1310)
73410 = 2DE16
8/7/2019 85
Hex to Decimal Conversion
8/7/2019 86
Hexal to Binary Conversion
8/7/2019 88
Table of Equivalent Values
Dec. Binary Octal Hexal Dec. Binary Octal Hexal
010 02 08 016 810 10002 108 816
110 12 18 116 910 10012 118 916
210 102 28 216 1010 10102 128 A16
310 112 38 316 1110 10112 138 B16
410 1002 48 416 1210 11002 148 C16
510 1012 58 516 1310 11012 158 D16
610 1102 68 616 1410 11102 168 E16
710
8/7/2019
1112 78 716 1510 11112 178 F16 89
Binary Addition
Computer Architecture
8/7/2019 90
Review of Addition
8/7/2019 91
Example
1 7 7
8/7/2019 92
Binary Addition
A B Cin Sum Cout
0 0 0 0 0
⚫ Proceeds in a similar
fashion as conventional 0 0 1 1 0
addition 0 1 0 1 0
⚫ Bits are added from right
to left 0 1 1 0 1
⚫ Sum is 1 or 0
⚫ Carry is 1 or 0
1 0 0 1 0
⚫ Results from addition of 1 0 1 0 1
bits is illustrated in the
adjacent truth table. 1 1 0 0 1
1 1 1 1 1
8/7/2019 93
Binary Addition: Example 1
1 1 0 0 0
8/7/2019 94
Logic Circuit to add 2 Bits: Half
Adder
⚫ Truth table for sum &
carry bits are as A B Sum Cout
follows. 0 0 0 0
⚫ Given the truth table 1 0 1 0
⚫ Sum = A + B
⚫ Cout = A • B 0 1 1 0
1 1 0 1
A
Half Sum = A + B
B
Carry = A • B
Adder
8/7/2019 95
Logic Circuit to add 3 bits: Full
Adder
⚫ Refer to truth table shown earlier
⚫ Sum = A + B + C
⚫ Carry = (A•B) + (B•C) + (C•A)
A A B
B Sum
C
FullAB
BC Carry
Adder
CA
8/7/2019 96
Ripple Carry Adder
8/7/2019 99
Need for Signed
Representations
⚫ Unsigned representations cannot represent
negative numbers
⚫ Such as: -2, -51 etc.
⚫ However negative numbers are frequently
used
⚫ Need a representation for positive & negative
numbers – that is, signed numbers
8/7/2019 100
Standard Signed
Representations
⚫ Signed numbers are represented using 3
different standards
⚫ Sign-bit Magnitude (SBM) representation
⚫ 1’s Complement Representation
⚫ 2’s Complement Representation
⚫ This is the representation that is used by computers
today!
8/7/2019 101
Strategy for Signed
Representation
⚫ General strategy is as follows:
⚫ All representations assume fixed size
⚫ 8, 16, 32, or 64 bits operated on as a single unit-word
⚫ Given n bits (unsigned range: 0 to 2n-1)
⚫ Break the range into two halves
⚫ One half represents positive numbers
⚫ 0 to 2n-1-1 corresponds to positive numbers
▪ Decimal value: 0 to 2n-1-1
⚫ Another half represents negative numbers
⚫ 2n-1 to 2n-1 corresponds to negative numbers
8/7/2019 ▪ Decimal range: -2n-1 to -1 102
Sign-Bit Magnitude (SBM)
Representation
⚫ Uses left-most bit called sign bit to indicate
sign
⚫ Sign bit = 0 implies positive number
⚫ Sign bit = 1 implies negative number
⚫ Example:
27 26 25 24 23 22 21 20
1 0 0 0 1 0 0 1
Sign-bit
Decimal value = -910
8/7/2019 103
SBM Examples (1)
8/7/2019 108
1’s Complement
8/7/2019 109
2’s Complement
Add 12
8/7/2019 111
2’s Complement Example
Binary to decimal
Invert all bits
(positive number)
Add 1
Binary to decimal
(Negative number)
8/7/2019 113
Example
⚫ Convert 8-bit 2’s complement to decimal
⚫ Case 1: 000010102
⚫ Sign bit is 0 indicating positive number
⚫ Simply convert binary to decimal to get 1010
⚫ Case 2: 111110102
⚫ Sign bit is 1 indicating negative number
⚫ Step 1: Invert all bits to get 000001012
⚫ Step 2: Add 12 to get 000001102
⚫ Convert binary to decimal to get -610
8/7/2019
▪ Note the negative sign on decimal number! 114
Subtraction using 2’s
Complement
⚫ Perform 510 – 310 using 4-bit 2’s complement
510 – 310 = 510 + (-310)
510 = 01012 INV
-310 = (00112 →11002 + 12) = 11012
510 + (-310) = 01012 + 11012 = 00102
00102 = 210
8/7/2019 115
Subtraction using 2’s
Complement
⚫ Perform 210 – 410 using 4-bit 2’s complement
210 – 410 = 210 + (-410)
210 = 00102 INV
-410 = (01002 →10112 + 12) = 11002
210 + (-410) = 00102 + 11002 = 11102
11102 is 2’s complement result and because
it is negative (sign bit is 1) it needs to be
converted
INV
11102 → 00012 + 12 = 00102 = -210
8/7/2019 116
Subtraction Circuit
A A+B
B Sum
C
FullAB
BC Carry
Adder
CA
8/7/2019 118
Ripple Carry Adder
A2 A1 A0
FA2 B2 FA1 B1 FA0 B0
1
C3 C2 C1 C0
8/7/2019 120
Add/Subtract Circuit
⚫ Circuit to Add or Subtract two 3-bit 2’s complement
number
The XOR gate inverts the bits
only when control input is 1
B2 B1
B0
A2 A1 A0
FA2 FA1 FA0
C
Cout C2 C1 C0 Control Input
0 = Add
8/7/2019 121
1 = Subtract
Division
quotient ⚫ Check for 0 divisor
⚫ Long division approach
dividend
⚫ If divisor ≤ dividend bits
1001
⚫ 1 bit in quotient, subtract
1000 1001010
⚫ Otherwise
-1000
divisor ⚫ 0 bit in quotient, bring down next
10 dividend bit
101
⚫ Restoring division
1010
⚫ Do the subtract, and if remainder
-1000
goes < 0, add divisor back
remainder 10
⚫ Signed division
⚫ Divide using absolute values
n-bit operands yield n-bit
quotient and remainder ⚫ Adjust sign of quotient and remainder
as required
8/7/2019 122
Division Hardware
Initially divisor
in left half
Initially dividend
8/7/2019 123
Faster Division
⚫ Can’t use parallel hardware as in multiplier
⚫ Subtraction is conditional on sign of remainder
⚫ Faster dividers (e.g. SRT division) generate
multiple quotient bits per step
⚫ Still require multiple steps
8/7/2019 124
Multiply
⚫ Grade school shift-add method:
Multiplicand 1000
Multiplier x 1001
1000
0000
0000
1000
Product 01001000
⚫ m bits x n bits = m+n bit product
⚫ Binary makes it easy:
⚫ multiplier bit 1 => copy multiplicand (1 x multiplicand)
⚫ multiplier bit 0 => place 0 (0 x multiplicand)
Shift-add Multiplier Version
Start
Multiplier
64-bit ALU Shift right
2. Shift the Multiplicand register left 1 bit
32 bits
Product
Control test
Write 3. Shift the Multiplier register right 1 bit
64 bits
Done Algorithm
Multiplication
8/7/2019 127
Real numbers
8/7/2019 128
Real numbers
⚫ Decimal real numbers
⚫ 13.234 = 1*101+3*100+2*10-1+3*10-2+4*10-3
⚫ Binary real numbers
⚫ 101.111 = 1*22+1*20+1*2-1+1*2-2+1*2-3=5.875
⚫ Decimal to binary 0.68*2=1.36 1
⚫ 4.68=100.? 0.36*2=0.72 0
⚫ 100.1010111 0.72*2=1.44 1
⚫ Just approximately 0.44*2=0.88 0
0.88*2=1.76 1
⚫ 4.6796875
0.76*2=1.52 1
8/7/2019
0.52*2=1.04 1 129
…
Fixed point real numbers
⚫ Representation
⚫ A number of bits is used to represent the integral
part
⚫ The rest represents the fraction value
⚫ The hardware is less costly
⚫ The precision is not high
⚫ Suitable for some special-purpose embedded
processors
8/7/2019 130
Floating Point
⚫ Representation for non-integral numbers
⚫ Including very small and very large numbers
⚫ Like scientific notation
⚫ –2.34 × 1056 normalized
⚫ +0.002 × 10–4
not normalized
⚫ +987.02 × 109
⚫ In binary
⚫ ±1.xxxxxxx2 × 2yyyy
⚫ Types float and double in C
8/7/2019 131
Floating Point Standard
⚫ Defined by IEEE Std 754-1985
⚫ Developed in response to divergence of
representations
⚫ Portability issues for scientific code
⚫ Now almost universally adopted
⚫ Two representations
⚫ Single precision (32-bit)
⚫ Double precision (64-bit)
8/7/2019 132
IEEE Floating-Point Format
single: 8 bits single: 23 bits
double: 11 bits double: 52 bits
S Exponent Fraction
8/7/2019 136
Floating-Point Example
⚫ Represent –0.75
⚫ –0.75 = (–1)1 × 1.12 × 2–1
⚫ S=1
⚫ Fraction = 1000…002
⚫ Exponent = –1 + Bias
⚫ Single: –1 + 127 = 126 = 011111102
⚫ Double: –1 + 1023 = 1022 = 011111111102
⚫ Single: 1011111101000…00
⚫ Double: 1011111111101000…00
8/7/2019 137
Floating-Point Example
⚫ What number is represented by the single-
precision float
11000000101000…00
⚫ S=1
⚫ Fraction = 01000…002
⚫ Fxponent = 100000012 = 129
⚫ x = (–1)1 × (1 + 012) × 2(129 – 127)
= (–1) × 1.25 × 22
= –5.0
8/7/2019 138
Denormal Numbers
⚫ Exponent = 000...0 hidden bit is 0
x = ( −1)S (0 + Fraction) 2−Bias
⚫ Smaller than normal numbers
⚫ allow for gradual underflow, with diminishing
precision
8/7/2019 143
FP Adder Hardware
Step 1
Step 2
Step 3
Step 4
8/7/2019 144
Floating-Point Multiplication
⚫ Consider a 4-digit decimal example
⚫ 1.110 × 1010 × 9.200 × 10–5
⚫ 1. Add exponents
⚫ For biased exponents, subtract bias from sum
⚫ New exponent = 10 + –5 = 5
⚫ 2. Multiply significands
⚫ 1.110 × 9.200 = 10.212 10.212 × 105
⚫ 3. Normalize result & check for over/underflow
⚫ 1.0212 × 106
⚫ 4. Round and renormalize if necessary
⚫ 1.021 × 106
⚫ 5. Determine sign of result from signs of operands
⚫ +1.021 × 106
8/7/2019 145
Floating-Point Multiplication
⚫ Now consider a 4-digit binary example
⚫ 1.0002 × 2–1 × –1.1102 × 2–2 (0.5 × –0.4375)
⚫ 1. Add exponents
⚫ Unbiased: –1 + –2 = –3
⚫ Biased: (–1 + 127) + (–2 + 127) = –3 + 254 – 127 = –3 + 127
⚫ 2. Multiply significands
⚫ 1.0002 × 1.1102 = 1.1102 1.1102 × 2–3
⚫ 3. Normalize result & check for over/underflow
⚫ 1.1102 × 2–3 (no change) with no over/underflow
⚫ 4. Round and renormalize if necessary
⚫ 1.1102 × 2–3 (no change)
⚫ 5. Determine sign: +ve × –ve –ve
⚫ –1.1102 × 2–3 = –0.21875
8/7/2019 146
FP Arithmetic Hardware
⚫ FP multiplier is of similar complexity to FP
adder
⚫ But uses a multiplier for significands instead of an
adder
⚫ FP arithmetic hardware usually does
⚫ Addition, subtraction, multiplication, division,
reciprocal, square-root
⚫ FP integer conversion
⚫ Operations usually takes several cycles
⚫ Can be pipelined
8/7/2019 147
ALU & CPU
8/7/2019 148
Introducing ALU
Multiplexer
A Out
010
B
011
Sum
Cin Full Adder 100
S0
This approach can be
S1 extended to include other
S2 operations such as subtraction.
8/7/2019
Cout 151
n-bit ALU
⚫ n-bit ALU
⚫ Repeat 1-bit ALU n times
⚫ All 1-bit ALUs get the same selection lines
⚫ Carry out (Cout)from one stage is wired to carry-in
of next state
⚫ Similar to how a ripple carry adder (or subtraction
circuit) is wired
⚫ Performs operation on n-bits simultaneously
8/7/2019 152
Example 4-bit ALU
Selection lines simply renamed to
operation code (OPCode) lines
A3 B3 A2 B2 A1 B1 A0 B0
OP0
OP1
OP2
O 4 O3 O2 O1 O0 Add/Sub
8/7/2019 153
ALU Notation
⚫ An ALU is denoted using the following graphical
notation.
Operand1 Operand2
(A) (B)
Indicates number of 8 8
bits on each line.
The size of each
operand is typically OP Code Result
the same and ALU 010 A•B
corresponds to the
110 A+B
word size.
4 9
210 A
310 B
Operation Result
Selection … …
8/7/2019 (OP Code) 154
Thought Experiment
⚫ Solution: Registers!
⚫ The fundamental storage units.
8/7/2019 155
Registers Revisited
⚫ Fixed number of D-Flip Flops to form a Word
⚫ Corresponding to size of ALU operands!
⚫ Operate as a single unit
⚫ Store/Read n-bits at a time
D0 D1 D2 D3
D Q D Q D Q D Q
CK CK CK CK
Q0 Q1 Q2 Q3
8/7/2019 156
Selecting a Register
8 8
Register 4 11
2
Set of registers is
called a Register File Register
8/7/2019
Select 157
Selecting 2 Registers
⚫ ALU needs 2 operands to work!
⚫ How to select 2 registers from a Register File?
8 8
00 M 00 M
Register 8 U 8
01 01 U
8 X 8 X
File 10 10
8 1 8 2
11 11
2 8 2 8
Register Register
Select 1 Select 2
8/7/2019
Operand1 Operand2158
ALU with Inputs
Mux2
Register
8
File
Mux1
(4)
8 8
What do we do
ALU with results or
output
2 from the2
4 8 ALU?
Results
DeMux
8
Register 2 8
01
8 Result from ALU
Register 3 10
8
Register 4 11
2
8/7/2019
Select Inputs 160
Handling ALU Output
A
Mux2
8
Each device has its own Clock
Register 8
DeMux
selection logic typically 8
specified using a truth 8
File
table! B
Mux1
8
8 8 (4)
Flags
ALU
2
2 2
4 8 Operation Result
010 A•B
110 A+B
Operation 210 Operand1 AOperand2 Destination
8/7/2019 161
Data path
8/7/2019 162
Handling Constant Values
Mux2
the 8 bits from the instruction depending on the
operation. If the operation is to store a constant
Register
DeMux
8 then the ALU8 simply passes the constant bits as its
8
output. The constant bits are then pushed to the
File
BDeMux and are finally stored in the register
Mux1
0
Mux 1
8 indicated by destination
(4)
8
Flags
ALU
4 4 Where do4 these
8 bits actually
4 come from?
4
8/7/2019 165
Operation Operand1 Operand2 Destination
Where do instructions come from?
16
(16 x 256)
Bi-directional
Data Bus
8/7/2019 169
Using Memory
⚫ Memory has 3 primary inputs
⚫ Address Bus carrying address of memory slot
▪ Indicates which memory slot to read or write
⚫ Data Bus (The actual data bits to be stored or read)
⚫ Control signals (Read/Write & Enable)
⚫ How to wire these inputs & outputs to the ALU
data path? We need go provide Addresses
to the Memory unit in order to
⚫ Design requirements do these operations!
▪ Need to store output from ALU
▪ Need to load data from memory into ALU
▪ Need to load instructions from memory into ALU
8/7/2019 170
Tackling Addresses
⚫ Address is used to select a memory slot
⚫ For fetching instructions
⚫ In an repetitive manner
⚫ Typically from consecutive locations
▪ Think of it as an Array in Java!
⚫ Need to somehow generate
// Assume the addresses
each instruction is 16-bits long
short memory[256];
▪ Typically done using some register in the ALU to store
for (int address = 0; (address < 256); address++) {
intermediate results instruction = memory[address];
⚫ For reading/writing data at random addresses
process(instruction);
}
⚫ Address depends on the instruction at hand
▪ The instruction typically needs to identify the address to
read or write.
8/7/2019 171
Address Generation Logic Circuit
⚫ Issues to consider & solutions
⚫ Address needs to be generated by adding 1
⚫ Use a ripple carry adder to add
⚫ Addresses need to be stored before/after add
⚫ Use a register
⚫ Need alternate between address for instructions and
address for storing/reading data
⚫ Use a multiplexer for choosing
⚫ Use a Clock to drive the selection lines of this multiplexer
▪ Select address for instruction first (Clock = 0).
▪ Select address for reading/writing data next (Clock = 1).
8/7/2019 172
Catch!
⚫ Our data path is not symmetric
⚫ Instructions are 16-bits wide
⚫ Data or Registers are 8-bits wide
⚫ How do we design a memory module that can
⚫ Provide 16-bits first
⚫ Provide 8-bits next
⚫ It is going to take some work
⚫ Use the lowest denominator memory module
⚫ One than can provide 1 byte at a time
⚫ Assemble bytes together to make instructions
8/7/2019 173
Working with Bytes…
Instruction Address Bus
Data Chip
Enable RD
Byte 1 Byte 2 Byte 3
8
00 01 1X 8 Memory
De-Mux (8 x 256)
Data Bus
S1 S0 1
Instruction Byte Least significant address bit changes between
/ Data Select 0 and 1 for each consecutive address.
When the clock is low (S1=0) the De-Mux places the bytes read from Memory into Byte1
and Byte2 depending on S0 (so S0, the least significant bit from the address bus) which
switches between 0 and 1 when clock is low to fetch two bytes from memory.. When the
clock is high (S1=1), the De-Mux ignores s0 and places the data read from memory into 174
8/7/2019
Byte 3.
Quiz?
⚫ Any questions?
⚫ How the CPU can communicate with other
devices, such as a keyboard and a modem?
8/7/2019 175