Вы находитесь на странице: 1из 9

Overview

Chapter 7 Part B
Digital Arithmetic and Arithmetic Circuits

Digital Arithmetic Signed Numbers Signed Numbers Arithmetic Hexadecimal Arithmetic Numeric and Alphanumeric Codes Binary Adders and Subtractors Carry Generation
2

BCD Codes

BCD Examples

BCD Code (Binary-Coded Decimal): A code used to represent each decimal digit of a number by a 4-Bit Binary Value. Valid Digits for 0 to 9 are 0000 to 1001.

Each digit is a 4-Bit Binary group: (84)10 = 1000 0100 (4987)10 = 0100 1001 1000 0111BCD

The binary codes 1010 to 1111 are invalid

Called an 8421 Code due to the decimal weight of each bit position.
3 4

Excess-3 Code

Excess-3 Examples

A BCD Code formed by adding 3 (0011) to its true 4-bit binary value. Excess-3 is a self-complementing code:

A negative code equivalent can be found by inverting the binary bits of the positive code

3 = 0011 + 0011 = 0110 = 6 in E3. 1 = 0001 + 0011 = 0100 = 4 in E3. If we complement 1 = 1011 in E3, this is the code for an 8.

Inverting the bits of the Excess-3 digit yields 9s Complement of the decimal equivalent.

9s Complement of 1 = (9 1) = 8 (SelfComplement)

Gray Code

Gray Code and Binary


A binary code that progresses so that only one bit changes between two successive codes.

Frank Gray was a physicist and researcher at Bell Labs who made numerous innovations in television, both mechanical and electronic, and is remembered for the Gray code.

Binary: b3b2b1b0 Gray: g3g2g1g0 Gray code bits can be defined as follows: g3 = b3 g2 = b3 b2 g1 = b2 b1 g0 = b1 b0
8

ASCII Code

Binary Adders

American Standard Code for Information Interchange. A seven-bit alphanumeric code used to represent text letters, numerals, punctuation, and special controls. An expanded 8-bit form is becoming more widespread.
9

Half Adder (HA): A circuit that will add two bits and produce a sum bit and a carry bit. Full Adder (FA): A circuit that will add a carry bit from another HA or FA and two operand bits to produce a sum bit and a carry bit.
10

Basic HA Addition

HA Circuit

Binary Two-Bit Addition Rules: 0 + 0 = 00 0 + 1 = 01 1 + 1 = 10

Basic Equations: S = A XOR B, C = A and B where S = Sum and C = Carry. Truth Table for HA Block:
A 0 0 1 1 B 0 1 0 1

0 1 1 1

COUT 0 0 0 1

= AB + AB = A B
COUT = AB

11

12

HA Circuit

Full Adder Basics


Adds a CIN input to the HA block. Equations are modified as follows:


COUT = ( A B ) CIN + A B

= ( A B ) CIN

A FA can be made from two HA blocks and an OR Gate.

13

14

Full Adder Basics

Full Adder Basics

15

16

Full Adder Basics

Parallel Adders

A circuit, consisting of n full adders, that will add n-bit binary numbers. The output consists of n sum bits and a carry bit. COUT of one full adder is connected to CIN of the next full adder.

17

18

Parallel Adders

Ripple Carry 1

In the n-Bit Parallel Adder (FA Stages) the Carryout is generated by the last stage (FAN). This is called a Ripple Carry Adder because the final carryout (Last Stage) is based on a ripple through each stage by CIN at the LSB Stage.
20

19

Ripple Carry 2

Ripple Carry - 3

Each Stage will have a propagation delay on the CIN to COUT of one AND Gate and one OR Gate. A 4-Bit Ripple Carry Adder will then have a propagation delay on the final COUT of 4 2 = 8 Gates. A 32-Bit adder such as in an MPU in a PC could have a delay of 64 Gates.
21 22

Look-Ahead Carry 1

Look Ahead Carry 2

Fast Carry or Look-Ahead Carry:

A combinational network that generates the final COUT directly from the operand bits (A1 to An, B1 to Bn). It is independent of the operations of each FA Stage (as the ripple carry is).

Fast Carry has a small propagation delay compared to the ripple carry. The fast carry delay is 3 Gates for a 4Bit Adder compared to 8 for the Ripple Carry.

23

24

Parallel Adder

Parallel Adder

Created in VHDL by using multiple instances of a full adder component in the top-level file of a VHDL design hierarchy.

25

26

VHDL Full Adder


