What is the value of y after the process runs with sel = "10"?
architecture Behavioral of case_example is signal sel : std_logic_vector(1 downto 0) := "10"; signal y : integer := 0; begin process(sel) begin case sel is when "00" => y <= 1; when "01" => y <= 2; when "10" => y <= 3; when others => y <= 0; end case; end process; end Behavioral;
Check which when branch matches the value of sel.
The sel signal is "10", so the case branch when "10" executes, setting y to 3.
What will be the value of out_signal after the process executes if input_val = '1'?
architecture Behavioral of overlap_case is signal input_val : std_logic := '1'; signal out_signal : integer := 0; begin process(input_val) begin case input_val is when '0' => out_signal <= 10; when '1' => out_signal <= 20; when others => out_signal <= 30; end case; end process; end Behavioral;
Match the input_val with the correct when branch.
Since input_val is '1', the case branch when '1' sets out_signal to 20.
What error will this VHDL code produce when compiled?
architecture Behavioral of error_case is signal sel : std_logic_vector(1 downto 0); signal y : integer := 0; begin process(sel) begin case sel is when "00" => y <= 1; when "01" => y <= 2; when "10" => y <= 3; -- Missing when others branch end case; end process; end Behavioral;
Check if the case statement covers all possible values of sel.
In VHDL, a case statement must cover all possible values. Missing the when others branch causes a compilation error.
Given mode = "01" and state = "10", what is the value of result after the process runs?
architecture Behavioral of nested_case is signal mode : std_logic_vector(1 downto 0) := "01"; signal state : std_logic_vector(1 downto 0) := "10"; signal result : integer := 0; begin process(mode, state) begin case mode is when "00" => result <= 100; when "01" => case state is when "00" => result <= 200; when "10" => result <= 300; when others => result <= 400; end case; when others => result <= 500; end case; end process; end Behavioral;
Follow the outer case on mode and then the inner case on state.
Outer case matches mode = "01", then inner case matches state = "10", so result is set to 300.
Consider this process with signal assignments. What is the value of z after the process completes if input = "11"?
architecture Behavioral of timing_case is signal input : std_logic_vector(1 downto 0) := "11"; signal z : integer := 0; begin process(input) begin case input is when "00" => z <= 5; when "11" => z <= z + 1; when others => z <= 0; end case; end process; end Behavioral;
Remember that signal updates inside a process take effect after the process completes.
The signal z is read before the process starts, so z + 1 uses the old value 0, and the new value 1 is scheduled but not visible inside the process. After the process, z becomes 1.
