Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
21615 Discussions

multiply two numbers

Altera_Forum
Honored Contributor II
1,870 Views

Hello. 

 

I am a new to vhdl and as a part of my tranning i need to multiplay 2 numbers can u help me and tell my what i doing wrong? 

 

 

LIBRARY IEEE; 

USE IEEE.STD_LOGIC_1164.ALL; 

use ieee.numeric_std.all; 

 

ENTITY MUL IS PORT( 

a,b: IN unsigned (3 downto 0);  

 

y : OUT unsigned (7 downto 0));  

END MUL ; 

ARCHITECTURE Behavioral OF MUL IS 

 

BEGIN 

 

process (a,b)  

 

variable temp1:unsigned(7 downto 0);  

variable temp:unsigned(7 downto 0);  

 

BEGIN 

 

 

for j in 0 to 3 loop 

 

if (b(j)='0') then  

temp1:=(7 downto 0 =>'0'); 

 

else  

 

temp1:=( j=>a(0),j+1=>a(1), j+2=>a(2),j+3=>a(3),others=>'0') ; 

 

temp:=temp+temp1; 

 

 

end if ; 

 

end loop;  

 

y<=temp; 

 

 

end process; 

 

END Behavioral;
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
831 Views

whats wrong with  

 

y <= a*b; 

 

But if you need to build your own multuplier - you havent said what problems you are having with this code.
0 Kudos
Altera_Forum
Honored Contributor II
831 Views

Yes i need to built my own multiplier my problem with the code is that logically i think it is ok and also compile but when i enter signals i am getting that y(out) is in unknown state.. 

 

Thx.
0 Kudos
Altera_Forum
Honored Contributor II
831 Views

That means temp is unknown and probably temp1 aswell 

Get a good testbench going in modelsim. This is debugging that you need to do yourself.
0 Kudos
Altera_Forum
Honored Contributor II
831 Views

I am using a wrap program and active vhdl sim. so i dont need test banch can u see the code and maybe guide me why temp1 and temp getting an unknown state? 

Thx.
0 Kudos
Altera_Forum
Honored Contributor II
831 Views

because temp is never initialised. 

And 'U' is not unknown, it is uninitialised. 'X' is unknown
0 Kudos
Altera_Forum
Honored Contributor II
831 Views

Ok thx i will try to fix it thx.

0 Kudos
Altera_Forum
Honored Contributor II
831 Views

I tried today this was not the issue but still thx .

0 Kudos
Altera_Forum
Honored Contributor II
831 Views

 

--- Quote Start ---  

I tried today this was not the issue but still thx . 

--- Quote End ---  

 

Are you referring to your original code? With Quartus synthesis, the missing initialization of temp is exactly the issue.
0 Kudos
Reply