n位饱和加法器

n-bit adder with saturation

你好,我正在尝试在具有饱和选项的 VHDL 中创建一个 n 位 adder/subtractor,如果饱和度 = 1,那么如果 a + b 溢出输出向量,它应该锁定到最大值减法的值,反之亦然。

这是处理饱和部分的过程,我不会 post 我的加法器的所有代码都在这里,因为我知道那部分没有问题,问题是我如何思考处理饱和...

process(saturate, o_flow, temp_sum)
begin
if (saturate = '1' AND o_flow = '1') then
    if carry(WIDTH-1) = '0' then
        y <= (WIDTH-1 => '0', others => '1');
    else
        y <= (WIDTH-1 => '1', others => '0');
    end if;
else
    y <= temp_sum;
end if;
end process;

很想得到一些帮助,所以你能发现我的错误吗?

您只是在敏感度列表中忘记了 carry

process(saturate, o_flow, temp_sum, carry)
begin
if (saturate = '1' AND o_flow = '1') then
    if carry(WIDTH-1) = '0' then
        y <= (WIDTH-1 => '0', others => '1');
    else
        y <= (WIDTH-1 => '1', others => '0');
    end if;
else
    y <= temp_sum;
end if;
end process;

但是由于你没有真正解释你观察到的东西以及它有什么问题,可能还有其他问题...