Lecture 4
Lecture 4
circuits design
using VHDL
Dr. Fatma ElFouly
Multiplier
Multiplier
Y(0)
r1
“0000” 4
x r5
Y(1) 6
x
“00000” r2 5 r
Mult-4bits
x&’0’
Y(2) 8
r y
r3
“000000” 6
x&”00” r6
Y(3) 8
r4
“0000000” 7
x&”000”
Multiplier
1101 x
*
1010 y x
0000 r1 r
Mult-4bits
11010 r2
000000 r3 y
1101000 r4
10000010 r
ENTITY mul IS
port (x,y:in std_logic_vector (3 downto 0);
r:out std_logic_vector (7 downto 0));
END mul ;
ARCHITECTURE rtl OF mul IS
signal r1: unsigned (3 downto 0);
signal r2: unsigned (4 downto 0);
signal r3,r5: unsigned (5 downto 0);
signal r4: unsigned (6 downto 0);
signal r6,r0: unsigned (7 downto 0);
Multiplier BEGIN
r1 <= unsigned (x) when y(0)='1' else (others =>'0');
r2 <= unsigned (x&'0') when y(1)='1' else (others =>'0');
r3 <= unsigned (x&"00") when y(2)='1' else (others=>'0');
r4 <= unsigned (x&"000") when y(3)='1' else
(others=>'0');
r5 <= r1+ ('0'& r2);
r6 <= r3+ ('0'& r4);
r0 <= r5+ r6;
r <= std_logic_vector (r0);
END rtl;
Comparator
Comparator
A comparator compares two or more inputs using one, or a number of different comparisons. When the given
relationship(s) is true, an output signal is given (logic 0 or logic1). Comparators are only modeled using
the if statement with an else clause and no else-if clauses. Any two data objects are compared using equality
and relational operators in the expression part of the if statement. Only two data objects can be compared at
once, that is, statements like “if (a = b = c)” cannot be used. However, logical operators can be used to
logically test the result of multiple comparisons, for example, “if ((a = b) and (a = c))”. These equality,
relational and logical operators are listed in the following Table.
Operators VHDL
=
/=
Equality & <
Relational <=
>
>=
not
Logical and
or
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity simple_comparator is
port (a, b: in std_logic_vector(5 downto 0);
y: out std_logic);
end entity simple_comparator;
architecture rtl of simple_comparator is
begin
process (a, b)
Comparator begin
if (a = b) then
y <= „1‟;
x
else
y <= „0‟; Comp z
end if;
end process; y
end architecture rtl;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;