Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

How to use functions in packages on testbench code.

Hi all,

How to use functions in the packages to testbench to give inputs a and b code.

function to_max(a, b : integer) return integer is

variable output :integer;

begin

if (a > b)then

output := a;

return output ;

else

output := b;

return output;

end if;

Thanks in advance

Regards

Raghavendra

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    eg:

    package my_function is

    function to_max(a, b : integer) return integer is

    variable output :integer;

    begin

    if (a > b)then

    output := a;

    return output ;

    else

    output := b;

    return output;

    end if;

    end package my_functions

    library ieee

    library work

    use work.my_functions.all

    entity test_program is

    port (

    x,y : in integer;

    y : out integer

    );

    architecture beh of test_program is

    begin

    y =to_max(x,y) ;

    end architecture beh;

    not synthesizable code but this is just a guide. hope it helps
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Thanks..How can i use in testbench code.

    --- Quote End ---

    1. Start by reading the two replies that you got to your question when you first posted it.

    2. If you're still confused, then ask a question about where you are confused by those two replies

    3. Don't ask the same question twice, when it was answered the first time.

    KJ