Lec05 - DS - 2018 - Print
Lec05 - DS - 2018 - Print
2018
Digital Systems
Arithmetic
BK
TP.HCM
dc
2018
e Introduction
• Digital circuits are frequently used for arithmetic
operations
• Fundamental arithmetic operations on binary
numbers and digital circuits which perform
arithmetic operations will be examined.
2
dc
2018
e Binary Addition
• Binary numbers are added like decimal
numbers.
• In decimal, when numbers sum more than 9 a
carry results.
• In binary when numbers sum more than 1 a
carry takes place.
• Addition is the basic arithmetic operation used
by digital devices to perform subtraction,
multiplication, and division.
3
dc
2018
e Binary Addition
• 0+0=0
• 1+0=1
• 1 + 1 = 0 + carry 1
• 1 + 1 + 1 = 1 + carry 1
• E.g.:
1010 (10) 001 (1)
+1100 (12) +101 (5)
10110 (22) +111 (7)
1101 (13)
4
dc
2018
• Unsigned number
7
dc
2018
8
dc
2018
27 0001 1011 b
- 17 0001 0001 b
+ 10 0000 1010 b
+ 27 0001 1011 b
+ - 17 1110 1111 b
+ 10 0000 1010 b
• Note that the range for 8-bit unsigned and signed numbers
are different.
• 8-bit unsigned: 0 …… +255
• 8-bit 2’s complement signed number: -128 …… +127
9
dc
Comparison Table
2018
• Note the
"wrap-around"
effect of the
binary
representation
– i.e. The top of the
table wraps
around to the
bottom of the
table
10
dc
Sign Extension
2018
11
dc
Sign Extension
2018
e
• Sometimes we need to extend a number into more bits
• Decimal
– converting 12 into a 4 digit number gives 0012
– we add 0's to the left-hand side
• Unsigned binary
– converting 0011 into an 8 bit number gives 00000011
– we add 0's to the left-hand side
• For signed numbers we duplicate the sign bit (MSB)
• Signed binary
– converting 0011 into 8 bits gives 00000011 (duplicate the 0 MSB)
– converting 1011 into 8 bits gives 11111011 (duplicate the 1 MSB)
– Called "Sign Extension"
12
dc
2018
13
dc
Signed Addition
2018
e
• The same hardware can be used for 2's
complement signed numbers as for unsigned
numbers
– this is the main advantage of 2's complement form
• Consider 4 bit numbers:
– the Adder circuitry will "think" the negative numbers are
16 greater than they are in fact
– but if we take only the 4 LSBs of the result (i.e. ignore
the carry out of the MSB) then the answer will be correct
providing it is with the range: -8 to +7.
• To add 2 n-bit signed numbers without possibility
of overflow we need to:
– sign extend to n+1 bits
– use an n+1 bit adder
14
dc
2018
15
dc
2018
16
dc
2018
17
dc
N
Multiplication and Division by 2
2018
18
dc
Multiplication of Binary Numbers
2018
19
dc
2018
e Binary Division
• This is similar to decimal long division.
• It is simpler because only 1 or 0 are possible.
• The subtraction part of the operation is done
using 2’s complement subtraction.
• If the signs of the dividend and divisor are the
same the answer will be positive.
• If the signs of the dividend and divisor are
different the answer will be negative.
20
dc
Summary of Signed and Unsigned Numbers
2018
e
Unsigned Signed
MSB has a positive value (e.g. +8 MSB has a negative value (e.g. -8
for for
a 4-bit system) a 4-bit system)
The carry-out from the MSB of an To avoid overflow in an adder,
adder can be used as an extra bit need to sign extend and use an
of the answer to avoid overflow adder with one more bit than the
numbers to be added
21
dc
2018
e BCD Addition
• When the sum of each decimal digit is less than
9, the operation is the same as normal binary
addition.
• When the sum of each decimal digit is greater
than 9, a binary 6 is added. This will always
cause a carry.
22
dc
2018
e Hexadecimal Arithmetic
• Hex addition:
– Add the hex digits in decimal.
– If the sum is 15 or less express it directly in hex digits.
– If the sum is greater than 15, subtract 16 and carry 1 to the
next position.
• Hex subtraction – use the same method as for binary
numbers.
• When the MSD in a hex number is 8 or greater, the
number is negative. When the MSD is 7 or less, the
number is positive.
FFF – 3A5 = C5A
C5A + 1 = C5B is 2’s complement of 3A5
23
dc
2018
e Arithmetic Circuits
• An arithmetic/logic unit
(ALU) accepts data
stored in memory and
executes arithmetic
and logic operations as
instructed by the
control unit.
24
dc
2018
e Arithmetic Circuits
• Typical sequence of operations:
– Control unit is instructed to add a specific number
from a memory location to a number stored in the
accumulator register.
– The number is transferred from memory to the B
register.
– Number in B register and accumulator register are
added in the logic circuit, with sum sent to
accumulator for storage.
– The new number remains in the accumulator for
further operations or can be transferred to memory
for storage.
25
dc
2018
e Binary Addition
• Recall the binary addition process
A1001
+ B0011
S1100
• LS Column has 2 inputs 2 outputs
– Inputs: A0 B0
– Outputs: S0 C1
• Other Columns have 3 inputs, 2 outputs
– Inputs: An Bn Cn
– Outputs: Sn Cn+1
– We use a "half adder" to implement the LS column
– We use a "full adder" to implement the other columns
– Each column feeds the next-most-significant column.
26
dc
2018
27
dc
2018
e Half Adder
• Truth Table
• Boolean Equations
• Implementation
28
dc
2018
e Full Adder
• Truth Table
• Boolean Equations
29
dc
2018
30
dc
2018
31
dc
2018
• Boolean Equations
32
dc
2018
e Adder Example
33
dc
2018
e Hierarchy
• Any Verilog design you do will be a module
• This includes testbenches!
34
dc
2018
e Hierarchy
• Build up a module from smaller pieces
– Primitives
– Other modules (which may contain other
modules)
• Design: typically top-down
• Verification: typically bottom-up
Full Adder Add_ful
Hierarchy l
Add_hal Add_hal
or
f f
e Add_half Module
Add_hal
f
xor and
36
dc
2018
e Add_full Module
Add_ful
l
Add_hal Add_hal
or
f f
37
dc
2018
38
dc
2018
input A, B, CI ;
output S, CO ;
endmodule
39
dc
2018
input A, B, CI;
output S, CO;
reg S, CO; // explained in later lecture – “holds” values
40
dc
2018
e Parallel Adder
• Uses 1 full adder per bit of the numbers
• The carry is propagated from one stage to the next
most significant stage
– takes some time to work because of the carry propagation delay
which is n times the propagation delay of one stage.
41
dc
2018
42
dc
2018
43
dc
2018
e Carry Propagation
• Parallel adder speed is limited by carry
propagation (also called carry ripple).
• Carry propagation results from having to wait
for the carry bits to “ripple” through the device.
• Additional bits will introduce more delay.
• Various techniques have been developed to
reduce the delay. The look-ahead carry
scheme is commonly used in high speed
devices.
44
dc
2018
45
dc
Integrated Circuit Parallel Adder
2018
e
• The most common parallel adder is a 4 bit device with 4
interconnected FAs and look-ahead Carry circuits.
• Parallel adders may be cascaded together as shown to
add larger numbers
46
dc Parallel adder used to add and subtract numbers
2018
e in 2’s-complement system.
47
dc 2’s Complement Addition using 1’s Complement
2018
e Operands
48
dc Parallel adder/subtractor using the
2018
e
2’s-complement system
ADD = 1, SUB = 0:
B register passes to adder
and Carry in = 0
ADD = 0, SUB = 1:
Complement of B register
passes to adder and Carry
in = 1
49
dc
2018
51