我正在用 VHDL 编写代码,用于信号的算术运算。我声明信号如下:
signal x : std_logic_vector (7 downto 0);
signal y: std_logic_vector (7 downto 0);
signal z: std_logic_vector ( 7 downto 0);
z<= x-y ;
详细地:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
USE ieee.std_logic_arith.conv_std_logic_vector;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
signal heat0,heat1,heat2 : std_logic_vector(31 downto 0);
signal Data_In, M_AXIS_TDATA Fixed_input_tdata: std_logic_vector (31 downto 0);
shared variable float, h0,h1,h2,fixed1,fixed2,fixed3,fixed_shift :ufixed (23 downto -8);
shared variable fixed_64: ufixed (31 downto -32);
float := to_ufixed(unsigned (Fixed_input_tdata), 23,-8);
h2 := to_ufixed(unsigned(Data_In),23,-8);
heat1 <= Data_in;
h1 := to_ufixed(unsigned(heat1),23,-8);
heat0<= heat1;
h0 := to_ufixed(unsigned(heat0),23,-8);
heat1_mult := std_logic_vector(unsigned(heat1) sll 1);
fixed_shift := to_ufixed(unsigned (heat1_mult), 23,-8);
fixed1 := fixed_shift+h2;
fixed2 := h0-fixed1;
fixed_64 := fixed2 *float;
fixed3 := h1+fixed_64;--(23 downto -8);
M_AXIS_TDATA <= std_logic_vector (fixed3);
那么用定点对std_logiC-vector进行算术运算是正确的方法吗?
举个例子,z= 0x01-0x11。这将给出负输出(0xF0):但我不想要负输出。我想将此值视为正值。我什至尝试将这些信号类型更改为无符号,但仍然无法成功。实际上我在 vhdl 中有一些复杂的数学运算,所以我在这里只是举一个例子来说明我的观点。我不想使用带符号的值。如何发送正无符号输出?
再举一个例子:如果我的输出是 bf978000,它将显示为负数 -1.18。我希望它是积极的,而不是消极的。
让我再举一个例子:
z= 2+ [0.2 * (4-10) ] = 0.8 。0.8 定点格式(0x000000cd)(24 个整数,8 个小数格式):0.2 是 0x00000033 定点格式。(24 个整数,8 个小数格式)但我得到 [0x00000002 + (0x00000033 * (0x00000004-0x0000000A)] = FFFFFED0。(这是负数)。如何再次将输出表示为 0.8。