我试图解决一些练习,我必须将名为A的8位向量移到2A(A + A)。
我的解决方案是:(A(7) and '1') & A(6 downto 0) & '0';
entity complementare is
port(a: in std_logic_vector(7 downto 0);
b: out std_logic_vector(7 downto 0));
end complementare;
architecture C of complementare is
signal mask, temp: std_logic_vector(7 downto 0);
component ripplecarry8bit is
port(a,b: std_logic_vector(7 downto 0);
cin: in std_logic;
cout: out std_logic;
s: out std_logic_vector(7 downto 0));
end component;
begin
mask<="11111111";
temp<=a nand mask;
rc: ripplecarry8bit port map(temp, "00000001", '0', cout, b);
end C;
--if you need I post ripplecarry code but consider it as a generic adder
要获得-2A (-A-A)
我想这样做:
signal compA: std_logic_vector(7 downto 0);
compA: complementar port map(A, compA);
--shifting
(compA(7) and '1') & compA(6 downto 0) & '0'; -- -A
现在,我的主要疑问是关于-A
,在使用互补之后,在获得compA之后,我必须将8位向量扩展到9位向量(因为我的输出必须是9位向量),我想这样做,但我有疑问:
'1' & compA; --or should I just append compA to a '0' value?
答案 0 :(得分:1)
对于大小为A
的{{1}}信号std_logic_vector
C_SIZEOF_A
获取等于-A(相同大小)的信号:
补充信号值并在此结果中加1:
signal A : std_logic_vector(C_SIZEOF_A-1 downto 0);
警告:未为std_logic_vector定义'+'运算符。您可以使用您喜欢的解决方案进行添加。我故意不想在这里给出解决方案,因为最简单的是使用signal minus_A : std_logic_vector(C_SIZEOF_A-1 downto 0);
minus_A <= (not A) + 1; -- Warning here !!!
信号,但你说你不能。
将信号乘以2(有符号或无符号)
将空位添加为LSB:
signed
将信号扩展为1位(已签名):
MSB是符号位。只扩展这一点:
signal 2A : std_logic_vector(C_SIZEOF_A downto 0);
2A <= A & '0';
将信号扩展为1位(无符号):
此处没有符号位,只需添加“0”:
signal A_extended : std_logic_vector(C_SIZEOF_A downto 0);
A_extended <= A(C_SIZEOF_A-1) & A;