else
1. Entity & Architecture Y <= '0';
end if;
library IEEE; -- Always include
end process;
use IEEE.std_logic_1164.all;
Priority Encoder
entity MODULE is process(y1, y2, y3)
begin
port ( if (y3='1') then dout <= "11"; -- Highest priority
elsif (y2='1') then dout <= "10";
A, B : in std_logic; -- Single-bit inputs
else dout <= "00"; -- Default
SEL : in std_logic_vector(1 downto 0); -- 2-bit bus end if;
end process;
Y : out std_logic
4. Bus Operations
);
signal BUS : std_logic_vector(3 downto 0); -- 4-
end MODULE; bit bus
BUS <= "1010"; -- Binary assignment
architecture BEHAVIOR of MODULE is BUS(3) <= '1'; -- Set MSB
OUT <= BUS(2 downto 1); -- Extract bits 2 and 1
-- Optional: signal temp : std_logic;
5. MUX
begin
-- Logic here -- 2-to-1 MUX
Y <= A when (SEL='0') else B;
end BEHAVIOR;
-- 4-to-1 Priority Encoder
2. Combinational Logic process(y1, y2, y3, y4)
begin
Direct Assignment
if (y4='1') then dout <= "11";
Y <= (A and B) or (not C); -- Boolean equation
elsif (y3='1') then dout <= "10";
Conditional (`when-else`) else dout <= "00";
Y <= '1' when (A='1' and B='0') else -- Priority end if;
check end process;
'0' when (C='1') else
'Z'; -- Default high-impedance -- 8-bit Adder
SUM <= A + B; -- Where A,B are 8-bit vectors
Selected Assignment (`with-select`) (
with SEL select 5. Anti-Latch Rules
Y <= I0 when "00", -- 4-to-1 MUX -- Method 1: Default first
I1 when "01", Y <= '0';
I2 when "10", if (A='1') then Y <= '1'; end if;
I3 when others; -- Mandatory!
-- Method 2: Explicit else
3. Process Blocks if (A='1') then
process(A, B, C) -- All inputs! Y <= '1';
begin else
Y <= '0'; -- Default (anti-latch) Y <= '0'; -- Must include!
if (A='1' and B='0') then end if;
Y <= '1';
elsif (C='1') then -- Note: "elsif" (no 'e')
Y <= 'Z';