如果我将两个std_logic_vector分别转换为值1和0
signal mlx, mtx : std_logic_vector(15 downto 0) 转换为一个整数
variable WLX : integer;
variable WTX : integer;
WLX := TO_INTEGER(signed(mlx));
WTX := TO_INTEGER(signed(mtx));然后将这些与-1字面量的减法进行比较:
if WTX-WLX = -1 结果会是真的吗?
谢谢
发布于 2013-06-05 23:09:19
如果mlx=X为“0001”,mtx=X为“0000”,那么是的,从mtx中以整数形式减去mlx得到-1,所以给定问题的答案是肯定的。
但是:将值转换为整数,以便对它们进行操作或比较,这通常是代码写得不好的标志。
为什么不对mlx和mtx使用带符号的,并避免使用整数呢?
architecture arch of ent is
signal mlx, mtx : signed(15 downto 0);
begin
process(clk) begin
if(rising_edge(clk)) then
if(mtx - mlx = -1) then
-- Do what needs to be done.
end if;
end if;
end process;
end architecture;https://stackoverflow.com/questions/16929851
复制相似问题