Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

04.Combinational components

.pdf
Скачиваний:
16
Добавлен:
23.08.2013
Размер:
302.26 Кб
Скачать

Chapter 4 Combinational Components

Page 21 of 28

When E = 0, the output of the NAND gate is a 1 regardless of what the other input is, and so the top p-MOS transistor is turned off. Similarly, the output of the AND gate is a 0, and so the bottom n-MOS transistor is also turned off. Thus, when E = 0, both transistors are off and so the output y is in the Z state.

When E = 1, the outputs of both the NAND and AND gates are equal to d'. So if d = 0, the output of the two gates are 1 and so the bottom transistor is turned on while the top transistor is turned off. Thus y will have the value 0, which is equal to d. On the other hand, if d = 1, the top transistor is turned on while the bottom transistor is turned off, and y will have the value 1.

The behavioral VHDL code for an 8-bit wide tri-state buffer is shown in Figure 26.

 

 

 

 

 

 

 

 

 

E

d

 

A

B

E

 

Y

E

 

 

 

 

 

0

0

 

1

0

0

 

Z

d

 

 

 

 

y

0

1

 

1

0

 

 

 

 

 

 

 

1

 

d

 

 

 

 

 

 

1

0

 

1

1

(a)

 

 

 

(b)

1

1

 

0

0

 

 

 

 

 

(c)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

E

Vcc

 

d

A

y

 

 

B

(d)

Figure 25. Tri-state buffer: (a) truth table; (b) logic symbol; (c) circuit; (d) truth table for the control portion of the tri-state buffer circuit.

LIBRARY ieee;

USE IEEE.std_logic_1164.ALL;

ENTITY TriState_Buffer IS PORT ( E: IN std_logic;

d: IN std_logic_vector(7 DOWNTO 0); y: OUT std_logic_vector(7 DOWNTO 0));

END TriState_Buffer;

ARCHITECTURE Behavioral OF TriState_Buffer IS

BEGIN

PROCESS (E, d)

 

BEGIN

 

IF (E = '1') THEN

 

y <= d;

 

ELSE

 

y <= (OTHERS => 'Z');

-- to get 8 Z values

END IF;

 

END PROCESS;

 

END Behavioral;

 

Figure 26. VHDL code for an 8-bit wide tri-state buffer.

4.10 Comparators

Quite often we need to compare two values for their arithmetic relationship (equal, greater, less than, etc.). A comparator is a circuit that compares two binary words and indicates whether the relationship is true or not. To compare whether a value is equal or not equal to a constant value, a simple AND gate can be used. For example, to compare a 4-bit variable x with the constant 3, the circuit in Figure 27 (a) can be used. The AND gate outputs a 1 when the input is equal to the value 3.

The XOR and XNOR gates can be used for comparing for inequality and equality respectively between two values. The XOR gate outputs a 1 when its two input values are different. So we can use one XOR gate for comparing each bit pair of the two operands. A 4-bit inequality comparator is shown in Figure 27 (b). Four XOR gates are used,

Microprocessor Design – Principles and Practices with VHDL

Last updated 7/16/2003 12:27 PM

Chapter 4 Combinational Components

Page 22 of 28

with each one comparing the same bit from the two operands. The outputs of the XOR gates are ORed together so that if any bit pair is different then the two operands are different and the resulting output is a 1. Similarly, an equality comparator can be constructed using XNOR gates instead since the XNOR gate outputs a 1 when its two input values are the same.

To compare for the greater-than or less-than relationships, we can construct a truth table and build the circuit from it using the regular method. For example, to compare whether a 4-bit value X is less than five, we get the truth table, equation and circuit shown in Figure 27 (c).

 

 

x3

 

 

 

y3

 

 

 

x2

 

x3

 

y2

F

 

x1

 

x2

F

y1

 

x1

 

x0

 

x0

 

y0

 

 

(a)

 

(b)

x3

x2

x1

x0

X < 5

0

0

0

0

1

0

0

0

1

1

0

0

1

0

1

0

0

1

1

1

0

1

0

0

1

0

1

0

1

0

0

1

1

0

0

0

1

1

1

0

1

×

×

×

0

x3

x2

x1

x0

 

 

 

F

(X < 5) = x3'x2' + x3'x2x1'x0'

(c)

Figure 27. Simple 4-bit comparators for: (a) X = 3; (b) X Y; (c) X < 5.

