Professional Documents
Culture Documents
Lab Session 3 Introduction To VHDL: Control Structures
Lab Session 3 Introduction To VHDL: Control Structures
Lab Session 3
Introduction to VHDL
Dr. I. Damaj
Control Structures and Arrays
Dr. I. Damaj
CPEG 340L Embedded Systems Design Laboratory
1
Control Structures
• Selection
• IF statements
• CASE statements
Dr. I. Damaj
• Looping
• FOR loops
1
08-Oct-16
IF-ELSE Statements
entity Equal is a b
port (
a, b: in integer;
c: out std_logic
);
end entity;
==
Dr. I. Damaj
architecture beh of Equal is
begin
process (a, b) c
begin
if (a = b) then
c <= '1';
else
c <= '0';
end if;
end process; 3
end architecture;
CASE Statements
entity Decoder is process(v)
port( begin
A,B,C: in std_logic; D <= (others => '0');
D: out std_logic_vector(7 downto 0) case (v) is
); when "000" => D(0) <= '1';
Dr. I. Damaj
2
08-Oct-16
Dr. I. Damaj
signal arr1: IntArr := (0,1,2,3,4,5,6,7,8,9);
begin
process(x)
begin
for i in 1 to arr1'Length loop
if (x = arr1(i)) then
index <= i;
exit;
end if;
index <= -1;
end loop; 5
end process;
end architecture;