Forum Discussion
5 Replies
- Altera_Forum
Honored Contributor
Change the line near the end to:
Note the change to enforce that the argument to UNSIGNED() is a std_logic_vector. Cheers, DaveDATA<= unsigned(DATAi)-UNSIGNED(std_logic_vector'(X"80")) when SIGNED_DATA=0 else DATAi; - Altera_Forum
Honored Contributor
--- Quote Start --- Change the line near the end to:
Note the change to enforce that the argument to UNSIGNED() is a std_logic_vector. Cheers, Dave --- Quote End --- Hai Dave, Thanks, its can simulate know..I have another question, can you help me to verify it. I have line code of bp<=SXT(a,9) + b and bp<= a+b, wheres a and b is std_logic_vector(7 downto 0) and bp is std_logic_vector(8 downto 0). My question is what the different between the two line codes? thanks in advanceDATA<= unsigned(DATAi)-UNSIGNED(std_logic_vector'(X"80")) when SIGNED_DATA=0 else DATAi; - Altera_Forum
Honored Contributor
--- Quote Start --- I have another question, can you help me to verify it. I have line code of bp<=SXT(a,9) + b and bp<= a+b, wheres a and b is std_logic_vector(7 downto 0) and bp is std_logic_vector(8 downto 0). My question is what the different between the two line codes? thanks in advance --- Quote End --- Neither is correct. If a, b, and bp are all std_logic_vector, then you cannot add without converting to signed or unsigned. std_logic_vector is just an array of bits, the compiler does not know how you want to interpret those bits, so you have to tell it using explicit casts/type-conversions.
where a and b are converted to unsigned, the sum a+b is also unsigned (1-bit wider), and it is converted to std_logic_vector before being assigned to bp (which is also std_logic_vector). Cheers, Davebp <= std_logic_vector(unsigned(a) + unsigned(b)); - Altera_Forum
Honored Contributor
--- Quote Start --- Neither is correct. If a, b, and bp are all std_logic_vector, then you cannot add without converting to signed or unsigned. std_logic_vector is just an array of bits, the compiler does not know how you want to interpret those bits, so you have to tell it using explicit casts/type-conversions.
where a and b are converted to unsigned, the sum a+b is also unsigned (1-bit wider), and it is converted to std_logic_vector before being assigned to bp (which is also std_logic_vector). Cheers, Dave --- Quote End --- Hai Dave, Then, what the different between bp<=SXT(a,9)+b with bp<=a+b? Or is it there are same actually? Can you give simple example for both line codes? Need helps,thanks in advancebp <= std_logic_vector(unsigned(a) + unsigned(b)); - Altera_Forum
Honored Contributor
--- Quote Start --- what the different between bp<=SXT(a,9)+b with bp<=a+b? Or is it there are same actually? Can you give simple example for both line codes? Need helps,thanks in advance --- Quote End --- Both are invalid syntax. As commented in a previous thread in response to your question, SXT just extends the a signal by 1 bit. Rather than asking these questions, you should create a Modelsim simulation and try to figure it out yourself. You'll learn much better that way. Cheers, Dave