8/9/2019 chap1_digreview
1/63
Combinational Logic ReviewDigital Devices was a LONG, LONG time ago in a galaxy FAR,
.
We don’t expect you to remember everything you learned in
g a ev ces, u you nee o remem er .
We will review some to help you remember. You also need to go
back and look at old notes. After a couple of days of review, we
,along.
Ask UESTIONS durin CLASS to SLOW thin s down.
V 0.5 1
8/9/2019 chap1_digreview
2/63
8/9/2019 chap1_digreview
3/63
Number Systems• To talk about binary data, we must first talk about
• The decimal number system (base 10) you should
– A digit in base 10 ranges from 0 to 9.
– A di it in base 2 ran es from 0 to 1 binar 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 in Base 16 can range from 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
re resent values 10 to 15. Base 16 is also called
V 0.5 3
Hexadecimal or just ‘Hex’.
8/9/2019 chap1_digreview
4/63
Positional Notation
Value of number is determined by multiplying each digit by a
weight and then summing. The weight of each digit is a
.
953.78 = 9 * 102 + 5 * 101 + 3 * 100 + 7 * 10-1 + 8 * 10-2
= 900 + 50 + 3 + .7 + .08 = 953.78
. = - -
= 8 + 0 + 2 + 1 + 0.5 + 0.25
= 11.75
0xA2F = 10*162 + 2*161 + 15*160
= * + * + *
V 0.5 4
= 2560 + 32 + 15 = 2607
8/9/2019 chap1_digreview
5/63
Base 10, Base 2, Base 16The textbook uses subscripts to represent different
bases (ie. A2F16, 953.7810, 1011.112)
.
The default base will be decimal, no special symbol for base 10.
The ‘0x’ will be used for base 16 (0xA2F)
The ‘0b’ will be used for base 2 (0b10101111)
If ALL numbers on a page are the same base (ie, all in base
16 or base 2 or whatever) then no symbols will be used and
a statement will be present that will state the base (ie, allnumbers on this page are in base 16).
V 0.5 5
8/9/2019 chap1_digreview
6/63
Common Powers
2-3 = 0.125
2-2 = 0.25-1
160 = 1 = 20
.
20 = 121 = 2
2 =
162 = 256 = 28
163 = 4096 = 212
23 = 8
24 = 16
25 =32
26 = 64
27 = 128
28 = 256210 = 1024 = 1 Ki (kilobinary)
220 = 1048576 = 1 Mi 1 me abinar = 1024 K = 210 * 210
29 = 512210 = 1024
211 = 2048
230 = 1073741824 = 1 Gi (1 gigabinary)
V 0.5 6
=
8/9/2019 chap1_digreview
7/63
Conversion of Any Base to Decimal
Converting from ANY base to decimal is done by multiplying
each digit by its weight and summing.
Binary to Decimal
0b1011.11 = 1*23 + 0*22 + 1*21 + 1*20 + 1*2-1 + 1*2-2
= 8 + 0 + 2 + 1 + 0.5 + 0.25= .
Hex to Decimal
0xA2F = 10*162 + 2*161 + 15*160
= 10 * 256 + 2 * 16 + 15 * 1
V 0.5 7
= 2560 + 32 + 15 = 2607
8/9/2019 chap1_digreview
8/63
Conversion of Decimal Integer
Divide Number N by base R until quotient is 0. Remainder at
EACH ste is a di it in base R from Least Si nificant di it to
Most significant digit.Convert 53 to binary
= = Least Si nificant Di it ,
26/2 = 13, rem = 0
13/2 = 6 , rem = 1 = , rem =
3/2 = 1, rem = 1
1/2 = 0, rem = 1 Most Significant Digit
53 = 0b 110101
= * 5 * 4 * 3 * 2 * 1 * 0
V 0.5 8
= 32 + 16 + 0 + 4 + 0 + 1 = 53
8/9/2019 chap1_digreview
9/63
Most Significant Digit
53 = 0b 110101
(has weight of 25 or
32). For base 2, also
eas gn can g
(has weight of 20 or 1).
For base 2, also called
ca e Most S gn cantBit (MSB). Always
LEFTMOST di it.
Least Significant Bit(LSB). Always
V 0.5 9
.
8/9/2019 chap1_digreview
10/63
Convert 53 to Hex
53/16 = 3, rem = 5 ,
53 = 0x35
* 1 * 0
= 48 + 5 = 53
V 0.5 10
8/9/2019 chap1_digreview
11/63
Hex (base 16) to Binary Conversion
Each Hex di it re resents 4 bits. To convert a Hex number to
Binary, simply convert each Hex digit to its four bit value.
Hex Di its to binar :0x0 = 0b 0000
0x1 = 0b 0001
ex g s o nary con :0x9 = 0b 1001
0xA = 0b 1010
0x3 = 0b 0011
0x4 = 0b 0100
0xB = 0b 1011
0xC = 0b 1100
0xD = 0b 1101
0x5 = 0b 01010x6 = 0b 0110
0x7 = 0b 0111
0xE = 0b 1110
0xF = 0b 1111
V 0.5 11
0x8 = 0b 1000
8/9/2019 chap1_digreview
12/63
,
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 nothave 4 bits, then pad with zeros for unsigned numbers.
0b 1010001 = 0b 0101 0001 = 0x51
V 0.5 12
8/9/2019 chap1_digreview
13/63
A Trick!
If faced with a large binary number that has to be
converted to decimal, I first convert the binary number
, .
0b 110111110011 = 0b 1101 1111 0011
=
= 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 featureon your calculator. Too bad calculators won’t be allowed on the
first test thou h…...
V 0.5 13
8/9/2019 chap1_digreview
14/63
Binary Numbers AgainRecall than N binary digits (N bits) can represent unsigned
N - .
4 bits = 0 to 15
8 bits = 0 to 255
16 bits = 0 to 65535
es es s mp y represen a on, we wou e o a so o
arithmetic operations on numbers in binary form.
Principle operations are addition and subtraction.
V 0.5 14
8/9/2019 chap1_digreview
15/63
Binary Arithmetic, Subtraction
The rules for binary arithmetic
are:The rules for binary subtraction
are:
0 + 0 = 0, carry = 01 + 0 = 1, carry = 0
0 - 0 = 0, borrow = 0
1 - 0 = 1 borrow = 0
0 + 1 = 1, carry = 0
= =
0 - 1 = 1, borrow = 1
, - = , orrow =
, .Binary subtraction, addition works just the same as
V 0.5 15
, .
8/9/2019 chap1_digreview
16/63
Binar Decimal additionDecimal
0b 101011
Binary
34+ 17
+ 0b 000001---------------
------
51
101100
From LSB to MSB:
=
7+4 = 1; with carry out of 1
to next column
,
1 (carry)+1+0 = 0, carry of 1
1 (carry)+0 + 0 = 1, no carry
1 (carry) + 3 + 1 = 5. =
0 + 0 = 0
1 + 0 = 1
V 0.5 16
.answer = % 101100
8/9/2019 chap1_digreview
17/63
Hex Addition
0x3ADecimal check.
+ 0x28--------
0x3A = 3 * 16 + 10
= 58
= *0x62
=
= 40
58 + 40 = 98
1 to next column0x62 = 6 * 16 + 2
1 (carry) + 3 + 2 = 6.answer = 0x62
V 0.5 17
8/9/2019 chap1_digreview
18/63
Hex addition again
Why is 0xA + 0x8 = 2 with a carry out of 1?
16). The digit that gets left is the excess (BASE - sum).
Ah + 8h = 10 + 8 = 18.
18 is GREATER than 16 (BASE), so need a carry out!Excess is 18 - BASE = 18 - 16 = 2, so ‘2’ is digit.
Exactly the same thing happens in Decimal.
5 + 7 = 2, carry of 1.5 + 7 = 12, this is greater than 10!.
- =
V 0.5 18
, .
8/9/2019 chap1_digreview
19/63
Subtraction
900
B nary
0b 100
- 001
------- - 0b 001-------
0-1 = 9; with borrow of 1 0-1 = 1; with borrow of 1rom nex co umn
0 -1 (borrow) - 0 = 9, with
borrow of 1
from next column
0 -1 (borrow) - 0 = 1, with
borrow of 1
9 - 1 (borrow) - 0 = 8.Answer = 899.
1 - 1 (borrow) - 0 = 0.Answer = % 011.
V 0.5 19
8/9/2019 chap1_digreview
20/63
Hex Subtraction
0x34Decimal check.
- 0x27----------
0x34 = 3 * 16 + 4
= 52
= *0x0D
- =
= 39
52 - 39 = 13
from next column0x0D = 13 !!
3 - 1 (borrow) - 2 = 0.answer = 0x0D.
V 0.5 20
8/9/2019 chap1_digreview
21/63
Hex subtraction a ain
Wh is 0x4 – 0x7 = 0xD with a borrow of 1?
The borrow has a weight equal to the BASE (in this case
.
BORROW +0x4 – 0x7 = 16 + 4 - 7 = 20 - 7 = 13 = 0xD.
0xD is the result of the subtraction with the borrow.
Exactl the same thin ha ens in decimal.
3 - 8 = 5 with borrow of 1 borrow + 3 - 8 = 10 + 3 - 8 = 13 - 8 = 5.
V 0.5 21
8/9/2019 chap1_digreview
22/63
Fixed PrecisionW t paper an penc , I can wr te a num er w t as many g ts asI want:
, , , , , , , , , , , , , , ,
A microprocessor or computing system usually uses FIXEDPRECISION for inte ers the limit the numbers to a fixed
number of bits:
0x AF4500239DEFA231 64 bit number, 16 hex digits0x 9DEFA231 32 bit number, 8 hex digits
0x A231 16 bit number, 4 hex digits
0x 31 8 bit number 2 hex di its
High end microprocessors use 64 or 32 bit precision; low end
V 0.5 22
.
8/9/2019 chap1_digreview
23/63
Unsigned OverflowIn this class I will use 8 bit precision most of the time, 16 bit
.
Overflow occurs when I add or subtract two numbers, and the
correc resu s a num er a s ou s e o e range o
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.
ts -- uns gne ntegers to - or to N bit – unsigned numbers 0 to 2 N-1
V 0.5 23
8/9/2019 chap1_digreview
24/63
Unsigned Overflow Example
Assume 8 t prec s on; e. I can’t store any more t an 8 ts oreach number.
= .
range of 0 to 255! What happens during the addition?
255 = 0x FF
+ 1 = 0x 01
-------------------
/= means Not Equal
256 /= 0x00
= ,
0xF + 1 (carry) + 0 = 0, carry out
Carry out of MSB falls off end, No place to put it!!!
V 0.5 24
na answer s ecause cou no s ore carry ou .
8/9/2019 chap1_digreview
25/63
Unsigned 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 correct result has overflowed the number range for that
precision, and thus the result is incorrect.
we cou e carry ou o e , en e 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
8/9/2019 chap1_digreview
26/63
Binary Codes (cont.)
N bits (or N binary Digits) can represent 2 N different values.
for exam le 4 bits can re resent 24 or 16 different values
N bits can take on unsigned decimal values from 0 to 2 N-1.
Codes usually given in tabular form.
000 black 001
010
red
pink
100
101
brown
blue
V 0.5 26111
green
white
8/9/2019 chap1_digreview
27/63
Codes for Characters
Also need to represent Characters as digital data.
The ASCII code (American Standard Code for
-
data. Typically 8 bits are actually used with the 8th bit being zero or used for error detection (parity checking).
8 bits = 1 Byte.
‘A’ = % 01000001 = 0x41‘&’ = % 00100110 = 0x26
7 .
enough to represent the Latin alphabet (A-Z, a-z, 0-9,
punctuation marks, some symbols like $), but what about
V 0.5 27
other symbols or other languages?
8/9/2019 chap1_digreview
28/63
ASCII American Standard
Code for InformationInterchange
V 0.5 28
8/9/2019 chap1_digreview
29/63
UNICODEUNICODE is a 16-bit code for representing alphanumeric data.
With 16 bits, can represent 216 or 65536 different symbols.
= -
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 Korean Hangul Symbols
0x3040-318F Hiranga, Katakana, Bopomofo, Hangul
0x4E00-9FFF Han C nese, Japanese, Korean
UNICODE used b Web browsers, Java, most software these
V 0.5 29
days.
8/9/2019 chap1_digreview
30/63
Number System Practice
What should you practice?• Hex to decimal decimal to hex conversion
• Hex to binary, binary to hex conversion
,
V 0.5 30
8/9/2019 chap1_digreview
31/63
8/9/2019 chap1_digreview
32/63
Majority Gate (and-or) form
V 0.5 32
Copyright 2005. Thomson/Delmar Learning, All rights
reserved.
8/9/2019 chap1_digreview
33/63
DeMorgan’s Law
Copyright 2005. Thomson/Delmar Learning, All rights
reserved.
V 0.5 33
8/9/2019 chap1_digreview
34/63
Majority Gate (nand-nand) form
V 0.5 34
Copyright 2005. Thomson/Delmar Learning, All rights
reserved.
8/9/2019 chap1_digreview
35/63
Representing ‘1’ and ‘0’
• In the electrical world, two ways of representing ‘0’ and ‘1’
– Presence or absence of electrical current – Different Voltage levels
• Different voltage levels are the most common
– Usually 0v for logic ‘0’, some non-zero voltage for logic ‘1’ (I.e.
>
• Can interface external sources to digital systems in many
ways
– Switches, buttons, other human controlled input devices – Transducers (change a physical quantity like temperature into a
digital quantity).
V 0.5 35
8/9/2019 chap1_digreview
36/63
Switch Inputs
Vdd Vdd
supply voltage,
typically 5V or
3.3V
L H
Gnd is 0 V
Switch closed asserted ,
V 0.5 36
(negated), output is L output is H
8/9/2019 chap1_digreview
37/63
Examples of high, low signals
Vdd Vdd Low True switch
H L
Switch closed asserted ,
V 0.5 37
,
output is H output is L
8/9/2019 chap1_digreview
38/63
CMOS transistors (P, N)
S: source
G: gate
D: drain
transistoroperation of P, N
types is
to each other
V 0.5 38
Copyright 2005. Thomson/Delmar Learning, All rights
reserved.
8/9/2019 chap1_digreview
39/63
Inverter gate - takes 2 transistors
PMOS is open (off)PMOS is closed (on)
NMOS is Closed (on) NMOS is Open (off)
Copyright 2005. Thomson/Delmar Learning, All rights
reserved.
V 0.5 39
8/9/2019 chap1_digreview
40/63
Buffer - takes 4 transistors
Copyright 2005. Thomson/Delmar Learning, All rights
reserved.
V 0.5 40
, ,
VDD.
8/9/2019 chap1_digreview
41/63
NAND gate - takes 4 transistors
A B Y
L L H
L H H
H H L
A B Y
0 0 1 out
1 0 11 1 0
V 0.5 41
8/9/2019 chap1_digreview
42/63
Another logic gate - takes 4 transistors
A B Y
0 0
1 01 1
V 0.5 42
8/9/2019 chap1_digreview
43/63
How do we make an AND gate?T e on y way w t CMOS trans stors s to connect an nverterafter a NAND gate.
Copyright 2005. Thomson/Delmar Learning, All rights
reserved.
Takes 6 transistors! In CMOS technology, NAND gates are
V 0.5 43
faster, and consume less power.
8/9/2019 chap1_digreview
44/63
Tri-State Buffer ere s anot er way to r ve a ne or us rom mu t p e
sources. Use a TRISTATE buffer.
A
EN
A Y
EN
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’.
When EN = 0 then Y = ‘Z’ hi h im edance
V 0.5 44
8/9/2019 chap1_digreview
45/63
Using Tri-State Buffers (cont)
Only A or B is enabled at a time.
A
S
Y
B
Implements 2/1 Mux function
If S=0 then Y = A
= =
V 0.5 45
8/9/2019 chap1_digreview
46/63
Combinational Building Blocks, Mux
V 0.5 46Copyright 2005. Thomson/Delmar Learning, All rightsreserved.
8/9/2019 chap1_digreview
47/63
Binary Adder
F (A,B,C) = A xor B xor C G = AB + AC + BC
These equations look familiar. These define a Binary Full
Adder :
Sum = A xor B xor Cin
Cout = AB + Cin A + Cin B
S
CiCoCinCout = AB + Cin (A + B)
Sum
Full Adder (FA)
V 0.5 47
4 Bi Ri l C Add
8/9/2019 chap1_digreview
48/63
4 Bit Ripple Carry Adder
A(0) B(0)A(1) B(1)A(2) B(2)A(3) B(3)
A B
CiCo
A B
CiCo
A B
CiCo
A B
CiCo CinCout C(0)C(1)C(2)C(3)C(4)
S SS S
Sum(0)Sum(1)Sum(2)Sum(3)
A[3:0]
B[3:0]SUM[3:0]+
V 0.5 48
Incrementer
8/9/2019 chap1_digreview
49/63
Incrementer
A(0)
EN
xor xor xor xor
A[3:0] Y[3:0]inc = en = +
If EN = 0 then Y = A
V 0.5 49
8/9/2019 chap1_digreview
50/63
8/9/2019 chap1_digreview
51/63
Understandin the shift o eration
MSB LSB
=
SI = 0
x =
SI = 0
0x21 = 0 0 1 0 0 0 0 1 2nd right shift
SI = 0
0x10 = 0 0 0 1 0 0 0 0 3rd right shift
V 0.5 51
tc….
8/9/2019 chap1_digreview
52/63
Right Shift vs. Left Shift
A right shift is MSB to LSB (divide by 2)
SIN
Out: SIN D7 D6 D5 D4 D3 D2 D1
7 6 5 4 3 2 1 0
In: D7 D6 D5 D4 D3 D2 D1 D0
SIOut: D6 D5 D4 D3 D2 D1 D0 SI
V 0.5 52
8/9/2019 chap1_digreview
53/63
Recall Basic Memor Definition
K x N Example:
ME
Data[N-1:0]Address[log2(K)-1:0]
(16 locations requireslog2(16) = 4 address lines,
eac ocat on stores 8 ts.
Address bus: A[3:0]
K locations, N bits per location
Address bus has log2(K) address lines, data bus has N data
lines.
V 0.5 53
Memory: Implement Logic or Store Data
8/9/2019 chap1_digreview
54/63
Memory: Implement Logic or Store Data
F (A,B,C) = A xor B xor C G = AB + AC + BC
8 x 2 Memory
A B C F G
0 0 0 0 00 0 1 1 0 A1
A2A
BC DO
GD1F
0 1 1 0 1
1 0 0 1 0 LookUp Table (LUT)
1 1 0 0 1
1 1 1 1 1
: s a ress
bus, D[1:0] is 2 bit
output bus.
A B Y
0 0 0
0 1 1
Location 0 has “00”,Location 1 has “10”,
“ ”
V 0.5 54
1 0 1
1 1 0
= A xor B
,
etc….
Clock Signal Review
8/9/2019 chap1_digreview
55/63
g
voltage
Pw rising edge falling edge
time f = 1/τ
τ - per o n secon s w - pu se w t n secon s
f - frequency pulse width (in Hertz)
duty cycle - ratio of pulse width to period (in %) duty cycle = Pw /τ
millisecond ms Kilohertz KHz10
-310
3
microsecond (μs)10
-6Megahertz (MHz)
106
V 0.5 55
10
-9
109
Slide by Prof Mitch Thornton
Storage Element: The D Flip Flop
8/9/2019 chap1_digreview
56/63
Storage Element: The D Flip-Flop
D: data inputCK: clock input
V 0.5 56
: se npu async ronous, ow rue
R: reset input (asynchronous, low true)
8/9/2019 chap1_digreview
57/63
S nchronous vs As nchronous In uts
Synchronous input: Output will change after active clock edge
syc ronous nput: utput c anges n epen ent o c oc
D
Sa e e emen s o en ave async se , rese con ro .
D input is synchronous with respect to Clk
Q
C S, R are asynchronous. Q output affected by S, R
R n epen ent o C. Async nputs are om nant over
Clk.
V 0.5 57
Registers
8/9/2019 chap1_digreview
58/63
The most common sequential building block is the register. A
register is N bits wide and has a load line for loading in a newvalue into the register.
Note that DFF simply loads old value when LD = 0. DFF
V 0.5 58Copyright 2005. Thomson/Delmar Learning, All rightsreserved.
s oa e every c oc cyc e.
Counter
8/9/2019 chap1_digreview
59/63
Ver useful se uential buildin block. Used to enerate memor
addresses, or keep track of the number of times a datapathoperation is performed.
Copyright 2005. Thomson/Delmar Learning, All rights
V 0.5 59
reserve .
Shift Register
8/9/2019 chap1_digreview
60/63
. parallel to serial data conversion or serial to parallel data
conversion.
Copyright 2005. Thomson/Delmar Learning, All rights
V 0.5 60
reserve .
Computer = Sequential+ Combinational
8/9/2019 chap1_digreview
61/63
Computer Sequential+ Combinational
building blocks/logic
• The next chapter will discuss using combinational+ se uential buildin blocks to build a com uter
– Combinational logic
– Memory
– Register
– Counter
V 0.5 61
8/9/2019 chap1_digreview
62/63
What do you need to know? (cont)
8/9/2019 chap1_digreview
63/63
W a do you eed o ow? (co )
• ASCII, UNICODE are binary codes for character
data
• Basic two-input Logic Gate operation
• NMOS/PMOS Transistor O erations
• Inverter/NAND transistor configurations
• -• Mux, Memory, Adder operation
•
• DFF, Register, Counter, Shifter register operation
V 0.5 63