Bird
Raised Fist0
VHDLprogramming~10 mins

Procedure declaration and usage in VHDL - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Procedure declaration and usage
Start
↓
Declare Procedure
↓
Call Procedure
↓
Execute Procedure Body
↓
Return to Caller
↓
Continue Main Process
↓
End
First, you declare a procedure with inputs. Then you call it in your code. The procedure runs its commands and returns control back.
Execution Sample
VHDL
process
procedure show_message(msg : in string) is
begin
  report msg;
end procedure;

begin
  show_message("Hello VHDL");
end process;
This code declares a procedure to print a message and then calls it to show 'Hello VHDL'.
Execution Table
StepActionProcedure Called?Parameter ValueOutput/Effect
1Start main processNo--
2Call show_message with "Hello VHDL"Yes"Hello VHDL"-
3Enter show_message procedureYes"Hello VHDL"-
4Execute report msgYes"Hello VHDL"Report: Hello VHDL
5End show_message procedureNo--
6Return to main processNo--
7End main processNo--
💡 Procedure call finished and main process ends.
Variable Tracker
VariableStartAfter CallAfter ProcedureFinal
msg-"Hello VHDL""Hello VHDL"-
Key Moments - 2 Insights
Why do we see 'Hello VHDL' only after the procedure is called?
Because the procedure body runs only when called (see execution_table step 4), so the report happens inside the procedure, not before.
Does the procedure run automatically when declared?
No, declaration just defines it. Execution happens only when called (see execution_table step 2).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the parameter value passed to the procedure at step 2?
A"Goodbye"
B"Hello VHDL"
C"Message"
DNo parameter
💡 Hint
Check the 'Parameter Value' column at step 2 in the execution_table.
At which step does the procedure actually print the message?
AStep 4
BStep 5
CStep 2
DStep 7
💡 Hint
Look at the 'Output/Effect' column in the execution_table for when the report happens.
If we remove the procedure call, what happens to the output?
AMessage still prints
BProcedure runs automatically
CNo output is produced
DCompilation error
💡 Hint
Recall from key moments that procedure runs only when called.
Concept Snapshot
Procedure declaration syntax:
procedure name(params) is
begin
  -- statements
end procedure;

Call with: name(arguments);

Procedures run only when called, can take inputs, and help reuse code.
Full Transcript
In VHDL, a procedure is a named block of code you declare once and call when needed. The flow starts with declaring the procedure, then calling it in your main process. When called, the procedure runs its statements, like printing a message, then returns control back. Variables passed as parameters hold values during the call. The procedure does not run automatically on declaration; it runs only when called. This helps organize code and reuse actions easily.

Practice

(1/5)
1. What is the main purpose of a procedure in VHDL?
easy
A. To group a set of instructions for reuse
B. To declare a new signal
C. To define a new entity
D. To assign values to constants

Solution

  1. Step 1: Understand what a procedure does

    A procedure groups instructions to perform a specific task that can be reused multiple times in the code.
  2. Step 2: Compare with other options

    Declaring signals, entities, or assigning constants are different VHDL tasks, not the main purpose of procedures.
  3. Final Answer:

    To group a set of instructions for reuse -> Option A
  4. Quick Check:

    Procedure = reusable instruction group [OK]
Hint: Procedures bundle instructions for reuse [OK]
Common Mistakes:
  • Confusing procedures with signal declarations
  • Thinking procedures define entities
  • Assuming procedures assign constants
2. Which of the following is the correct way to declare a procedure in VHDL?
easy
A. procedure my_proc() begin -- code end procedure;
B. procedure my_proc is begin -- code end procedure;
C. procedure my_proc is -- code end;
D. procedure my_proc is begin -- code end;

Solution

  1. Step 1: Recall VHDL procedure syntax

    A procedure declaration uses the syntax: procedure name is begin ... end procedure;.
  2. Step 2: Check each option

    procedure my_proc is begin -- code end procedure; matches the correct syntax with is, begin, and end procedure;. Options B, C, and D have syntax errors or missing keywords.
  3. Final Answer:

    procedure my_proc is begin -- code end procedure; -> Option B
  4. Quick Check:

    Procedure syntax = procedure my_proc is begin -- code end procedure; [OK]
