Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Please help me debug my vhdl code of 4 bit ALU

Status
Not open for further replies.

RollingEEE

Full Member level 3
Joined
Mar 25, 2006
Messages
165
Helped
8
Reputation
16
Reaction score
7
Trophy points
1,298
Location
Bangladesh
Activity points
2,406
4 bit alu vhdl

This code is suppose to be vhdl for a 4 bit ALU

Code:
library ieee;
use ieee.std_logic_1164.all;
use work.all;

entity normalalu is
	port (A, B: in std_ulogic_vector(0 to 3);
		  O   : out std_ulogic_vector(0 to 4);
		  S	  : in std_ulogic_vector (0 to 1));
end normalalu;
		  
architecture behavior of normalalu is
begin
	reg:process(A, B, S)
	variable Q: std_ulogic_vector(0 to 4);
	begin
		if S = "00" then
			O(0 to 4)<= A(0 to 3) + B(0 to 3);
		elsif S = "01" then
			O(0 to 4)<= A(0 to 3) - B(0 to 3);
		elsif S = "10" then
			O(0 to 4)<= A(0 to 3) and B(0 to 3);
		else
			O(0 to 4)<= A(0 to 3) or B(0 to 3);
		end if;
	end process;
end behavior;

QuartusII gives error saying that
Error (10327): VHDL error at normalalu.vhd(17): can't determine definition of operator ""+"" -- found 0 possible definitions[/code]

Please help
 

vhdl code for 4 bit alu

I believe you have missed out "use IEEE.numeric_std.all;"

On another note, your code can be trimmed as follows:

library ieee;
use ieee.std_logic_1164.all;
use IEEE.numeric_std.all;
use work.all;

entity normalalu is
port (A, B: in std_ulogic_vector(0 to 3);
O : out std_ulogic_vector(0 to 4);
S : in std_ulogic_vector (0 to 1));
end normalalu;

architecture behavior of normalalu is
begin
reg:process(A, B, S)
begin
if S = "00" then
O <= A + B;
elsif S = "01" then
O <= A - B;
elsif S = "10" then
O<= A and B;
else
O <= A or B;
end if;
end process;
end behavior;

Your variable Q is not necessary.
 

vhdl code for alu

You're getting this error cause you haven't declared the IEEE math libraries where these functions (+,-,etc) are found. You have to use these libraries. I think the math libraries are obsolete..so use the Numeric_Std library. This will solve the error.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top