- Joined
- Jul 10, 2010
- Messages
- 4
- Reaction score
- 0
Hi,
i am implementing a very simple and small ALU. basically i was a programmer of verilog but unfortunately i have to do this job in VHDL now. the code is written below:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.NUMERIC_STD.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE WORK.TYPE_ALU.ALL;
ENTITY ALU IS
PORT (
FUNC : IN TYPE_OP;
IN1 : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
IN2 : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
ALU_OUT : OUT STD_LOGIC_VECTOR(31 DOWNTO 0));
END ALU;
ARCHITECTURE BEHAVIOR OF ALU IS
SIGNAL IN1_IN2 : STD_LOGIC_VECTOR(31 DOWNTO 0);
SIGNAL TEMP_OUT : STD_LOGIC_VECTOR(31 DOWNTO 0);
SIGNAL TEMP1 : STD_LOGIC_VECTOR(31 DOWNTO 0);
SIGNAL TEMP2 : STD_LOGIC_VECTOR(31 DOWNTO 0);
BEGIN
-- VARIABLE V1 : INTEGER;
-- VARIABLE V2 : INTEGER;
P_ALU: PROCESS (FUNC,IN1,IN2)
BEGIN
TEMP1 <= IN1;
TEMP2 <= IN2;
CASE FUNC IS
WHEN ADD|LDMEM|SDMEM|ADDI => TEMP_OUT <= TEMP1+TEMP2;
WHEN SUBA|SUBI => TEMP_OUT <= TEMP1-TEMP2;
WHEN LAND|LANDI => TEMP_OUT <= TEMP1 AND TEMP2;
WHEN LOR|LORI => TEMP_OUT <= TEMP1 OR TEMP2;
WHEN LXOR|LXORI => TEMP_OUT <= TEMP1 XOR TEMP2;
WHEN LNOR|LNORI => TEMP_OUT <= NOT(TEMP1 OR TEMP2);
WHEN SLT|SLTI => TEMP_OUT <= sxt((TEMP1 < TEMP2),32);
WHEN SLLR => TEMP_OUT <= TEMP1 SLL TO_INTEGER(UNSIGNED(TEMP2));
WHEN SRLR => TEMP_OUT <= TEMP1 SRL TO_INTEGER(UNSIGNED(TEMP2));
WHEN OTHERS => TEMP_OUT <= (OTHERS=>'Z');
END CASE;
ALU_OUT <= TEMP_OUT;
END PROCESS P_ALU;
END BEHAVORAL;
the problem is with the libraries. like i am also using '+' operator so i have to use the arithmatic library, likewise i am also making conversions from std_logic_vector to undigned integer so i need the unsigned library as well. similarly for SLL and SRL i need the numeric library. please help me if anybody can understand my problem.
thanx to all of u in advance.
regards,
ashfaq ahmed
i am implementing a very simple and small ALU. basically i was a programmer of verilog but unfortunately i have to do this job in VHDL now. the code is written below:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.NUMERIC_STD.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE WORK.TYPE_ALU.ALL;
ENTITY ALU IS
PORT (
FUNC : IN TYPE_OP;
IN1 : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
IN2 : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
ALU_OUT : OUT STD_LOGIC_VECTOR(31 DOWNTO 0));
END ALU;
ARCHITECTURE BEHAVIOR OF ALU IS
SIGNAL IN1_IN2 : STD_LOGIC_VECTOR(31 DOWNTO 0);
SIGNAL TEMP_OUT : STD_LOGIC_VECTOR(31 DOWNTO 0);
SIGNAL TEMP1 : STD_LOGIC_VECTOR(31 DOWNTO 0);
SIGNAL TEMP2 : STD_LOGIC_VECTOR(31 DOWNTO 0);
BEGIN
-- VARIABLE V1 : INTEGER;
-- VARIABLE V2 : INTEGER;
P_ALU: PROCESS (FUNC,IN1,IN2)
BEGIN
TEMP1 <= IN1;
TEMP2 <= IN2;
CASE FUNC IS
WHEN ADD|LDMEM|SDMEM|ADDI => TEMP_OUT <= TEMP1+TEMP2;
WHEN SUBA|SUBI => TEMP_OUT <= TEMP1-TEMP2;
WHEN LAND|LANDI => TEMP_OUT <= TEMP1 AND TEMP2;
WHEN LOR|LORI => TEMP_OUT <= TEMP1 OR TEMP2;
WHEN LXOR|LXORI => TEMP_OUT <= TEMP1 XOR TEMP2;
WHEN LNOR|LNORI => TEMP_OUT <= NOT(TEMP1 OR TEMP2);
WHEN SLT|SLTI => TEMP_OUT <= sxt((TEMP1 < TEMP2),32);
WHEN SLLR => TEMP_OUT <= TEMP1 SLL TO_INTEGER(UNSIGNED(TEMP2));
WHEN SRLR => TEMP_OUT <= TEMP1 SRL TO_INTEGER(UNSIGNED(TEMP2));
WHEN OTHERS => TEMP_OUT <= (OTHERS=>'Z');
END CASE;
ALU_OUT <= TEMP_OUT;
END PROCESS P_ALU;
END BEHAVORAL;
the problem is with the libraries. like i am also using '+' operator so i have to use the arithmatic library, likewise i am also making conversions from std_logic_vector to undigned integer so i need the unsigned library as well. similarly for SLL and SRL i need the numeric library. please help me if anybody can understand my problem.
thanx to all of u in advance.
regards,
ashfaq ahmed