Consider the following VHDL code snippet. What value will be assigned to result after the procedure call?
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity test_proc is end entity; architecture behavior of test_proc is signal result : integer := 0; procedure add_five(signal val : inout integer) is begin val <= val + 5; end procedure; begin process begin result <= 10; wait for 10 ns; add_five(result); wait; end process; end architecture;
Remember that inout parameters allow the procedure to modify the argument.
The procedure add_five adds 5 to the input integer. Since result starts at 10, after the call it becomes 15.
Given the procedure below, what happens if you call it with a signal passed as in parameter but try to modify it inside?
procedure increment(val : in integer) is begin val := val + 1; end procedure;
Check the rules for modifying in parameters inside procedures.
Parameters declared as in are read-only inside procedures. Assigning to them causes a compilation error.
Examine the code below. The procedure is supposed to double the input signal value, but the signal remains unchanged after the call. Why?
procedure double_val(val : in integer) is begin val := val * 2; end procedure; signal my_val : integer := 3; begin double_val(my_val); -- my_val remains 3
Think about how 'in' parameters behave inside procedures.
Parameters declared as 'in' are passed by value (copy). Modifying them inside the procedure does not change the original signal.
Which option shows the correct syntax for declaring a procedure with an out parameter in VHDL?
Parameter mode comes after the parameter name, separated by a colon.
In VHDL, the correct syntax is param_name : mode type. So val : out integer is correct.
Given the following VHDL code, how many times is the procedure increment called and what is the final value of counter?
signal counter : integer := 0; procedure increment(signal val : inout integer) is begin val <= val + 1; end procedure; begin increment(counter); increment(counter); increment(counter); -- What is counter now?
Each call adds 1 to counter, which starts at 0.
The procedure is called three times, each time increasing counter by 1. So final value is 3.
