Contact Session 2
Contact Session 2
Contact Session 2
4-bit 8-bit
0100 (4) 00000100 (still 4)
1100 (-4) 00001100 (12, not -4)
•Instead, replicate the MS bit -- the sign bit:
4-bit 8-bit
0100 (4) 00000100 (still 4)
1100 (-4) 11111100 (still -4)
Overflow
•If operands are too big, then sum cannot be represented as an
n-bit 2’s comp number.
01000 (8) 11000 (-8)
+ 01001 (9) + 10111 (-9)
10001 (-15) 01111 (+15)
•We have overflow if:
– signs of both operands are the same, and
– sign of sum is different.
•Another test -- easy for hardware:
– carry into MS bit does not equal carry out
Logical Operations
•AND
– useful for clearing bits 11000101
• AND with zero = 0 AND 00001111
• AND with one = no change 00000101
•OR 11000101
– useful for setting bits OR 00001111
• OR with zero = no change 11001111
• OR with one = 1
•NOT NOT 11000101
– unary operation -- one argument 00111010
– flips every bit
Digital Logic
Structures
Transistor: Building Block of Computers
•Microprocessors contain millions of transistors
– Intel Pentium II: 7 million
– Compaq Alpha 21264: 15 million
– Intel Pentium III: 28 million
– Intel Pentium IV: 42 million
•Logically, each transistor acts as a switch, meaning that
we can operate it at either saturation or cutoff but nowhere
else along the load line. When saturated, a transistor is like
a closed switch. When cutoff, it’s like an open switch.
•Combined to implement logic functions
– AND, OR, NOT
•Combined to build higher-level structures
– Adder, multiplexer, decoder, register, …
Simple Switch Circuit
•Switch open:
– No current through circuit
– Light is off
– Vout is +2.9V
•Switch closed:
– Short circuit across switch
– Current flows
– Light is on
– Vout is 0V
Switch-based circuits can easily represent two states:
on/off, open/closed, voltage/no voltage.
Basic Logic Gates
More than 2 Inputs?
•AND/OR can take any number of inputs.
– AND = 1 if all inputs are 1.
– OR = 1 if any input is 1.
– Similar for NAND/NOR.
A B C D
0 0 0 0 1. AND combinations
that yield a "1" in the
0 0 1 0 truth table.
0 1 0 1
0 1 1 0
2. OR the results
1 0 0 0 of the AND gates.
1 0 1 1
D = A . B . C + A . B. C
1 1 0 0
1 1 1 0
Practice
•Implement the following truth table.
A B C
0 0 0
0 1 1
1 0 1
1 1 0
• Implement the following Expression.
Y = A + AB + AB
DeMorgan's Laws
Law I: AB = A + B
A B AB A B AB A+B
0 0 0 1 1 1 1
0 1 0 1 0 1 1
1 0 0 0 1 1 1
1 1 1 0 0 0 0
DeMorgan's Laws
Law II: A+B=A.B
2-bit
decoder
Multiplexer
• A multiplexer is a circuit with many inputs
but only one output. By applying control
signals, we can steer any input to the
output. The circuit has n input signals, m
control signals, and 1 output. Multiplex
means many into one.
Multiplexer (MUX)
•n-bit selector and 2n inputs, one output
– output equals one of the inputs, depending on selector
4-to-1 MUX
Adder Circuits
• A Half Adder is a circuit which adds two
binary digit at a time.
• A Half Adder has only two inputs and there
is no provision to add a carry coming from
the lower order bit when multi-bit addition
is performed.
• A Full Adder is used to perform multi-bit
addition.
Full Adder
•Add two bits and carry-in,
produce one-bit sum and carry-out.
A B Cin S Cout
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
Combinational
•Combinational Circuit
vs. Sequential
– always gives the same output for a given set of inputs
• ex: adder always generates sum and carry,
regardless of previous inputs
•Sequential Circuit
– stores information
– output depends on stored information (state) plus input
• so a given input might produce different outputs,
depending on the stored information
– example: ticket counter
• advances when you push the button
• output depends on previous state
– useful for building “memory” elements and “state machines”
Latch
• The latch is a electronic circuit used to store
information in asynchronous sequential
logic systems. One latch can store one bit of
information. Latches often occur in
multiples, some of which have special
names, such as the 'quad latch' (which can
store four bits) and the 'octal latch' (eight
bits).
R-S Latch: Simple Storage Element
•R is used to “reset” or “clear” the element – set it to zero.
•S is used to “set” the element – set it to one.
1 1
0 1 1 0
1
1 0 0 1
0
1 1
•If both R and S are one, out could be either zero or one.
– “quiescent” state -- holds its previous value
– note: if a is 1, b is 0, and vice versa
Clearing the R-S latch
•Suppose we start with output = 1, then change R to zero.
1
0 1
1
1 0
0
1 Output changes to zero.
1
1 0
1
0 1
0
0
0 1
1 0
•R = S = 0
– both outputs equal one
– final state determined by electrical properties of gates
– Don’t do it!
Gated D-Latch
•Two inputs: D (data) and WE (write enable)
– when WE = 1, latch is set to value of D
• S = NOT(D), R = D
– when WE = 0, latch holds previous value
• S=R=1
Register
•A register stores a multi-bit value.
– We use a collection of D-latches, all controlled by a common
WE.
– When WE=1, n-bit value D is written to register.