Forum Discussion
Altera_Forum
Honored Contributor
14 years agoVHDL Code-Multiplication
I am new to this site. I have to work on a project which needs vhdl coding and I am new to it too.
i just need to multiply two elements . so i do that by entering a*b. but i get this error " found 0 defntiions of operator "*" " .i have included these libraries use IEEE.STD_LOGIC_1164.all; use ieee.numeric_std.all; use ieee.std_logic_arith.all; i have tried giving it this way.. result <= std_logic_vector(a*b) seeing one of the forums. then I get the following error. near std_logic_vector " type conversion expression type cannot be determined uniquely" a and b can be complex numbers Please help me. How could just multiplication of two elements have so many complications in VHDL ? :(6 Replies
- Altera_Forum
Honored Contributor
You need to use the signed/unsigned types that are in the numeric_std package.
And don't use std_logic_arith. resut <= std_logic_vector(unsigned(a) * unsigned(b)); - Altera_Forum
Honored Contributor
thanks for your reply. Is std_arth not for arithmetic operations??
and i got the previous problem solved.can you help me in few more doubts? 1.Will signed and unsigned include complex numbers?? 2.how to define a data type of matrix in vhdl and how to access the elements? My knowledge on vhdl is limited. Please do help :) - Altera_Forum
Honored Contributor
std_logic_arith is a non-standard VHDL package, and it conflicts with numeric_std, so do not use it.
1. signed an unsigned are just integers - but you can use them to represent fixed point. for complex numbers just store separate parts, or create a new record type that contains both. Thats what the type system is there for. 2. to create an array: type my_array_t is array(0 to n) of integer; --of course you can use any type in the array - Altera_Forum
Honored Contributor
Thank you very much people for your timely response. Will come to you if i get struck somewhere again.
- Altera_Forum
Honored Contributor
I have defined an array as
type array_name :array(natural range <>) of real; variable arr : array_name(0 to 10000); Supposing that i have given all values to the arr, How do i access only first 50 elements of it. will arr(0 to 50) work?? - Altera_Forum
Honored Contributor
--- Quote Start --- will arr(0 to 50) work?? --- Quote End --- Yes. However, this is not a question you really need to ask on the forum. You can answer these sorts of syntax questions by 'asking' the compiler, i.e., compile the code with either Quartus or Modelsim. Just in case you didn't think of that ... Cheers, Dave