The return statement is used to complete the execution of the innermost enclosing function or procedure body.
The return statement ends the execution of a subprogram (procedure or function) in which it appears. It causes an unconditional jump to the end of a subprogram (example 1).
If a return statement appears inside nested subprograms it applies to the innermost subprogram (i.e. the jump is performed to the next end procedure or end function clause).
This statement can only be used in a procedure or function body. The return statement in a procedure may not return any value, while a return in a function must return a value (an expression) which is of the same type as specified in the function after the return keyword (example 2).
procedure RS ( signal S, R: in BIT; signal Q, NQ: inout BIT) is
if (S = '1' and R = '1') then
report "forbidden state: S and R are equal to '1'";
Q <= S and NQ after 5 ns;
NQ <= R and Q after 5 ns;
end procedure RS;
The return statement located in the if then clause causes the procedure to terminate when both S and R are equal to '1'. The procedure would terminate even if the end if would be followed by some other statements.
type REAL_NEW is range 0.0 to 1000.0;
variable a, b : REAL_NEW := 2.0;
variable c: REAL;
function Add (Oper_1, Oper_2: REAL_NEW) return REAL is
variable result : REAL;
result := REAL(Oper_1)+REAL(Oper_2);
end function Add;
The return statement in a function must return a value of the type specified in the function header after the return clause.
- Although the return statement is a sequential one, it is not allowed to use it in a process.