Forum Discussion

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

Division using STD_LOGIC_VECTOR

Hello everybody,

I'm trying to divide two STD_LOGIC_VECTOR variables, but the "/" operator isn't recognized to this type of variable.

When I try to multiply using "*" it works, but when I try to divide it doesn't work.

I already try to convert the STD_LOGIC_VETOR to a INTEGER and then divide, but the function CONV_INTEGER returns me a wrong answer.

Can somebody help me?

Thanks!

3 Replies

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

    for a start, you cannot do arithmatic on a std_logic_vector in standard VHDL (pre 2008) - you need non-standard libraries for that. And they do not include a division function. You need to use the numeric_std library for arithmatic, with is done on unsigned and signed data types.

    Your attempts at using integer will not work as there is no fraction in in the integer. eg. 3/2 = 1.

    You need to look into the lpm_divider megafunction. It has pipelining that a division function would not.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you for the answer, but I've tried to add the numeric_std library and the code doesn't compile.

    It's an academic work, in which I need to implement the operations using floating point in IEEE 754 pattern.

    It's hard and I think your help gonna be very useful.

    Thank you!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    if you Need operations with IEEE754 Floating Point you should use the ALTFP_xxx megafunctions as operations on integers or signed / unsigned vectors and Floating Point numbers are quite different...