5305
architecture sel_arch of mux_4 is begin with s select x <= a when "00"; b when "01"; c when "10"; d when "11"; d when others; end sel_arch;
--
at the beginning or end of the line
-- Entity entity gates is port ( vA, vB : in std_logic_vector(3 downto 0); A,B,C,D : in std_logic; W,U,X,Y,Z : out std_logic; vX, vY : out std_logic_vector(3 downto 0) ); end entity gates; -- Architecture architecture RTL of gates is begin W <= A and B; U <= A nor B; --AND, NOR X <= C xor D; Y <= C xnor D; --XOR, XNOR Z <= (A and B) or (C and D); --AND-OR vX <= vA and vB; -- Vector bitwise AND vY <= vA or vB; -- Vector bitwise OR end architecture RTL;
-- Entity entity gates is port ( A,B,C,D : in std_logic; Y : out std_logic ); end entity gates; -- Architecture architecture combo of gates is begin combo_process : process (A,B,C,D) begin if ((C='1') and (D='1')) then Y <= '0'; elsif ((A='1') or (B='1')) then Y <= '1'; else Y <= '0'; end if; end process combo_process; end architecture combo;
-- Entity entity DLatches is port ( d, gate, clr : in std_logic; q : out std_logic ); end entity DLatches; -- Architecture architecture LArch of DLatches is begin latch_proc_1 : process (gate, d) begin if (gate='1') then q <= d; -- No rising_edge() end if; -- No gate=0 value, so latch inferred end process latch_proc_1;
rising_edge(signal)
in an
if statement to get a rising edge of a value.
-- Entity entity Data_Reg is port ( clk, reset, load : in std_logic; d : in std_logic_vector(3 downto 0); q : out std_logic_vector(3 downto 0)); end entity Data_Reg; -- Architecture architecture Reg_Arch of Data_Reg is begin dreg_proc : process (clk, reset, load) begin if (reset='0') then q <= "0000"; elsif (rising_edge(clk)) then if (load='1') then q <= d; end if; end if; end process dreg_proc; end architecture Reg_Arch;
architecture Add16_Arch of Add16 is component Add4 port ( A,B : in std_logic_vector(3 downto 0); Cin : in std_logic; Cout : out std_logic); Sum : in std_logic_vector(3 downto 0) ); end component; Begin Add4_u1 : Add4 port_map ( A=> A(3 downto 0), B=>(3 downto 0), Z=> Cin(0), Sum(3 downto 0) ); ... Add4_u4 : Add4 port_map ( A=> A(15 downto 12), B=>(15 downto 12), Z=> Cin(3), Sum(15 downto 12) ); end architecture Add16_Arch;
architecture Loop_Arch of my_loop is begin while (I <= 8) loop if (B = '1') then Z(I) <= A(I); end if; I := I + 1; end loop; end architecture Loop_Arch;