2016-09-23 92 views
1

我正试图在它的二进制补码中转换一个std_logic_vector。我正试图在矢量上执行-2乘法。std_logic_vector的二进制补码

library ieee; 
use ieee.std_logic_1164.all; 

entity twoscomplement is 
port (x : in std_logic_vector(15 downto 0); 
     y : out std_logic_vector(15 downto 0) 
    ); 
end entity; 

architecture model of twoscomplement is 
signal x_c : std_logic_vector (15 downto 0); 

x_c <= (not(x) +'1')*2 ; -- x_c = -2*x 

end model; 
+0

什么是您的具体问题?你有错误需要处理吗? – user1155120

+0

你在x_c声明后缺少'begin'。对于早于2008年使用'use ieee.numeric_std.all;','x_c <= std_logic_vector(shift_left(not unsigned(x)+ 1,1));'的附加使用条款,',其中shift的距离为1将有一个匹配x的结果长度。对于-2008,使用'ieee.numeric_std_unsigned.all;'和'x_c <= shift_left((不是x + 1),1);'的使用条款。使用“*”会增加结果长度。请参见使用标准软件包指南IEEE Std 1076-2008 G.3.5.1用2的幂乘以余数, – user1155120

+3

不要采用'std_logic_vector'的2的补码。取一个'numeric_std.signed'的2的补码。 –

回答

0

附加库

use IEEE.numeric_std.all; 

...内部架构

x_c <= signed(x);