Consider this VHDL code for a 4-bit register with synchronous reset. What will be the value of q after the rising edge of the clock if reset = '0' and d = "1010"?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity reg4 is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; d : in STD_LOGIC_VECTOR (3 downto 0); q : out STD_LOGIC_VECTOR (3 downto 0)); end reg4; architecture Behavioral of reg4 is signal reg_q : STD_LOGIC_VECTOR(3 downto 0) := "0000"; begin process(clk) begin if rising_edge(clk) then if reset = '1' then reg_q <= (others => '0'); else reg_q <= d; end if; end if; end process; q <= reg_q; end Behavioral;
Remember that the register updates q only on the rising edge of clk and reset is synchronous.
Since reset is '0', the register loads the input d on the rising edge of clk. Therefore, q becomes "1010".
Given this 8-bit register with asynchronous reset, what will be the value of q immediately after reset = '1' is asserted?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity reg8_async is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; d : in STD_LOGIC_VECTOR (7 downto 0); q : out STD_LOGIC_VECTOR (7 downto 0)); end reg8_async; architecture Behavioral of reg8_async is signal reg_q : STD_LOGIC_VECTOR(7 downto 0) := (others => '0'); begin process(clk, reset) begin if reset = '1' then reg_q <= (others => '0'); elsif rising_edge(clk) then reg_q <= d; end if; end process; q <= reg_q; end Behavioral;
Asynchronous reset sets the register output immediately when asserted.
Because reset is asynchronous and active high, when reset = '1', q is immediately set to all zeros regardless of the clock.
What is the error in this VHDL code for a 3-bit register with synchronous reset?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity reg3 is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; d : in STD_LOGIC_VECTOR (2 downto 0); q : out STD_LOGIC_VECTOR (2 downto 0)); end reg3; architecture Behavioral of reg3 is signal reg_q : STD_LOGIC_VECTOR(2 downto 0) := (others => '0'); begin process(clk) begin if rising_edge(clk) then if reset = '1' then reg_q <= (others => '0'); else reg_q <= d; end if; end if; end process; q <= reg_q; end Behavioral;
Think about synchronous reset behavior and where the reset condition should be checked.
For synchronous reset, the reset condition must be checked inside the if rising_edge(clk) block. Checking reset outside causes unintended asynchronous behavior.
Which of the following VHDL code snippets for a 2-bit register will cause a syntax error?
Check for missing semicolons in the code.
Option C is missing a semicolon after q <= d, causing a syntax error.
Given this VHDL entity for a register, how many bits does it store?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity reg_custom is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; d : in STD_LOGIC_VECTOR (15 downto 4); q : out STD_LOGIC_VECTOR (15 downto 4)); end reg_custom; architecture Behavioral of reg_custom is signal reg_q : STD_LOGIC_VECTOR(15 downto 4) := (others => '0'); begin process(clk) begin if rising_edge(clk) then if reset = '1' then reg_q <= (others => '0'); else reg_q <= d; end if; end if; end process; q <= reg_q; end Behavioral;
Count the bits from index 15 down to 4.
The vector ranges from 15 down to 4, which is 15 - 4 + 1 = 12 bits.
