Complete the code to declare a pure function in VHDL.
function add(a : integer; b : integer) return integer is begin return a + b; end [1];
In VHDL, a pure function does not have side effects and always returns the same output for the same inputs.
Complete the code to declare an impure function in VHDL.
impure function get_random return integer is begin -- returns a random number return integer'image(integer(now)); -- dummy example end [1];
An impure function in VHDL can have side effects or depend on external state, like time or signals.
Fix the error in the function declaration to make it pure.
pure function multiply(a : integer; b : integer) return integer is begin return a * b; end [1];
The function does not have side effects, so it should be declared as pure.
Fill both blanks to complete a pure function that calculates the square of a number.
pure function square(x : integer) return integer is begin return x [1] x; end [2];
The multiplication operator * is used to calculate the square, and the function is declared pure because it has no side effects.
Fill all three blanks to complete an impure function that returns the current simulation time as an integer.
impure function get_time return integer is begin return [1].[2]([3]); end impure;
The function uses the current simulation time now and converts it to a string with integer'image. The argument is now again to get the current time value.
