EEE 270 Advanced Topics in Logic Design: Read Before Class
EEE 270 Advanced Topics in Logic Design: Read Before Class
Design
Arithmetic Units
Adders/Subtractors
Multipliers
Adders/Subtractors - Integers
Half adder: X Y
X G
S
S=X + Y Y
C=X∙Y C
P
Full adder: Cin
S=X + Y + Cin
C S
C=XY + (X + Y)Cin
=G+P∙Cin X Y Cin
• XY: carry generate G
• X + Y: carry propagate P Half G Half C2
Adder Adder
P
S C
Ripple Carry Adder
A 4-bit ripple carry adder made from four 1-bit full adder
2 2 2
2
VHDL Description of a 4-bit CLA
entity CLA4 is
port (A, B: in bit_vector (3 downto 0); Ci: in bit;
S: out bt_vector (3 downto 0); Co, PG, GG: out bit);
end CLA4;
Subtraction (A-B)
• Unsigned:
A≥B => A-B
A<B => the difference A-B+2n is subtracted from 2n, a “–” sign
added before the result (2n-X is taking the 2’s complement of X)
Signed integer
• For binary numbers
s an-2 … a2a1a0
s=0 for positive numbers;
s=1 for negative numbers
• Signed-magnitude: the n-1 digits are a positive magnitude
• Signed 2’s complement
2’s Complement Adder/Subtractor
ENTITY addsubtract IS
PORT ( S : IN STD_LOGIC;
A, B : IN STD_LOGIC_VECTOR (3 DOWNTO 0);
Sout : OUT STD_LOGIC_VECTOR (3 DOWNTO 0);
Cout : OUT STD_LOGIC);
END adderlpm;
COMPONENT full_add
PORT( a, b, c_in : IN STD_LOGIC;
c_out : OUT STD_LOGIC);
END COMPONENT;
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 S;
adder: full_add PORT MAP (A(i),B_comp(i),C(I -1),C(i),Sout(i));
END GENERATE;
END structural;
VHDL code for adder/subtractor
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY addsubtract IS
PORT ( S : IN STD_LOGIC;
A, B : IN STD_LOGIC_VECTOR (3 DOWNTO 0);
Sout : OUT STD_LOGIC_VECTOR (3 DOWNTO 0);
Cout : OUT STD_LOGIC);
END adderlpm;
Adders/Subtractors
Multipliers
Multiplication
Example: 10 x 14
Shift 1 -- The bit shifted out of the product register is 0. No
add is performed.
Shift 2 -- The bit shifted out of the product register is 1. Add
the multiplicand to the first 4 bits of the product register.
Shift 3 -- Again add the multiplicand to the leftmost 4 bits of
the product register.
Shift 4 -- Shift then add.
Finally, shift right and end. The product is found in the 8-bit
product register (140)
10 x 14 = 140
Add-and-Shift Multiplier
Add-and-Shift Multiplier
State Graph
VHDL code for 4-bit
binary multiplier
Array Multiplier
Array Multiplier
VHDL code for 4-bit
array multiplier
VHDL code for 4-bit
array multiplier
Summary