Instead of constructing a comparator for a fixed number of bits for the input values, we often prefer to construct an iterative circuit by constructing a 1-bit slice comparator and then daisy chaining them together for as many bits as is needed. The 1-bit slice comparator will have, in addition to the two input operand bits xi and yi, a pi bit that keeps track of whether all the previous bit pairs compared so far are true or not for that particular relationship. The circuit outputs a 1 if pi = 1 and the relationship is true for the current bit pair xi and yi. Figure 28 (a) shows a 1-bit slice comparator for equality. If the current bit pair xi and yi are equal, the XNOR gate will output a 1. Hence, pi+1 = 1 if the current bit pair is equal and the previous bit pair pi = 1. To obtain a 4-bit iterative equality comparator, we connect four 1-bit equality comparators in series as shown in Figure 28 (b). The initial p0 bit is set to a 1. Thus, if all four bit-pairs are equal, then the last bit, p4 will be a 1, otherwise, p4 will be a 0.

Microprocessor Design – Principles and Practices with VHDL

Last updated 7/16/2003 12:27 PM

Chapter 4 Combinational Components

Page 23 of 28

 

xi yi

 

x3

y3

 

x2

y2

 

x1

y1

 

x0

y0

 

 

EQ

 

 

 

 

 

 

 

 

 

 

 

 

 

pi+1

pi

p4

EQ

 

p3

EQ

 

p2

EQ

 

p1

EQ

p0

'1'

 

 

 

 

 

 

 

 

 

(a)

(b)

Figure 28. Iterative comparators: (a) 1-bit slice for xi = yi; (b) 4-bit X = Y.

4.11 Shifter / Rotator

The shifter and the rotator are used for shifting bits in a binary word one position either to the left or to the right. The difference between the shifter and the rotator is in how the end bits are shifted in or out. The six different operations for the shifter / rotator are summarized in Figure 29.

For each bit position, a multiplexer is used to move a bit from either the left or right to the current bit position. The size of the multiplexer will determine the number of operations that can be implemented. For example, we can use a 4-to-1 mux to implement the four operations as specified by the table in Figure 30 (a). Two select lines, s1 and s0, are needed to select between the four different operations. For a 4-bit operand, we will need to use four 4-to-1 muxes as shown in Figure 30 (b). How the inputs to the muxes are connected will depend on the given operations.

Operation

Comment

Example

Shift left with 0

Shift bits to the left one position. The

10110100

leftmost bit is discarded and the rightmost

101101000

 

bit is filled with a 0.

Shift left with 1

Same as above except that the rightmost bit

10110100

is filled with a 1.

101101001

 

Shift right with 0

Shift bits to the right one position. The

10110100

rightmost bit is discarded and the leftmost

010110100

 

bit is filled with a 0.

Shift right with 1

Same as above except that the leftmost bit is

10110100

filled with a 1.

110110100

 

Rotate left

Shift bits to the left one position. The

10110100

leftmost bit is moved to the rightmost bit

01101001

 

position.

Rotate right

Shift bits to the right one position. The

10110100

rightmost bit is moved to the leftmost bit

01011010

 

position.

Figure 29. Shifter and rotator operations.

Microprocessor Design – Principles and Practices with VHDL

Last updated 7/16/2003 12:27 PM

Chapter 4

Combinational Components

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Page 24 of 28

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

S1

 

s0

 

 

Operation

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

 

0

 

 

 

Pass through

 

 

 

 

 

 

 

 

in

3

 

 

 

 

 

in

2

 

 

 

 

 

 

in

1

 

 

 

 

 

 

in

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

 

1

 

 

 

Shift left and fill with 0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

0

 

 

 

Shift right and fill with 0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

1

 

 

 

Rotate right

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(a)

 

 

 

 

 

 

 

 

 

 

'0'

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'0'

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3

 

2

 

1

0

 

3

 

2

1

0

 

3

 

2

1

0

3

 

2

1

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

s1

 

mux3

 

 

 

 

s1

 

mux2

 

 

 

 

s1

 

mux1

 

 

 

 

s1

 

mux1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

s

 

 

 

s0 y

 

 

 

 

 

 

s0

 

 

y

 

 

 

 

s0

 

 

y

 

 

 

 

s0

 

 

y

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

s

in3

in2

in1

in0

 

s01

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

4-bit shifter/rotator

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

s0out3

out2

out1

out0

 

 

 

 

 

 

out3

 

 

 

 

out2

 

 

 

 

out1

 

 

 

 

out0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(b)

(c)

Figure 30. A 4-bit shifter / rotator: (a) operation table; (b) circuit; (c) logic symbol.

In the example, when s1 = s0 = 0, we want to pass the bit straight through without shifting, i.e. we want the value for ini to pass to outi. Given s1 = s0 = 0, d0 of the mux is selected, hence, ini is connected to d0 of muxi which outputs

to outi. For s1 = 0 and s0 = 1, we want to shift left, i.e. we want the value for ini to pass to outi+1. With s1 = 0 and s0 = 1, d1 of the mux is selected, hence, ini is connected to d1 of muxi+1 which outputs to outi+1. For this selection, we also

want to shift in a 0 bit, so d1 of mux0 is connected directly to a 0.

The behavioral VHDL code for an 8-bit shifter / rotator having the functions as defined in Figure 30 (a) is shown in Figure 31.