ENTITY full_add IS PORT( a, b, c_in : IN STD_LOGIC; c_out, sum : OUT STD_LOGIC; END full_add; ARCHITECTURE adder OF full_add IS BEGIN c_out <= ((a xor b) and c_in) or (a and b); sum <= (a xor b) xor c_ini; END adder;

Parallel Adder VHDL

Requires a separate component file for a full adder, saved in a folder where the compiler can find it. A component declaration statement in the top-level file of the design hierarchy. A component instantiation statement for each instance of the full adder component.

27

28

Parallel Adder VHDL Code 1


ENTITY add4par IS PORT( c0 a,b c4 sum END add4par; : IN STD_LOGIC; : IN STD_LOGIC_VECTOR (4 downto 1); : OUT STD_LOGIC; : OUT STD_LOGIC_VECTOR (4 downto 1);

Parallel Adder VHDL Code 2


ARCHITECTURE adder OF add4par IS -- Component declaration. COMPONENT full_add PORT( a, b, c_in : IN STD_LOGIC; c_out, sum : OUT STD_LOGIC; END COMPONENT; -- Define a signal for the internal carry bits SIGNAL c : STD_LOGIC_VECTOR (3 downto 1);

29

30

Parallel Adder VHDL Code 3


BEGIN -- four component instantiation statements. adder1 : full_add PORT MAP (a => a(1), b => b(1), c_in => c0, c_out => c(1) -- connects to c_in of adder 2. sum => sum(1)); END adder;

VHDL Generate Statement 1


ENTITY add4gen IS PORT( c0 a,b c4 sum END add4gen; : IN STD_LOGIC; : IN STD_LOGIC_VECTOR (4 downto 1); : OUT STD_LOGIC; : OUT STD_LOGIC_VECTOR (4 downto 1));

31

32

VHDL Generate Statement 2


ARCHITECTURE adder OF add4gen IS -- Component declaration COMPONENT full_add PORT( a, b, c_in :IN STD_LOGIC; c_out, sum : OUT STD_LOGIC; END COMPONENT; - - Defining a signal for internal carry bits. SIGNAL c : STD_LOGIC_VECTOR (4 downto 0);
33

VHDL Generate Statement 3


BEGIN c(0) <= c0; -- Input port c0 mapped to internal signal (c0) adders: FOR i IN 1 to 4 GENERATE -- Implicit port mapping. adder : full_add PORT MAP (a(i), b(i), c(i-1), c(i), sum (i)); END GENERATE; c4 <= c(4); END adder; -- Output port c4 mapped to internal signal c(4)

34

Subtractor (2s Complement) 1

Subtractor (2s Complement) 2


The concept of Subtraction using 2s Complement addition allows a Parallel FA to be used. This could be used in a MPU ALU (Arithmetic Logic Unit) for Subtraction. The subtract operation involves adding the inverse of the subtrahend to the minuend and then adding a 1.
35

Difference = A B = A + B + 1

This operation can be done in a parallel n-Bit FA by inverting (B1 to Bn) and connecting CIN at the LSB Stage to +5 V. The circuit can be modified to allow either the ADD or SUBTRACT operation to be performed.
36

Subtractor (2s Complement) 2

Parallel Binary Adder/Subtractor

XOR gates are used as programmable inverters to pass binary numbers (e.g., B1B2B3B4) to the parallel adder in true or complemented form.
When ADD/SUB = 1, B is complement ed. When ADD/SUB = 0, B is in its true form.

37

38

Parallel Binary Adder/Subtractor

Parallel Binary Adder/Subtractor

39

40

VHDL Parallel Binary Adder/Subtractor 1


ENTITY addsub4g IS PORT( sub : IN BIT; a,b : IN BIT_VECTOR (4 downto 1); c4 : OUT BIT; sum : OUT BIT_VECTOR (4 downto 1)); END addsub4g;

VHDL Parallel Binary Adder/Subtractor 2

ARCHITECTURE adder OF addsub4g IS COMPONENT full_add PORT( a, b, c_in : IN BIT; c_out : OUT BIT); END COMPONENT; - - Define a signal for internal carry bits SIGNAL c : BIT_VECTOR (4 downto 0); SIGNAL b_comp : BIT_VECTOR (4 downto 1); BEGIN

41

42

VHDL Parallel Binary Adder/Subtractor 3


- - add/subtract select to carry input (sub = 1 for subtract) c(0) <= sub; adders: FOR i IN 1 to 4 GENERATE --invert b for subtract function (b(i) xor 1,) --do not invert b for add function (b(i) xor 0) b_comp(i) <= b(i) xor sub; adder: full_add PORT MAP (a(i), b_comp(i), c(I -1), c(i), sum (i)); END GENERATE; C4 <= C(4); END adder;
43

Overflow

If the sign bits of both operands are the same and the sign bit of the sum is different from the operand sign bits, an overflow has occurred. Overflow is not possible if the sign bits of the operands are different from each other.
44

Overflow Examples

Overflow 8-bit Parallel Adder

Adding two 8-bit negative numbers: 80H 1000 0000 + 80H + 1000 0000 100H 100000000 (Signbit overflow;V = 1) Adding two 8-bit positive numbers:
7FH 0111 1111 + 01H 0000 0001 80H 1000 0000

S A A 7 A 6 A5 A4 A3 A2 A1 SB B7 B 6 B5 B4 B3 B2 B1 S S 7 S 6 S5 S4 S3 S2 S1

(SA = Sign bit of A) (SB = Sign bit of B ) (S = Sign bit of sum)

(Sign bit overflow; V = 1)


45 46

Overflow Detector Truth Table


SA
0 0 0 0 1 1 1 1

Overflow Detector Truth Table

SB
0 0 1 1 0 0 1 1

S
0 1 0 1 0 1 0 1

V
0 1 0 0 0 0 1 0
47 48

V = S ASBS + SASB S

BCD Adder

BCD Adder

A Parallel Adder whose output sum is in groups of 4 bits, each representing a BCD (8421) Digit. Basic design is a 4-Bit Binary Parallel Adder to generate a 4-Bit Sum of A + B. Sum is input to the four-bit input of a Binary-to-BCD Code Converter.
49 50

Homework

ACLU 25

Chapter 7

13 17 18 22 28 42

a,b (BCD and Excess-3 Codes) (ASCII) (Half Adder) (Four-Bit Adder) (12-Bit Adder) (BCD Adder)

Add 01102 and 01012 as unsigned number and determine if there is overflow. Add 01102 and 01012 as signed number and determine if there is overflow. Sketch an 8-bit adder subractor assuming two 4-bit adders with carry-in and carry out are available as a component. Add other components if needed.
52

51

Вам также может понравиться