Combinational Logic Review: Far, Far, Away
Combinational Logic Review: Far, Far, Away
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, all
numbers on this page are in base 16).
V 0.4 5
Common Powers
2-3 = 0.125
2-2 = 0.25 160 = 1 = 20
2-1 = 0.5 161 = 16 = 24
20 = 1 162 = 256 = 28
21 = 2
22 = 4
163 = 4096 = 212
23 = 8
24 = 16
25 =32
26 = 64
27 = 128 210 = 1024 = 1 K
28 = 256 220 = 1048576 = 1 M (1 Mega) = 1024 K = 210 * 210
29 = 512 230 = 1073741824 = 1 G (1 Giga)
210 = 1024
211 = 2048
212 = 4096
V 0.4 6
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
Hex to Decimal
53 = 0b 110101
= 1*25 + 1*24 + 0*23 + 1*22 + 0*21 + 1*20
= 32 + 16 + 0 + 4 + 0 + 1 = 53
V 0.4 8
Least Significant Digit
Most Significant Digit
53 = 0b 110101
53/16 = 3, rem = 5
3 /16 = 0 , rem = 3
53 = 0x35
= 3 * 161 + 5 * 160
= 48 + 5 = 53
V 0.4 10
Hex (base 16) to Binary Conversion
Of course, you can also use the binary, hex conversion feature
on your calculator. Too bad calculators won’t be allowed on
the first test, though…...
V 0.4 13
Binary Numbers Again
Recall than N binary digits (N bits) can represent unsigned
integers from 0 to 2N-1.
4 bits = 0 to 15
8 bits = 0 to 255
16 bits = 0 to 65535
Besides simply representation, we would like to also do
arithmetic operations on numbers in binary form.
Principle operations are addition and subtraction.
V 0.4 14
Binary Arithmetic, Subtraction
The rules for binary arithmetic The rules for binary subtraction
are: are:
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, carry = 1 1 - 1 = 0, borrow = 0
V 0.4 17
Hex Addition
Decimal check.
0x3A
0x3A = 3 * 16 + 10
+ 0x28 = 58
-------- 0x28 = 2 * 16 + 8
0x62 = 40
58 + 40 = 98
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.4 18
Hex addition again
Why is 0xA + 0x8 = 2 with a carry out of 1?
The carry out has a weight equal to the BASE (in this case
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!.
So excess is 12 - 10 = 2, carry of 1.
V 0.4 19
Hex Subtraction
Decimal check.
0x34
0x34 = 3 * 16 + 4
- 0x27 = 52
-------- 0x27 = 2 * 16 + 7
0x0D = 39
52 - 39 = 13
4-7 = D; with borrow of 1
from next column
0x0D = 13 !!
3 - 1 (borrow) - 2 = 0.
answer = 0x0D.
V 0.4 20
Hex subtraction again
The borrow has a weight equal to the BASE (in this case
16).
V 0.4 21
Fixed Precision
With paper and pencil, I can write a number with as many digits as
I want:
1,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; they limit the numbers to a fixed
number of bits:
0x AF4500239DEFA231 64 bit number, 16 hex digits
0x 9DEFA231 32 bit number, 8 hex digits
0x A231 16 bit number, 4 hex digits
0x 31 8 bit number, 2 hex digits
V 0.4 23
Unsigned Overflow Example
Assume 8 bit precision; ie. I can’t store any more than 8 bits for
each number.
Lets add 255 + 1 = 256. The number 256 is OUTSIDE the
range of 0 to 255! What happens during the addition?
255 = 0x FF
/= means Not Equal
+ 1 = 0x 01
-------------------
256 /= 0x00
V 0.4 25
Binary Codes (cont.)
N bits (or N binary Digits) can represent 2N different values.
(for example, 4 bits can represent 24 or 16 different values)
000 black
001 red
010 pink
011 yellow
100 brown
101 blue
110 green
111 white V 0.4 26
Codes for Characters
Also need to represent Characters as digital data.
The ASCII code (American Standard Code for
Information Interchange) is a 7-bit code for Character
data. Typically 8 bits are actually used with the 8th bit
being zero or used for error detection (parity checking).
8 bits = 1 Byte.
V 0.4 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-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 Korean Hangul Symbols
0x3040-318F Hiranga, Katakana, Bopomofo, Hangul
0x4E00-9FFF Han (Chinese, Japanese, Korean)
V 0.4 31
DeMorgan’s Law
V 0.4 32
Majority Gate (nand-nand) form
V 0.4 33
Representing ‘1’ and ‘0’
V 0.4 34
Switch Inputs
High True switch Vdd is power
Vdd Vdd supply voltage,
typically 5V or
3.3V
L H
Gnd is 0 V
Gnd Gnd
H L
Gnd Gnd
S: source
G: gate
D: drain
transistor
operation of P, N
types is
complementary
to each other
V 0.4 38
Buffer - takes 4 Transistors
AB Y
L L H
L H H
H L H
H H L
AB Y
0 0 1
0 1 1
1 0 1
1 1 0
V 0.4 40
How do we make an AND gate?
The only way with CMOS transistors is to connect an inverter
after a NAND gate.
EN EN
A Y
A Y
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’ (high impedance)
V 0.4 42
Using TriState Buffers (cont)
Only A or B is enabled at a time.
S
A
If S=0 then Y = A
If S=1 then Y = B
V 0.4 43
Combinational Building Blocks, Mux
V 0.4 44
Copyright 2005. Thomson/Delmar Learning, All rights
reserved.
Binary Adder
F (A,B,C) = A xor B xor C G = AB + AC + BC
A B
Cout = AB + Cin A + Cin B
Cout Cin = AB + Cin (A + B)
Co Ci
S
V 0.4 45
4 Bit Ripple Carry Adder
A(3) B(3) A(2) B(2) A(1) B(1) A(0) B(0)
Cout C(4) A B
C(3)
A B
C(2)
A B
C(1)
A B
C(0)
Co Ci Co Ci Co Ci Co Ci Cin
S S S S
A[3:0]
SUM[3:0]
B[3:0]
+
V 0.4 46
Incrementer
A(3) A(2) A(1) A(0)
EN
If EN = 1 then Y = A + 1
A[3:0] inc Y[3:0]
If EN = 0 then Y = A
EN
V 0.4 47
Combinational Right Shifter
A combinational block that can either shift right or pass data
unchanged
V 0.4 48
Understanding the shift operation
MSB LSB
0x85 = 1 0 0 0 0 1 0 1
SI = 0
Etc….
V 0.4 49
Right Shift vs Left Shift
A right shift is MSB to LSB
In: D7 D6 D5 D4 D3 D2 D1 D0
SIN
Out: SIN D7 D6 D5 D4 D3 D2 D1
In: D7 D6 D5 D4 D3 D2 D1 D0
SI
Out: D6 D5 D4 D3 D2 D1 D0 SI
V 0.4 50
Recall Basic Memory Definition
KxN
Address[log2(K)-1:0] Data[N-1:0]
M
E
M
V 0.4 51
Memory: Implement Logic or Store Data
F (A,B,C) = A xor B xor C G = AB + AC + BC
8 x 2 Memory
ABC F G A A2 F
00 0 0 0 D1
B A1 G
00 1 1 0 DO
C
01 0 1 0 A0
01 1 0 1
10 0 1 0 LookUp Table (LUT)
10 1 0 1 A[2:0] is 3 bit address
11 0 0 1
11 1 1 1 bus, D[1:0] is 2 bit
output bus.
Recall that Exclusive OR (xor) is
Location 0 has “00”,
AB Y
0 0 0 Location 1 has “10”,
0 1 1
Y = A⊕B Location 2 has “10”,
1 0 1
1 1 0 = A xor B etc….
V 0.4 52
Clock Signal Review
Pw
rising edge falling edge
voltage
τ - period (in seconds) Pw - pulse width (in seconds)
time
f - frequency pulse width (in Hertz) f = 1/τ
D: data input
CK: clock input
S : set input (asynchronous, low true)
R: reset input (asynchronous, lowV 0.4
true) 54
Synchronous vs Asynchronous Inputs
Synchronous input: Output will change after active clock edge
Asychronous input: Output changes independent of clock
V 0.4 55
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.4 57
Shift Register
Very useful sequential building block. Used to perform either
parallel to serial data conversion or serial to parallel data
conversion.
V 0.4 58
What do you need to Know?
• Convert hex, binary integers to Decimal
• Convert decimal integers to hex, binary
• Convert hex to binary, binary to Hex
• N binary digits can represent 2N values, unsigned
integers 0 to 2N-1.
• Addition, subtraction of binary, hex numbers
• Detecting unsigned overflow
V 0.4 59
What do you need to know? (cont)
• ASCII, UNICODE are binary codes for character
data
• Basic two-input Logic Gate operation
• NMOS/PMOS Transistor Operations
• Inverter/NAND transistor configurations
• Tri-state buffer operation
• Mux, Memory, Adder operation
• Clock signal definition
• DFF, Register, Counter, Shifter register operation
V 0.4 60