VHDL减法计算

VHDL subtraction calculation

VHDL如何进行减法运算?它做两个补码吗? 对于 2 位减法器,有人向我展示了对 i/o 使用向量,但它需要 3 个输入 pins/switches 才能测试输出。 (下载到 DE0 Nano Board)。 所以我尝试使用整数值:

entity TwoBitSubtractor is port(
    x,y         : in integer range 0 to 3;
    result     : out integer range -3 to 3);
end TwoBitSubtractor;

architecture gates of TwoBitSubtractor is
begin
    result <= x - y;
 end gates;

它编译成功,但板中的一些输出让我感到困惑。 例如: 01 - 10 = 100

这是DE0纳米板的ss

-1 不是 111 吗?

DE0 纳米板规格 http://www.ti.com/lit/ug/tidu737/tidu737.pdf

您正在使用 integer 信号进行计算,但您只能使用类型 std_logic 或使用 std_logic_vector 设置一组 IO 引脚。因此,在您未向我们展示的顶级实体中的某处,integerstd_logic(_vector) 之间存在转换。没有隐式功能,您必须转换为 signedunsigned 数据类型,请在此处 (Duolos VHDL designer guide) 查看转换函数。

我猜你正在使用 unsigned 值,请尝试在顶级实体中使用 signed。输入也是如此,您不能用 "01""10" 指定 integer,只能用 0、1、2、3 等文字指定。