VHDL 有符号值
VHDL Signed Values
我刚开始在大学学习 VHDL 模块,我的讲师不太擅长解释。如何在 VHDL 中 use/declare 签名值?
这是我所学的基本代码格式,我目前正在编写一个 2 位减法器。其他网站的信息相当混乱。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
entity TwoBitSubtractor is port(
x,y :in integer range 0 to 3;
result :out integer range 0 to 3);
end TwoBitSubtractor;
architecture gates of TwoBitSubtractor is
begin
result<= x - y;
end gates;
您应该使用 signed
类型来指定带符号的值。整数也可以用于以更易读的方式声明值,但是这样你就超出了位级定义,我认为这在 VHDL 中是不希望的。例如,您忽略了用于 integer
的任何信号的位数,这对于高级语言可能很好,但对于 VHDL 就不太有用了。
library ieee;
use ieee.numeric_std.all;
entity TwoBitSubtractor is port(
x : in signed(2 downto 0);
y : in signed(2 downto 0);
result : out signed(2 downto 0));
end TwoBitSubtractor;
architecture gates of TwoBitSubtractor is
begin
result <= x - y;
end gates;
查看它们在实体端口中的声明方式。关于signed/unsigned的更多详情,请查看here
还有 TwoBitSubtractor
和 testbench
的在线模拟,检查 here
我刚开始在大学学习 VHDL 模块,我的讲师不太擅长解释。如何在 VHDL 中 use/declare 签名值?
这是我所学的基本代码格式,我目前正在编写一个 2 位减法器。其他网站的信息相当混乱。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
entity TwoBitSubtractor is port(
x,y :in integer range 0 to 3;
result :out integer range 0 to 3);
end TwoBitSubtractor;
architecture gates of TwoBitSubtractor is
begin
result<= x - y;
end gates;
您应该使用 signed
类型来指定带符号的值。整数也可以用于以更易读的方式声明值,但是这样你就超出了位级定义,我认为这在 VHDL 中是不希望的。例如,您忽略了用于 integer
的任何信号的位数,这对于高级语言可能很好,但对于 VHDL 就不太有用了。
library ieee;
use ieee.numeric_std.all;
entity TwoBitSubtractor is port(
x : in signed(2 downto 0);
y : in signed(2 downto 0);
result : out signed(2 downto 0));
end TwoBitSubtractor;
architecture gates of TwoBitSubtractor is
begin
result <= x - y;
end gates;
查看它们在实体端口中的声明方式。关于signed/unsigned的更多详情,请查看here
还有 TwoBitSubtractor
和 testbench
的在线模拟,检查 here