Concept Flow - Function declaration and usage
Start
Declare Function
Call Function
Execute Function Body
Return Result
Use Result in Main Code
End
This flow shows how a function is declared, called, executed, and its result used in VHDL.
function add_two(x : integer) return integer is begin return x + 2; end function add_two; result := add_two(3);
| Step | Action | Input | Function Body Execution | Return Value | Result Usage |
|---|---|---|---|---|---|
| 1 | Declare function add_two | - | - | - | - |
| 2 | Call add_two with x=3 | 3 | Calculate 3 + 2 | 5 | - |
| 3 | Assign return value to result | - | - | 5 | result = 5 |
| 4 | Use result in main code | - | - | - | result used as 5 |
| 5 | End of execution | - | - | - | - |
| Variable | Start | After Function Call | Final |
|---|---|---|---|
| x | - | 3 | - |
| result | - | - | 5 |
VHDL functions are declared with inputs and a return type. They are called by passing arguments. The function body executes and returns a value. The returned value can be assigned to variables. Functions must be declared before use.
function multiply(x : integer; y : integer) return integer is begin return x * y; end function;
signal result : integer; result <= multiply(3, 4);
function increment(value : integer) return integer is begin value := value + 1; return value; end function;
Pass the test and this pattern moves unknown