LIBRARY ieee;

USE ieee.std_logic_1164.all;

USE ieee.std_logic_unsigned.all;

ENTITY shifter IS PORT (

 

SHSel: IN std_logic_vector(1 downto 0);

-- select for operations

input: IN std_logic_vector(7 downto 0);

-- input

output: OUT std_logic_vector(7 downto 0));

-- output

END shifter;

 

 

ARCHITECTURE Behavior OF shifter IS

 

BEGIN

 

 

process(SHSel, input)

 

begin

 

 

CASE SHSel IS

 

 

WHEN "00" =>

-- pass through

 

output <= input;

 

WHEN "01" =>

-- shift left with 0

 

output <= input(6 downto 0) & '0';

 

WHEN "10" =>

-- shift right with 0

 

output <= '0' & input(7 downto 1);

 

WHEN OTHERS =>

-- rotate right

 

output <= input(0) & input(7 downto 1);

 

END CASE;

 

 

END PROCESS;

 

 

END Behavior;

 

 

Figure 31. Behavioral VHDL code for an 8-bit shifter / rotator having the operations as defined in Figure 30(a).

Microprocessor Design – Principles and Practices with VHDL Last updated 7/16/2003 12:27 PM

Chapter 4 Combinational Components

Page 25 of 28

4.12 Multiplier

In grade school, we were taught to multiply two numbers using a shift-and-add algorithm. Regardless of whether the two operands are in decimal or binary, the same algorithm is used. In fact, multiplying with binary numbers is even easier because you are always multiplying with either a 0 or a 1. Figure 32 (a) shows the manual multiplication of two 4-bit unsigned binary numbers, the multiplicand M = m3m2m1m0 with the multiplier Q = q3q2q1q0 to produce the resulting product P = p7p6p5p4p3p2p1p0.

The algorithm, as shown in Figure 32 (b), looks at the bits for Q from right to left in order. For each bit qi, if it is a 1 then M, shifted to the correct position, is added to the product, otherwise, a 0 is added. When the algorithm terminates, the result is in P. Following this sequential algorithm to implement a multiplication circuit give rise to a sequential circuit that is slow because only one 8-bit adder is used four times over to generate the product In addition, a register is needed to store the intermediate and final product. We will look at this sequential circuit in a later chapter.

Fortunately, a faster combinational multiplication circuit can be obtained based on this same algorithm. For this combinational circuit, AND gates are used to multiply the individual bits to give the intermediate products and multiple adders are used to sum the partial products. Observe that ANDing two bits gives the same result as multiplying the two bits, and this ANDing of M with qi replaces the need to test whether qi is a 1 or not. Thus, each intermediate product is obtained by ANDing the multiplicand M with one bit of the multiplier qi. For example (see Figure 32 (a)), bit zero of the first intermediate product is obtained by ANDing m0 with q0, bit one is obtained by ANDing m1 with q0, and so on. So the four bits of the first intermediate product are m3q0, m2q0, m1q0, and m0q0.

The final product is obtained by adding all the intermediate products with each one shifted over to the correct position. For example, p0 is just m0q0, p1 is the sum of m1q0 and m0q1, p2 is the sum of m2q0, m1q1 and m0q2, and so on. Figure 32 (c) shows the connections of the full adders to the bits of the intermediate products to produce the final product. The four full adders in each row are connected as in the ripple-carry adder with each carry-out signal connected to the carry-in of the next full adder. The carry-out of the last full adder is connected to the operand input of the last full adder in the row below. The last carry-out from the last row of adders is the value for p7 of the final product. As in the ripple-carry adder, all the initial carry-in c0 are set to a 0.

Multiplicand (M)

1

1

0 1

 

 

 

 

 

 

m3

m2

m1

m0

Multiplier (Q)

 

× 1

0

1 1

 

 

 

 

 

× q3

 

q

2

q

1

q

0

 

1 1 0 1

 

 

 

 

 

m3q0

m2q0

m1q0 m0q0

Intermediate products

1 1

0

1

 

m3q2

m3q1

m2q1

m1q1

m0q1

 

 

 

0 0 0 0

 

 

m2q2

m1q2

m0q2

 

 

 

 

 

+ 1 1 0 1

 

 

+ m3q3

m

2q3

m

1q3

m

0q3

 

 

 

 

 

 

 

Product (P)

1 0 0 0 1

1

1 1

p7 p6

 

p5

 

p4

 

p3

 

p2

p1

p0

(a)

P = 0

FOR i = 0 TO 3 IF qi = 1 THEN

P = P + (M << i) // the operation M << i is to shift M to the left by i bit position

END IF END FOR

// result is in P

(b)

Microprocessor Design – Principles and Practices with VHDL

Last updated 7/16/2003 12:27 PM

