在结构VHDL中连接执行加法器/减法器

时间:2015-02-12 03:17:02

标签: vhdl

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

    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 个答案:

答案 0 :(得分:0)

使进位阵列更长一段时间:

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

并改变这一点:

     o_Couts => carry(i));

到此:

     o_Couts => carry(i+1));
在生成语句中

,同时保持i_Cin进位输入关联。

如果最后一次输出没有通过输出端口传送,则网络将在合成期间被吃掉。