Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logic 8位ALU溢出故障和使用VHDL执行_Logic_Vhdl_Hardware_Fpga - Fatal编程技术网

Logic 8位ALU溢出故障和使用VHDL执行

Logic 8位ALU溢出故障和使用VHDL执行,logic,vhdl,hardware,fpga,Logic,Vhdl,Hardware,Fpga,我一直在尝试设计一个8位ALU,但我遇到了溢出和Cout的问题。我花了几个小时试着去做,但没有得到正确的结果,我希望有人能解释一下如何去纠正它。非常感谢 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; -- Uncomment the following library declaration if using -- arithmetic f

我一直在尝试设计一个8位ALU,但我遇到了溢出和Cout的问题。我花了几个小时试着去做,但没有得到正确的结果,我希望有人能解释一下如何去纠正它。非常感谢

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity ALU_8_bit is
    Port ( A : in  STD_LOGIC_VECTOR (3 downto 0);
           B : in  STD_LOGIC_VECTOR (3 downto 0);
           CTRL : in  STD_LOGIC_VECTOR (2 downto 0);
           Y : out  STD_LOGIC_VECTOR (3 downto 0);
              OFL: out STD_LOGIC;
              COUT: out STD_LOGIC
              );
end ALU_8_bit;



architecture Behavioral of ALU_8_bit is

signal result: std_logic_vector(3 downto 0);


begin

process(A,B,CTRL) begin
    if (CTRL ="000") then
        result <= A; 
    elsif (CTRL = "001") then
        result <= A + B; 
    elsif (CTRL = "010") then
        result <= A - B;
    elsif (CTRL = "011") then
        result <= NOT A + 1;
    elsif (CTRL = "100") then
        result <= NOT A; 
    elsif (CTRL = "101") then
        result <= A AND B;
    elsif (CTRL = "110") then 
        result <= A OR B;  
    else --(CTRL = "111") then
        result <= A XOR B;
    end if;
end process;

Y <= result;

--process (A,B,result,cout)
--begin
--  if  ((A(3) = '1') and (B(3) ='1') and (result(3) = '0')) then Cout <= '1';
--  elsif ((A(3) = '1') and (B(3) = '0') and (result(3) = '0')) then Cout <= '1';
--  elsif ((A(3) = '0') and (B(3) = '1') and (result(3) = '0')) then Cout <= '1';
--  else Cout <= '0';
--  end if;
--end process;

process(result,CTRL)
begin 
    if (CTRL = "001") then
        --Y <= result;
        COUT <=  A(3) and B(3); --result(3);
        OFL <= result(3) xor (B(2) and A(2));
    else 
        OFL <= '0';
        COUT <= '0';
    end if;
end process;

end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.NUMERIC_STD.ALL;
使用IEEE.STD_LOGIC_UNSIGNED.ALL;
--如果使用,请取消注释以下库声明
--具有有符号或无符号值的算术函数
--使用IEEE.NUMERIC_STD.ALL;
--如果正在实例化,请取消对以下库声明的注释
--此代码中的任何Xilinx原语。
--UNISIM图书馆;
--使用UNISIM.VComponents.all;
实体ALU_8_位为
端口(A:标准逻辑向量(3到0);
B:标准逻辑向量(3到0);
CTRL:标准逻辑向量(2到0);
Y:输出标准逻辑向量(3到0);
OFL:输出标准逻辑;
COUT:out标准逻辑
);
结束ALU_8_位;
ALU_8_位的结构是
信号结果:标准逻辑向量(3到0);
开始
流程(A、B、CTRL)开始
如果(CTRL=“000”),则

结果我认为,如果您想要获得Cout和溢出,最好再创建一个变量result

信号结果:标准逻辑向量(4到0)

根据操作的不同,您可以比较所需的位,以了解它是溢出还是溢出


顺便说一句,它是一个4位ALU,而不是8位。我认为,如果您想获得Cout和溢出,最好再多一位创建变量结果:

信号结果:标准逻辑向量(4到0)

根据操作的不同,您可以比较所需的位,以了解它是溢出还是溢出


顺便说一下,它是一个4位ALU,而不是8位,我想你要找的技巧是使“结果”比输入宽一点,以保持进位。然后,在添加输入之前,需要将输入扩展1位…根据Brian的注释
COUT
分配
result(4)
。还请注意,需要为加法和减法(正确)指定
OFL
大小写,请参见(阅读全文)。您将继续使用
A(3)
B(3)
result(3)
位。请注意,实际上A-B是A+而不是B+1,其中+1表示进位。你指望合成只制造一个ALU。如果你有进位,你可以使用方法2。我认为你正在寻找的技巧是使“结果”比输入宽一点,以保持进位。然后,在添加输入之前,需要将输入扩展1位…根据Brian的注释
COUT
分配
result(4)
。还请注意,需要为加法和减法(正确)指定
OFL
大小写,请参见(阅读全文)。您将继续使用
A(3)
B(3)
result(3)
位。请注意,实际上A-B是A+而不是B+1,其中+1表示进位。你指望合成只制造一个ALU。如果你有进位,你可以使用方法2。我认为你正在寻找的技巧是使“结果”比输入宽一点,以保持进位。然后,在添加输入之前,需要将输入扩展1位…根据Brian的注释
COUT
分配
result(4)
。还请注意,需要为加法和减法(正确)指定
OFL
大小写,请参见(阅读全文)。您将继续使用
A(3)
B(3)
result(3)
位。请注意,实际上A-B是A+而不是B+1,其中+1表示进位。你指望合成只制造一个ALU。如果你有随身携带,你可以使用方法2。