Combinational Logic Review G: Far, Far, Away Far, Away
Combinational Logic Review G: Far, Far, Away Far, Away
Combinational Logic Review G: Far, Far, Away Far, Away
g Review
Digital Devices was a LONG, LONG time ago in a galaxy FAR,
FAR, AWAY for many of you.
you
We dont expect you to remember everything you learned in
Digital Devices,
Devices but you need to remember > 0%.
0%
Binary Representation
The basis of all digital data is binary representation.
Binary - means two
1, 0
True, False
Hot, Cold
ld
On, Off
W
We mustt be
b able
bl to
t handle
h dl more than
th just
j t values
l
for
f
real world problems
11, 0,
0 56
True, False, Maybe
Hot,, Cold,, LukeWarm,, Cool
On, Off, Leaky
V 0.5
Number Systems
y
To talk about binary data, we must first talk about
number systems
The decimal number system (base 10) you should
be familiar with!
A digit in base 10 ranges from 0 to 9.
A digit
g in base 2 ranges
g from 0 to 1 ((binary
y number
system). A digit in base 2 is also called a bit.
A digit in base R can range from 0 to R-1
A digit
di i in
i Base 16 can range from
f
0 to 16-1
(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). Use letters A-F to
p
values 10 to 15. Base 16 is also called
represent
Hexadecimal or just Hex.
V 0.5
Positional Notation
Value of number is determined by multiplying each digit by a
weight and then summing. The weight of each digit is a
POWER of the BASE and is determined by position
position.
953.78 = 9 * 102 + 5 * 101 + 3 * 100 + 7 * 10-1 + 8 * 10-2
= 900 + 50 + 3 + .7 + .08 = 953.78
0b1011 11 = 1*23 + 0*22 + 1*21 + 1*20 + 1*2-11 + 1*2-22
0b1011.11
= 8 + 0 + 2 + 1 + 0.5 + 0.25
= 11.75
0xA2F = 10*162 + 2*161 + 15*160
= 10 * 256
+ 2 * 16 + 15 * 1
= 2560 + 32 + 15 = 2607
V 0.5
Common Powers
2-3 = 0.125
2-2 = 0.25
2-11 = 0.5
05
20 = 1
21 = 2
22 = 4
23 = 8
24 = 16
25 =32
26 = 64
27 = 128
28 = 256
29 = 512
210 = 1024
211 = 2048
212 = 4096
160 = 1 = 20
161 = 16 = 24
162 = 256 = 28
163 = 4096 = 212
V 0.5
Leastt Significant
L
Si ifi t Digit
Di it
(has weight of 20 or 1).
For base 2, also called
Least Significant Bit
(LSB). Always
RIGHTMOST digit.
V 0.5
More Conversions
Convert 53 to Hex
53/16 = 3, rem = 5
3 /16 = 0,
0 rem = 3
53 = 0x35
= 3 * 161 + 5 * 160
= 48 + 5 = 53
V 0.5
10
Hex Di
H
Digits
it to
t binary
bi
(cont):
( t)
0x9 = 0b 1001
0xA = 0b 1010
0xB = 0b 1011
0xC = 0b 1100
0xD = 0b 1101
0xE = 0b 1110
0xF = 0b 1111
V 0.5
11
Hex to Binary,
Binary Binary to Hex
0xA2F = 0b 1010 0010 1111
0x345 = 0b 0011 0100 0101
Binary to Hex is just the opposite, create groups of 4 bits
starting with least significant bits. If last group does not
h
have
4 bi
bits, then
h padd with
i h zeros for
f unsigned
i d numbers.
b
0b 1010001 = 0b 0101 0001 = 0x51
12
A Trick!
If faced with a large binary number that has to be
converted to decimal, I first convert the binary number
to HEX,
HEX then convert the HEX to decimal.
decimal Less work!
0b 110111110011 = 0b 1101 1111 0011
=
D
F 3
= 13 * 162 + 15 * 161 + 3*160
= 13 * 256 + 15 * 16 + 3 * 1
= 3328 + 240 + 3
= 3571
Of course, you can also use the binary, hex conversion feature
on your calculator. Too bad calculators wont be allowed on the
first
s test,
es , though...
oug ...
V 0.5
13
V 0.5
14
0 + 0 = 0, carry = 0
0 - 0 = 0, borrow = 0
1 + 0 = 1, carry = 0
1 - 0 = 1,, borrow = 0
0 + 1 = 1, carry = 0
0 - 1 = 1, borrow = 1
1 + 1 = 0,
0 carry = 1
1 - 1 = 0,
0 borrow
b
=0
15
Binary,
y, Decimal addition
Decimal
Binary
0b 101011
34
+ 17
-----51
from LSD to MSD:
7+4 = 1; with carry out of 1
to next column
1 (carry) + 3 + 1 = 5.
answer = 51.
51
+ 0b 000001
--------------101100
From LSB to MSB:
1+1 = 0,
0 carry of 1
1 (carry)+1+0 = 0, carry of 1
1 (carry)+0 + 0 = 1, no carry
1 +0 = 1
0+0=0
1+0=1
answer = % 101100
V 0.5
16
Hex Addition
Decimal check.
0x3A
0x3A = 3 * 16 + 10
= 58
0x28 = 2 * 16 + 8
= 40
58 + 40 = 98
+ 0x28
-------0x62
A+8 = 2; with carry out of
1 to next column
0x62 = 6 * 16 + 2
= 96 + 2 = 98!!
1 (carry) + 3 + 2 = 6.
answer = 0x62
V 0.5
17
18
Subtraction
Decimal
Bi
Binary
900
0b 100
- 001
------899
- 0b 001
------011
19
Hex Subtraction
Decimal check.
0x34
0x34 = 3 * 16 + 4
= 52
0x27 = 2 * 16 + 7
= 39
52 - 39 = 13
- 0x27
---------0x0D
4 7 = D; with borrow of 1
4-7
from next column
0x0D = 13 !!
3 - 1 (borrow) - 2 = 0.
answer = 0x0D.
V 0.5
20
21
Fixed Precision
Withh paper andd pencil,
Wi
il I can write
i a number
b with
i h as many digits
di i as
I want:
11,027,80,032,034,532,002,391,030,300,209,399,302,992,092,920
027 80 032 034 532 002 391 030 300 209 399 302 992 092 920
A microprocessor or computing system usually uses FIXED
PRECISION for integers;
g ; theyy limit the numbers to a fixed
number of bits:
0x AF4500239DEFA231
0x
9DEFA231
0x
A231
0x
31
22
Unsigned
g
Overflow
In this class I will use 8 bit precision most of the time, 16 bit
occasionally.
occasionally
Overflow occurs when I add or subtract two numbers, and the
correct result is a number that is outside of the range of
allowable numbers for that precision. I can have both
unsigned and signed overflow (more on signed numbers later)
8 bits -- unsigned integers 0 to 28 -1 or 0 to 255.
16 bits
bi -- unsigned
i d integers
i
0 to 216-11 or 0 to 65535
N bit unsigned numbers 0 to 2N-1
V 0.5
23
+ 1 = 0x 01
------------------256 /= 0x00
0xF + 1 = 0,
0 carry out
0xF + 1 (carry) + 0 = 0, carry out
Carry out of MSB falls off end, No place to put it!!!
Fi l answer is
Final
i WRONG bbecause could
ld nott store
t
carry out.
t
V 0.5
24
Unsigned
g
Overflow
A carry out of the Most Significant Digit (MSD) or Most
Significant Bit (MSB) is an OVERFLOW indicator for addition
of UNSIGNED numbers.
The
h correct result
l has
h overflowed
fl
d the
h number
b range for
f that
h
precision, and thus the result is incorrect.
If we could
ld STORE th
the carry outt off th
the MSD
MSD, th
then th
the answer
would be correct. But we are assuming it is discarded because
of fixed precision, so the bits we have left are the incorrect
answer.
V 0.5
25
black
red
pink
yellow
brown
blue
green
white
V 0.5
26
27
ASCII
American Standard
Code for Information
Interchange
V 0.5
28
UNICODE
UNICODE is a 16-bit code for representing alphanumeric data.
With 16 bits, can represent 216 or 65536 different symbols.
16 bits = 2 Bytes per character (the extended version uses 32
32-bits
bits
per character, or 4 bytes, for 4,294,967,296 different symbols).
0x0041-005A A-Z
0x0061-4007A a-z
Some other alphabet/symbol ranges
0x3400-3d2d
0x3040-318F
0 4E00 9FFF
0x4E00-9FFF
29
V 0.5
30
V 0.5
31
C
Copyright
i h 2005.
2005 Thomson/Delmar
Th
/D l
Learning,
L
i All rights
i h
reserved.
V 0.5
32
DeMorgans Law
V 0.5
33
V 0.5
34
Representing 1 and 0
In the electrical world, two ways of representing 0 and 1
are (these are not the only ways):
Presence or absence of electrical current
Different Voltage levels
35
Switch Inputs
High True switch
Vdd
Vdd
Vdd is power
supply voltage,
typically 5V or
3.3V
H
Gnd is 0 V
Gnd
Gnd
Switch open
(negated), output is L
V 0.5
36
Vdd
Gnd
Gnd
37
transistor
operation of P, N
types is
complementary
to each other
V 0.5
38
V 0.5
39
In digital logic,
logic NMOS must be connected to ground,
ground PMOS to
VDD.
V 0.5
40
Y
1
1
1
0
out
V 0.5
41
AB
0 0
0 1
1 0
1 1
V 0.5
42
43
Tri-State Buffer
There iis another
Th
h way to d
drive
i a li
line or bus
b ffrom multiple
li l
sources. Use a TRISTATE buffer.
EN
A
EN
A
When EN = 1, then Y = A.
When EN = 0, then Y = ??????
Y is undriven, this is called the high impedance state.
Designate high impedance by a Z.
g impedance)
p
)
When EN = 0,, then Y = Z ((high
V 0.5
44
45
V 0.5
46
Binaryy Adder
F (A,B,C) = A xor B xor C
G = AB + AC + BC
Co
Ci
Cin
V 0.5
47
Cout C(4) A
Co
A(2) B(2)
C(3)
Ci
Co
Ci
A(1) B(1)
C(2)
Co
Ci
Sum(3)
Sum(2)
Sum(1)
A(0) B(0)
C(1)
Co
Ci
C(0)
Cin
Sum(0)
A[3:0]
[ ]
B[3:0]
SUM[3:0]
V 0.5
48
Incrementer
A(3)
A(2)
A(1)
A(0)
EN
xor
xor
xor
xor
Y(3)
Y(2)
Y(1)
Y(0)
A[3:0]
inc
Y[3:0]
If EN = 1 th
then Y = A + 1
If EN = 0 then Y = A
EN
V 0.5
49
If EN = 1 then Y = A >> 1
If EN = 0 then Y = A
V 0.5
50
0 1 0 0 0 0 1 0
0x21 =
SI = 0
0 0 1 0 0 0 0 1
0x10 =
0 0 0 1 0 0 0 0
Et
Etc.
V 0.5
51
Right
g Shift vs. Left Shift
A right shift is MSB to LSB (divide by 2)
In:
SIN
D7 D6
D5
D4
D3
D2
D1
D0
Out:
SIN D7 D6 D5 D4 D3 D2 D1
7
6
5
4
3
2
1
0
A left shift is LSB to MSB (multiply by 2)
In:
D7 D6
D5
D4
D3
D2
D1
D0
SI
Out:
D6
7
D5
6
D4
5
D3
4
V 0.5
D2
3
D1
2
D0 SI
1
0
52
KxN
16 x 8
Address[log2(K)-1:0]
M
E
M
Data[N-1:0]
Address bus has log2(K) address lines, data bus has N data
lines.
V 0.5
53
G = AB + AC + BC
8 x 2 Memory
ABC
00 0
00 1
01 0
01 1
10 0
10 1
11 0
11 1
F
0
1
1
0
1
0
0
1
G
0
0
0
1
0
1
1
1
A
B
C
Y
0
1
1
0
Y = AB
= A xor B
V 0.5
A2
A1
D1
DO
F
G
A0
Pw
voltage
rising edge
- period
i d (i
(in seconds)
d )
time
Pw - pulse
l width
idth (i
(in seconds)
d )
falling edge
f = 1/
duty cycle = Pw /
Kilohertz ((KHz))
3
10
Megahertz (MHz)
6
10
Gigahertz (GHz)
9
10
V 0.5
55
D: data input
CK: clock input
S : sett input
i t (asynchronous,
(
h
low
l true)
t )
R: reset input (asynchronous, lowV 0.5
true)
56
Synchronous
y
vs Asynchronous
y
Inputs
p
Synchronous input: Output will change after active clock edge
A h
Asychronous
iinput: Output
O
changes
h
iindependent
d
d off clock
l k
St t elements
State
l
t often
ft have
h
async set,
t resett control.
t l
S
D
Q
C
R
V 0.5
57
Registers
The most common sequential building block is the register. A
register is N bits wide and has a load line for loading in a new
value into the register.
V 0.5
58
Counter
Veryy useful sequential
q
buildingg block. Used to generate
g
memoryy
addresses, or keep track of the number of times a datapath
operation is performed.
V 0.5
59
Shift Register
Very useful sequential building block.
block Used to perform either
parallel to serial data conversion or serial to parallel data
conversion.
V 0.5
60
Combinational logic
Memory
Register
Counter
V 0.5
61
V 0.5
62
63