FPGA Center


Return expression is used to assign the result of a procedure or function.

return expression;

A subprogram (function or procedure) can be stopped by using return expression in it. So the subprogram is terminated unconditionally. (EXAMPLE 1)

If the return expression is in some nested structures, the inner structure will be terminated.

The return expression in a procedure does not return any value. But funciton does. The type of the returned value is determined by the expression next to "return" in the function declaration. (EXAMPLE 2)



procedure  XT( signal X, T: in BIT; signal Q, NQ: inout BIT) is
       if (X = '1' and T = '1') then
               report "ALARM : X and T values are '1'";
               Q <= X and NQ after 5 ns;
              NQ <= T and Q after 5 ns;
       end if;
end procedure XT;

In this example if both of the X and T signals are '1', XT procedure will be terminated. It doesn't change whether there are some lines before "end if" statement.


P4: process
       type Real_tip is range 0.0 to 100.0;
       variable x, y : Real_type := 8.3;
       variable z: REAL;
        function Add (Op1, Op2: Real_tip) return REAL is
                 variable Result : REAL;
                Result := REAL(Op1)+REAL(Op2);
                return Result; -- this will return a value which is real.
         end function Add ;
    z:= Add(x,y);
end process;







Home | Fpga | VHDL | VHDL Dictionary | Digital Design | Simulation | PCB | Examples | Contact Us
Copyright © 2010 - 2013 FPGAcenter. All Rights Reserved.