Professional Documents
Culture Documents
How Computers Work: Computer Arithmetic
How Computers Work: Computer Arithmetic
How Computers Work: Computer Arithmetic
Lecture 4
Computer Arithmetic
XADDR
RA1
Memory
RD1 BRZ(R31,XADDR,XP)
ISEL 0 1
OPCODE RA C RB RC
+1 0 1
ASEL BSEL
0 1 2 1 0
A B
ALUFN ALU
A op B
Z
RA2
Memory
RD2
PCSEL 0 1 0 1 2 WDSEL
D WD WA WD WA RC
PC Memory Register File
WE WEMEM WE WERF
1
What are we going to learn today?
2
A Wild and Crazy Idea:
Arithmetic / Logic Unit is describable by a
table:
ergo, we can implement it with a memory:
32
A
B 32 32
ALUFN
Bad Idea, because:
A few 2 ~70 is a large number of rows!
Ci A B S Co
0 0 0 0 0 Generates 1 sum bit, carry
0 0 1 1 0 Can be cascaded to N bits
0 1 0 1 0
0 1 1 0 1 AB
1 0 0 1 0
1 0 1 0 1
Co FA Ci
1 1 0 0 1
1 1 1 1 1
S
3
Ripple-carry N-bit adder:
FA FA FA FA
4
But What is Co really ?
Ci A B S Co
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
S:
0 1 0 1
Ci A B S Co
0 0 0 0 0 Ci 1 0 1 0
0 0 1 1 0
0 1 0 1 0 B
0 1 1 0 1
A
1 0 0 1 0
1 0 1 0 1 0 0 1 0
1 1 0 0 1 Co:
1 1 1 1 1 Ci 0 1 1 1
B
How Computers Work Lecture 4 Page 10
5
The Karnaugh Map
Characteristics:
1: Unit-Distance Input Labels
2: Wrap-Around
AND
A
Q
B
Q
0
0
A 1
0 B
6
OR
A
Q
B
Q
0
1
A 1
1 B
XOR
A
Q
B
Q
0
1
A 0
1 B
7
Q: What is Cout?
A
0 0 1 0
Ci 0 1 1 1
B
Q: What is Cout?
A
0 0 1 0
Ci 0 1 1 1
B
A: (A and Ci) or (A and B) or (B and Ci)
A: (A Ci) + (A B) + (B Ci)
A: A Ci + A B + B Ci
8
How about S ?
Ci A B S
0 0 0 0
0 0 1 1 A
0 1 0 1
0 1 1 0 0 1 0 1
1 0 0 1 Ci 1 0 1 0
1 0 1 0
1 1 0 0 B
1 1 1 1
Parity
A
B
S
Ci
9
Tree Structure
A1
A2
A3
A4
AN
O(n) gates.
How Computers Work Lecture 4 Page 19
An Idea !
Speed things up by doing as much work as
possible on A & B Inputs before the carry
arrives:
?
?
How Computers Work Lecture 4 Page 20
10
Generate and Propagate
G
(35)
S:
0 0 X 1 A
Ci 1 1 X 0 G: 0 0 1 0
B
P
A
(36) G
P: 0 1 0 1
Co:
0 1 X 0 B
Ci 0 1 X 1
P
How Computers Work Lecture 4 Page 21
Implementation of Co
A B
G=AB
P = A xor B
G P
Cout = G + P Cin
Cout Cin
11
Implementation of S
G=AB
P = A xor B
G P
S = P xor Cin
Cin
S
How Computers Work Lecture 4 Page 23
12
The 74181 ALU
13
Any more tricks to go faster?
What about changing the Encoding of the inputs (i.e. base
4 !!!!!!!)
O(log(n)) limitation still there, but converting to a higher radix,
doing the computation, then going back to binary CAN be faster
than doing it naively in binary.
How about analog computing?
Works, but watch out for noise.
How about parallel computing?
Works, but watch out for cost.
How about pipelined computing?
Q: Whats a pipelined computer?
A: Youre going to find out real soon.
How Computers Work Lecture 4 Page 27
Summary
Todays Lecture:
How to build the Arithmetic/Logical Unit
Time/Space/Cost Trade-offs
Recitation
K-maps and sum-of-products form
Multipliers
14