Consider the following VHDL function and its usage in a process. What value will be assigned to result after the process runs?
function multiply_by_two(x : integer) return integer is begin return x * 2; end function; signal result : integer := 0; begin process begin result <= multiply_by_two(5); wait; end process;
Remember the function returns the input multiplied by 2.
The function multiply_by_two returns the input integer multiplied by 2. Calling it with 5 returns 10, so result is assigned 10.
Given the following recursive VHDL function, what is the value returned by factorial(4)?
function factorial(n : integer) return integer is begin if n = 0 then return 1; else return n * factorial(n - 1); end if; end function;
Factorial of 4 is 4 * 3 * 2 * 1.
The factorial function multiplies all positive integers down to 1. factorial(4) = 4*3*2*1 = 24.
Identify which function declaration is invalid and will cause a syntax error in VHDL.
Check the parameter declarations carefully.
Option A misses the colon ':' between parameter names and types, causing a syntax error.
out_val after this process?Given the function and process below, what value will out_val hold after the process executes?
function increment(x : integer) return integer is begin return x + 1; end function; signal out_val : integer := 0; begin process variable temp : integer := 5; begin out_val <= increment(temp); wait; end process;
The function adds 1 to the input variable.
The variable temp is 5. The function increment returns 5 + 1 = 6, so out_val becomes 6.
Given these two overloaded functions, what is the result of compute(3.0)?
function compute(x : integer) return integer is begin return x * 2; end function; function compute(x : real) return real is begin return x / 2.0; end function; signal result_real : real := 0.0; begin process begin result_real <= compute(3.0); wait; end process;
Check which function matches the argument type 3.0.
The argument is a real number (3.0), so the compute function with a real parameter is called, returning 3.0 / 2.0 = 1.5.
