2015-02-12 48 views
0

因此,我使用以下VHDL代码来实现仅使用2:1多路复用器,反相器(翻转位)和全加器的Nbit加法器/减法器。当第一个加法器有i_Control的进位时,我有问题将加法器的执行连接到下一个加法器。任何帮助将不胜感激 :)。连接执行结构VHDL中的加法器/减法器

library IEEE; 
use IEEE.std_logic_1164.all; 
use work.all; 

entity add_subtract is 
    generic(N : integer := 16); 
    port(i_M : in std_logic_vector(N-1 downto 0); 
     i_N : in std_logic_vector(N-1 downto 0); 
     i_Control : in std_logic_vector(N-1 downto 0); 
     o_S : out std_logic_vector(N-1 downto 0)); 

end add_subtract; 

architecture structure of add_subtract is 

component bit_adder 
    port(i_X  : in std_logic; 
      i_Y  : in std_logic; 
      i_Cin : in std_logic; 
      o_Ss : out std_logic; 
     o_Couts : out std_logic); 
end component; 

component inverter 
    port(i_A : in std_logic; 
     o_F : out std_logic); 
end component; 

component bit_mux 
    port(i_X : in std_logic; 
     i_Y : in std_logic; 
      i_S : in std_logic; 
      o_N : out std_logic); 
end component; 

signal compvalue, muxvalue, addervalue : std_logic_vector(N-1 downto 0); 
signal sel, carry : std_logic_vector(N-1 downto 0); 
signal k : integer := 0; 
begin 

carry(0) <= i_Control(0); 

G1: for i in 0 to N-1 generate 
one_comp: inverter 
    port map(i_A  => i_N(i), 
     o_F  => compvalue(i)); 

mux: bit_mux 
    port map(i_X  => i_N(i), 
     i_Y  => compvalue(i), 
     i_S  => i_Control(i), 
     o_N  => muxvalue(i)); 

struct_adder: bit_adder 
    port map(i_X  => i_M(i), 
     i_Y  => muxvalue(i), 
     i_Cin => carry(i), 
     o_Ss => o_S(i), 
     o_Couts => carry(i)); 

end generate; 

end structure; 
+1

家庭作业。没有人像这样实现一个减法器。只需输入'c <= a-b;' – Philippe 2015-02-12 06:38:23

回答

0

使进阵列一个较长:

signal carry : std_logic_vector(N downto 0); -- was N-1 

并改变这一点:

 o_Couts => carry(i)); 

这样:

 o_Couts => carry(i+1)); 

在生成的语句,而留下i_Cin按原样进行输入关联。

如果最后一次执行不通过输出端口传送,网络将在合成过程中被吃掉。

+0

感谢您的回复。你的建议得到加法器/减法器正常工作:) – 2015-02-13 03:35:19