Professional Documents
Culture Documents
Gates:
Combinational Logic
3
Review Digital Logic
D Q
Value of D is sampled on positive clock
edge.
Q outputs sampled value for rest of
cycle.
CLK
Q
Review: Edge-Triggering in Verilog 7
always @ (CLK)
Q <= D;
endmodule
module ff(D, Q, CLK);
input D, CLK;
output Q;
reg Q;
Correct ?
always @ (posedge CLK)
Q <= D;
endmodule
8
R If Change == 1 on
(red) positive CLK edge
traffic light changes
Y
(yellow)
If Rst == 1 on
positive CLK edge
RYG=100
G
(green)
RYG
100
9
Rst == 1 Change == 1
Rst == 1 Change == 1
Change
Rst == 1 Change == 1
One-Hot Encoding
D Q R D Q G D Q Y
12
Rst == 1 Change == 1
Rst
Change
D Q R D Q G D Q Y
13
D Q R D Q G D Q Y
???
14
D Q
Value of D is sampled on positive clock
edge.
Q outputs sampled value for rest of
cycle.
module ff(Q, D, CLK);
input D, CLK;
CLK
output Q;
reg Q;
endmodule
15
State Elements: Traffic Light Controller
D Q R D Q G D Q Y
D Q R D Q G D Q Y
19
ALU for MIPS ISA
design a 1-bit ALU using AND gate, OR gate, a full
adder, and a mux
20
ALU for MIPS ISA
design a 32-bit ALU
by cascading 32 1-bit ALUs
21
ALU for MIPS
a 1-bit ALU performing AND, OR, addition and
subtraction
Overflow
=Carryin XOR Carryout
26
A 32-bit ALU
constructed from
32 1-bit ALUs
27
A 32-bit ALU
with zero detector
28
29
A Verilog behavioral definition of a MIPS ALU.
30
ALU for MIPS
propagate = a + b; generate = ab
31
ALU for MIPS
shift right
64-bit ALU ADD multiplier
multiplicand
32 bits
shift right
32-bit ALU ADD multiplier
Observations
product reg. wastes space that exactly matches the size
of multiplier
3 steps per bit
combine multiplier register and product register
42
Multiply Hardware Version 3
multiplicand
ADD
32 bit ALU
write into
left half
product (multiplier) control
shift right
43
Multiply Algorithm Version 3
Observations
2 steps per bit because of multiplier and product in one
register, shift right 1 bit once (rather than twice in
version 1 and version 2)
MIPS registers Hi and Li correspond to left and right
half of product
MIPS has instruction multu
How about signed numbers in multiplication ?
method 1: keep the sign of both numbers and use the
magnitude for multiplication, after 32 repetitions, then
change the product to appropriate sign.
method 2: Booths algorithm
Booths algorithm is more elegant in signed number
multiplications
Booths algorithm uses the same hardware as version 3
46
Booths Algorithm
remainder (modulo )
50
Divide Hardware Version 1
divisor
shift right
64-bit ALU
quotient
shift left
2. test remainder
Observations
1/2 bits in divisor always 0
1/2 of divisor is wasted
1/2 of 64-bit ALU is wasted
Possible improvement
instead of shifting divisor to right, shifting remainder to
left ?
first step can not produce a 1 in quotient, so switch order
to shift first and then subtract. This can save one
iteration
54
Divide Hardware Version 2
divisor
shift left
remainder control
55
Divide Algorithm Version 2
start: place dividend in remainder
1. shift remainder left 1 bit
2. sub. divisor from the left half of remainder and place the
result in the left half of remainder
3. test remainder
Observations
3 steps (shift remainder left, subtract, shift quotient left)
Further improvement (version 3)
eliminating quotient register by combining with
remainder register as shifted left
therefore loop contains only two steps, because the shift
of remainder is shifting the remainder in the left half and
the quotient in the right half at the same time
consequence of combining the two registers together is
the remainder shifted one time unnecessary at the last
iteration
final correction step: shift back the remainder in the left
half of the remainder register (i.e., shift right 1 bit of
remainder only)
58
Divide Hardware Version 3
divisor
32bits
32-bit ALU
Observations
same hardware as multiply, need a 32-bit ALU to add and
subtract and a 64-bit register to shift left and right
divide algorithm version 3 is called restoring division
algorithm for unsigned numbers
Signed numbers divide
simplest method
remember signs of dividend and divisor, make
positive, and finally complement quotient and
remainder as necessary
dividend and remainder must have the same sign
quotient is negative if dividend sign and divisor sign
disagree
SRT (named after three persons) method
an efficient algorithm
62
Floating Point Numbers
How about
very small numbers, very large numbers
rationals, such as 2/3; irrationals such as 2;
transcendentals, such as , .
63
Floating Point Numbers
0 = 0 00000000 00000000000000000000000
-1.5 = 1 01111111 10000000000000000000000
64
Floating Point Numbers
- 0.75 = __________________________________
- 5.0 = ___________________________________
7 = ____________________________________
Double precision
64 bits total
52-bit significand
11-bit exponent (excess 1023 bias)
Number is: (-1)s (1.M) x 2E-1023
68
Basic Addition Algorithm
4-bit significand
1.0110 x 23 + 1.1000 x 22
align binary points (denormalize smaller number)
1. 0110 x 23
0. 1100 x 23
No overflow, no rounding
70
Another Addition Example
1.0001 x 23 - 1.1110 x 1
4-bit significand; extra bit needed for accuracy
1. Align binary point:
1. 0001 x 23
- 0. 01111 x 23