Chapter 4 Combinational Components

 

 

 

 

 

 

 

 

Page 26 of 28

m

3 q

0

m

2 q

0

m

1 q

0

m

0 q

0

 

 

 

 

 

 

 

 

 

 

 

 

m

3 q

 

1

m

2 q

 

1

m

1 q

 

1

m

0 q

 

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

m3 q3

+

p7 p6

m3 q2

+

m2 q3

+

p5

+ +

m2 q2

+

m1 q3

+

p4

m1 q2

+

m0 q3

+

p3

(c)

+

+

0

m0 q2

 

 

+

0

 

0

p2

p1

p0

Figure 32. Multiplication: (a) manual method; (b) algorithm; (c) circuit.

4.13Summary Checklist

Full adder

Ripple-carry adder

Carry-lookahead adder

Two’s complement

Sign extension

Subtractor

ALU

Arithmetic extender

Logic extender

Carry extender

Decoder

Encoder

Multiplexer

Building larger muxes using smaller muxes

Tri-state buffer

Z value

Comparator

Multiplier

Microprocessor Design – Principles and Practices with VHDL

Last updated 7/16/2003 12:27 PM

Chapter 4 Combinational Components

Page 27 of 28

4.14 Exercises

5.1.Derive the carry-lookahead equation and circuit for c5.

5.2.Draw the circuit for a 4-bit ALU that realizes the following operation table:

S2

S1

S0

Operation

0

0

0

Pass A to output

0

0

1

Pass B to output via AE

0

1

0

A + B

0

1

1

A'

1

0

0

A XOR B

1

0

1

A NAND B

1

1

0

A – 1

1

1

1

A – B

5.3.Draw the circuit for an 8-to-1 multiplexer using only 4-to-1 multiplexers.

5.4.Use one 8-to-1 multiplexer to implement the function F(x,y,z) = Σ (0,3,4,6,7).

5.5.Use 2-to-1 multiplexers to implement the function F(x,y,z) = Σ (0,2,4,5).

5.6.Derive the truth table for a 3-to-8 decoder using negative logic.

5.7.Draw the circuit for an 8-to-3 priority encoder.

5.8.Draw the circuit for an 8-to-3 priority encoder using only 4-to-2 priority encoders.

5.9.Write the behavioral VHDL code for the 8-to-3 priority encoder.

5.10.Draw the circuit diagram for a 4-bit iterative comparator that tests for the greater-than-or-equal-to relationship.

5.11.Derive the truth table for comparing two 4-bit operands for the less-than-or-equal-to relationship. Derive the equation and circuit from this truth table.

5.12.Draw the circuit for a 4-bit shifter/rotator that realizes the following operation table:

S2

S1

S0

Operation

0

0

0

Pass through

0

0

1

Rotate left

0

1

0

Shift right and fill with 1

0

1

1

not used

1

0

0

Shift left and fill with 0

1

0

1

Pass through

1

1

0

Rotate right

1

1

1

Shift right and fill with 0

5.13. Draw the complete detail circuit diagram for the 4-bit multiplier based on the circuit shown in Figure 32 (c). 5.14.

Microprocessor Design – Principles and Practices with VHDL

Last updated 7/16/2003 12:27 PM

Chapter 4 Combinational Components

Index

A

Active-high, 2

Active-low, 2

Adder, 2, 8 carry-lookahead, 4 full, 2 ripple-carry, 3

AE. See Arithmetic logic unit. ALU. See Arithmetic logic unit.

Arithmetic extender. See Arithmetic logic unit. Arithmetic logic unit, 10

AE arithmetic extender, 10 CE carry extender, 10

LE logic extender, 10 Assert, 2

C

Carry extender. See Arithmetic logic unit. Carry-lookahead adder, 4

CE. See Arithmetic logic unit. Combinational components, 2 Comparator, 21

D

De-assert, 2

Decoder, 14

Demultiplexer, 14

E

Encoder, 15 priority, 16

F

FA. See Full adder.

Full adder, 2

I

Iterative circuit, 22

Page 28 of 28

L

LE. See Arithmetic logic unit.

Logic extender. See Arithmetic logic unit.

M

Multiplexer, 17

Multiplier, 25

Mux. See Multiplexer.

N

Negative logic, 2

Negative numbers, 6

P

Positive logic, 2

Priority encoder, 16

R

Ripple-carry adder, 3

Rotator, 23

S

Shifter, 23

Sign extension, 7

Subtractor, 2, 8

T

Tri-state buffer, 20

Two’s-complement, 6

V

VHDL code

3-to-8 decoder, 15

4-to-1 multiplexer, 19 adder/subtractor, 10

arithmetic logic unit (ALU), 13 full adder, 3

shifter/rotator, 24 tri-state buffer, 21

Microprocessor Design – Principles and Practices with VHDL

Last updated 7/16/2003 12:27 PM