模拟中8位加法器的输出为xxxxxxxxx

问题描述 投票:0回答:1
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”!

“错误的输出模拟结果”

vhdl quartus
1个回答
0
投票

我可以看到您的代码有两个问题。可能还有更多。

一个问题是因为您从一个(隐式)过程驱动数组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 信号分配增量周期的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.