Csci 136 Computer Architecture II
Csci 136 Computer Architecture II
Csci 136 Computer Architecture II
Xiuzhen Cheng
cheng@gwu.edu
Announcement
Homework assignment #4: Due on Feb 22, before
class
Readings: Sections 3.2, 3.3, B.5, B.6
Problems: 3.7, 3.9, 3.10, 3.12, 3.18-3.22
a
32
ALU
result
32
b
32
1010
Detecting Overflow
No overflow when adding a positive and a negative
number
No overflow when signs are the same for
subtraction
Overflow occurs when the value affects the sign:
overflow when adding two positives yields a negative
or, adding two negatives gives a positive
or, subtract a negative from a positive and get a negative
or, subtract a positive from a negative and get a positive
Effects of Overflow
An exception (interrupt) occurs
Control jumps to predefined address for exception
Interrupted address is saved for possible resumption
a
Sum
CarryOut
How could we build a 1-bit ALU for add, and, and or?
How could we build a 32-bit ALU?
A 1-bit ALU
AND and OR
A logic unit performing logic
AND and OR.
Full Adder
A 1-bit Full Adder ((3,2)
adder).
Implementation of a 1-bit
adder
In-Class Question
Prove that you can detect overflow by
CarryIn31 xor CarryOut31
that is, an overflow occurs if the CarryIN to the most
significant bit is not the same as the CarryOut of the
most significant bit
Implementation: Connect
Result31 to Less
Overflow detection
Conditional Branch
MIPS Instruction:
beq $S1, $s2, label
Idea:
Test $s1-$s2. Use
an OR gate to test
whether the result is
0 or not. It $s1=$s2,
set a zero detector.
Function
0000
And
0001
Or
0010
Add
0110
Sub
0111
1100
Slt
NOR
Carry-Lookahead Adder
The concept of propagate and generate
c(i+1) = (ai . bi) + (ai . ci) + (bi . ci) = (ai . bi) + ((ai+bi).ci)
pi = ai + bi;
gi = ai . bi
Carry-Lookahead Adder
CarryOut is 1 if
some earlier
adder generates
a carry and all
intermediary
adders propagate
the carry.
A 16-Bit Adder
Give the equations for
C1, C2, C3, C4?
Better: use the CLA
principle again!
Second-level of
abstraction!
An Example
Determine gi, pi, Gi, Pi, and C1, C2, C3, C4 for the
following two 16-bit numbers:
a:
0010 1001 0011 0010
b:
1101 0101 1110 1011
Do it yourself
Summary
Traditional ALU can be built from a multiplexor plus a
few gates that are replicated 32 times
To tailor to MIPS ISA, we expand the traditional ALU
with hardware for slt, beq, and overflow detection
Carry lookahead is much faster than ripple carry!
CLA principle can be applied multiple times!
Questions?