I have been searching this for a while and have not been able to replicate any posted solutions online so I was hoping some of you wonderful people could help me out. I am creating an ALU. i have a two 32 bit inputs and one 32 bit output along with a 5 bit shamt and a 4 bit control signal. My code is as follows with the error location commented on.
library ieee;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.numeric_std.all;
Entity mips_alu IS
PORT(ALUControl : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
inputA, inputB : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
shamt : IN STD_LOGIC_VECTOR(4 DOWNTO 0);
Zero : OUT STD_LOGIC;
ALU_Result : OUT STD_LOGIC_VECTOR(31 DOWNTO 0)
);
END mips_alu;
ARCHITECTURE behavior of mips_alu IS
BEGIN
PROCESS(ALUControl)
BEGIN
CASE ALUControl is
WHEN "0000" =>
ALU_Result <= inputA AND inputB;
WHEN "0001" =>
ALU_Result <= inputA OR inputB;
WHEN "0010" =>
ALU_Result <= inputA + inputB;
WHEN "0110" =>
ALU_Result <= inputA - inputB;
WHEN "0111" =>
IF (inputA < inputB) THEN
ALU_Result <= inputA;
END IF;
WHEN "1000" =>
ALU_Result <= shift_left(inputB, to_integer(unsigned(shamt)));
-- The line above is where i get my first error, The following lines will have the same issue
WHEN "1001" =>
ALU_Result <= shift_right(inputB, shamt);
WHEN "1010" =>
ALU_Result <= shift_left(inputB, inputA);
WHEN "1011" =>
ALU_Result <= shift_right(inputB, inputA);
WHEN "1100" =>
ALU_Result <= inputA NOR inputB;
WHEN "1101" =>
ALU_Result <= inputB(31 DOWNTO 16);
WHEN OTHERS =>
ALU_Result <= inputA;
END CASE;
END PROCESS;
END behavior;
The error I am getting says:
10511 VHDL Qualified Expression error at mips_alu.vhd(33): shift_left type specified in qualified expression must match std_logic_vector type that is implied for expression by context
I have tried several variations of this so if i am missing something please let me know, all help is appreciated as I am a bit of a novice to vhdl
In the numeric_std document you can find the function shift_left
or shift_right
. In both descriptions there you can see that function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
. So you need to use casting of your std_logic_vector
to unsigned
.
In your case it will looks like:
ALU_Result <= std_logic_vector(shift_left(unsigned(inputB), to_integer(unsigned(shamt))));
end etc. for other lines where you use shift_left
or shift_right
function.