Hint: Procedure ends with 'end procedure;' [OK]
Common Mistakes:
  • Omitting 'procedure' keyword at the end
  • Using parentheses after procedure name
  • Ending with just 'end;' instead of 'end procedure;'
3. What will be the output of the following VHDL procedure call?
procedure add_one(signal x : inout integer) is
begin
  x <= x + 1;
end procedure;

signal val : integer := 5;
begin
  add_one(val);
  -- What is val now?
end;
medium
A. 5
B. 7
C. 6
D. Error: procedure call syntax

Solution

  1. Step 1: Understand procedure behavior

    The procedure add_one takes a signal x as inout and increments it by 1.
  2. Step 2: Apply procedure to signal val

    Initially, val is 5. After calling add_one(val);, val becomes 5 + 1 = 6.
  3. Final Answer:

    6 -> Option C
  4. Quick Check:

    5 + 1 = 6 [OK]
Hint: Inout parameter changes value inside procedure [OK]
Common Mistakes:
  • Assuming input parameters cannot change
  • Confusing procedure call syntax
  • Forgetting procedure modifies signal
4. Identify the error in this procedure declaration:
procedure multiply_by_two(x : in integer; y : out integer) is
begin
  y := x * 2;
end;
medium
A. Procedure must end with 'end procedure;' not just 'end;'
B. Procedure body cannot assign values to 'out' parameters
C. Parameters cannot have modes like 'in' or 'out'
D. Missing 'procedure' keyword before 'multiply_by_two'

Solution

  1. Step 1: Check procedure ending syntax

    In VHDL, a procedure must end with end procedure; not just end;.
  2. Step 2: Verify other parts

    The procedure keyword is present, parameter modes are allowed, and assigning to 'out' parameters is valid.
  3. Final Answer:

    Procedure must end with 'end procedure;' not just 'end;' -> Option A
  4. Quick Check:

    Procedure ends with 'end procedure;' [OK]
Hint: Procedure must end with 'end procedure;' [OK]
Common Mistakes:
  • Ending procedure with just 'end;'
  • Thinking parameter modes are not allowed
  • Confusing procedure and function endings
5. You want to create a procedure that swaps two integer signals a and b. Which of the following is the correct procedure declaration and usage?
hard
A. procedure swap(signal x, y : in integer) is variable temp : integer; begin temp := x; x := y; y := temp; end procedure; -- Usage: swap(a, b);
B. procedure swap(signal x, y : out integer) is variable temp : integer; begin temp := x; x := y; y := temp; end procedure; -- Usage: swap(a, b);
C. procedure swap(x, y : integer) is variable temp : integer; begin temp := x; x := y; y := temp; end procedure; -- Usage: swap(a, b);
D. procedure swap(signal x, y : inout integer) is variable temp : integer; begin temp := x; x <= y; y <= temp; end procedure; -- Usage: swap(a, b);

Solution

  1. Step 1: Determine correct parameter modes for swapping

    To swap values, both parameters must be inout or signal with mode allowing read and write. 'inout' is correct.
  2. Step 2: Check procedure declaration and usage

    procedure swap(signal x, y : inout integer) is variable temp : integer; begin temp := x; x <= y; y <= temp; end procedure; -- Usage: swap(a, b); declares parameters as signal x, y : inout integer and uses a temporary variable to swap values correctly. Usage is correct.
  3. Final Answer:

    procedure swap(signal x, y : inout integer) is variable temp : integer; begin temp := x; x <= y; y <= temp; end procedure; -- Usage: swap(a, b); -> Option D
  4. Quick Check:

    Swap needs inout parameters [OK]
Hint: Use 'inout' mode to modify both parameters [OK]
Common Mistakes:
  • Using 'in' mode which is read-only
  • Using 'out' mode which cannot read input
  • Omitting 'signal' keyword for signals
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard