Je dois créer une ALU qui a des conditions pour add, add unsigned, sub, sub unsigned, and, or, xor, nor, slt, et slt unsigned. J'ai des difficultés à mettre en œuvre la conception pour inclure les conditions non signées. J'ai noté dans le code où les erreurs se produisent. De plus, tous les autres aspects de l'UAL fonctionnent correctement, c'est SEULEMENT la partie non signée qui me pose problème. J'ai fait des recherches au sujet de unsigned et de std_logic mais je n'ai pas réussi à trouver les problèmes similaires au mien.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.NUMERIC_STD.all;
entity ALU is
Port (A, B : in STD_LOGIC_VECTOR (31 downto 0);
ALUCntl : in STD_LOGIC_VECTOR (3 downto 0);
Carryin : in STD_LOGIC;
ALUOut : out STD_LOGIC_VECTOR (31 downto 0);
Zero : out STD_LOGIC;
Carryout : out STD_LOGIC;
Overflow : out STD_LOGIC);
end ALU;
architecture Behavioral of ALU is
signal ALU_Result, slt, sltu : std_logic_vector (31 downto 0);
signal add_result,sub_result,a32,b32: std_logic_vector(32 downto 0);
-- create separate a and b for unsigned
signal add_u,sub_u,a32u,b32u: unsigned(32 downto 0);
signal c32: std_logic_vector(32 downto 0):=(others=>'0');
signal add_ov,sub_ov:std_logic;
begin
with ALUCntl select
ALU_Result <=add_result(31 downto 0) when "0010", -- add
sub_result(31 downto 0) when "0110", -- sub
slt when "0111", -- set less than
std_logic_vector(add_u(31 downto 0)) when "0100", -- add unsigned
std_logic_vector(sub_u(31 downto 0)) when "0101", -- sub unsigned
sltu when "1000", -- set less than unsigned
A AND B when "0000",
A OR B when "0001",
A XOR B when "0011",
A NOR B when "1100",
A when others;---condition for all other alu control signals
ALUOut <= ALU_Result;
----Set less than-----------------------------------
process(a32,b32)
begin
if (a32 < b32) then
slt <= x"00000001";
else
slt <= x"00000000";
end if;
end process;
process(a32u,b32u)
begin
if (a32u < b32u) then
sltu <= x"00000001";
else
sltu <= x"00000000";
end if;
end process;
----Addition Operation and carry out generation-----
a32 <='0'& A;
b32 <='0'& B;
c32(0)<=Carryin;
add_result<=std_logic_vector(signed(a32) + signed(b32) + signed(c32));
sub_result<=std_logic_vector(signed(a32) - signed(b32));
a32u <=unsigned('0'& A);
b32u <=unsigned('0'& B);
add_u<=a32u + b32u + unsigned(c32);
sub_u<=a32u - b32u;
---Zero flag-----------------------------
Zero <= '1' when ALU_Result =x"00000000" else '0';
---Overflow flag---------------------------------------
add_ov<= (A(31)and B(31) and (not alu_result(31))) or ((not A(31))and (not B(31)) and alu_result(31));
sub_ov<= (A(31)and (not B(31)) and (not alu_result(31))) or ((not A(31))and B(31) and alu_result(31));
with ALUCntl select
Overflow<= add_ov when "0010" | "0100",
sub_ov when "0110" | "0101",
'Z' when others;
---Carryout-------------------------------------------------
With ALUCntl select
Carryout<= add_result(32) when "0010",
sub_result(32) when "0110",
add_u(32) when "0100",
sub_u(32) when "0101",
'Z' when others;
end Behavioral;