library ieee;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
entity eight_bits_adder is
port(SUBADD:in std_logic;dis:in std_logic;
OPa:in std_logic_vector(7 downto 0);
OPb:in std_logic_vector(7 downto 0);
Dout:out std_logic_vector(8 downto 0):=(others=>'Z'));
end entity eight_bits_adder;
architecture behavioral of eight_bits_adder is
signal result:std_logic_vector(8 downto 0):=(others=>'0');
signal OPb_temp:std_logic_vector(7 downto 0);
begin
output:process(dis) is
begin
if dis='0' then
Dout<=(others=>'Z');
else
Dout<=result;
end if;
end process output;
OP:process(SUBADD,OPa,OPb,OPb_temp) is
variable temp:std_logic;
variable Carry:std_logic;
begin
OPb_temp<=OPb;
temp:=SUBADD;
Carry:='0';
if SUBADD='1' then
OPb_temp<=not OPb_temp;
end if;
for index in OPa'reverse_range loop
result(index)<=OPa(index) xor OPb_temp(index);
Carry:=(OPa(index) and OPb_temp(index)) or ((OPa(index) xor OPb_temp(index)) and temp);
temp:=Carry;
end loop;
result(result'left)<=Carry;
end process OP;
end architecture behavioral;
以上是我的8位加法器代码,基本思想是输入dis
控制数据是否出现在输出上,输入SUBADD
确定将执行,加或减的操作。问题是我运行了模拟之后,输出的只是“ xxxxxxxxx”!
我可以看到您的代码有两个问题。可能还有更多。
一个问题是因为您从一个(隐式)过程驱动数组result
的一个元素:
result(result'left)<=Carry;
以及此过程中的其他位从a之内for
循环:
for index in OPa'reverse_range loop
result(index)<=OPa(index) xor OPb_temp(index);
...
end loop;
在精化时间,您的模拟不知道包含此result
循环的进程将驱动for
的哪些位。因此,假设它们都是。随后未分配值的任何元素将由'U'
驱动-std_logic
子类型的默认值。因此,至少result
的左位将由两个进程驱动。您的代码很复杂,还没有提供MCVE。所以,这就是我能说的。您需要了解有关VHDL 最长静态前缀的更多信息。
另一个问题是,直到所有进程挂起后,才会发生信号分配(<=
)。因此,例如,在after this
OPb_temp
的新值将不可用。 result(index)<=OPa(index) xor OPb_temp(index);
行已执行。您需要了解有关VHDL 信号分配和增量周期的更多信息。