Vhdl 从16个1位ALU(结构代码)创建16位ALU

Vhdl 从16个1位ALU(结构代码)创建16位ALU,vhdl,alu,Vhdl,Alu,我已经为1位ALU以及控制电路创建了结构和行为代码。控制电路决定将在两个变量之间执行的操作:a,b 以下是我的行为部分代码: library ieee; use ieee.std_logic_1164.all; package erotima2 is -- AND2 declaration component myAND2 port (outnotA,outnotB: in std_logic; outAND: out std_logic); end component;

我已经为1位ALU以及控制电路创建了结构和行为代码。控制电路决定将在两个变量之间执行的操作:a,b

以下是我的行为部分代码:

 library ieee;
use ieee.std_logic_1164.all;
package erotima2 is

-- AND2 declaration
 component myAND2
        port (outnotA,outnotB: in std_logic; outAND: out std_logic);
 end component;


-- OR2 declaration
  component myOR2          
       port (outnotA,outnotB: in std_logic; outOR: out std_logic);
 end component;

-- XOR2 declaration
  component myXOR2          
       port (outnotA,outnotB: in std_logic; outXOR: out std_logic);
 end component;

--fulladder declaration
  component fulladder     
            port(CarryIn,outnotA,outnotB: in std_logic; sum,CarryOut: out std_logic);
  end component;

--Ainvert declaration
  component notA        
            port(a: in std_logic; signala: std_logic_vector(0 downto 0); outnotA: out std_logic);
  end component;    

--Binvert declaration
  component notB                
           port(b: in std_logic; signalb: std_logic_vector(0 downto 0); outnotB: out std_logic);
  end component;

    --ControlCircuit declaration--
component ControlCircuit
    port (
            opcode : in std_logic_vector (2 downto 0);
            signala,signalb : out std_logic_vector(0 downto 0);
            operation : out std_logic_vector (1 downto 0);
            CarryIn: out std_logic);

end component;

--mux4to1 declaration
    component mux4to1           
            port(outAND, outOR, sum, outXOR: in std_logic; operation: in std_logic_vector(1 downto 0); Result: out std_logic);
    end component;

end package erotima2;   


--2 input AND gate
library ieee;
use ieee.std_logic_1164.all;
 entity myAND2 is
     port (outnotA,outnotB: in std_logic; outAND: out std_logic);
 end myAND2;
 architecture model_conc of myAND2 is
 begin
    outAND<= outnotA and outnotB;
 end model_conc;


 -- 2 input OR gate  
library ieee;
use ieee.std_logic_1164.all;
  entity myOR2 is
        port (outnotA,outnotB: in std_logic; outOR: out std_logic);
 end myOR2;
 architecture model_conc2 of myOR2 is
  begin
        outOR <= outnotA or outnotB;
 end model_conc2;     


--2 input XOR gate
library ieee;
use ieee.std_logic_1164.all;
    entity myXOR2 is
        port(outnotA,outnotB: in std_logic; outXOR: out std_logic);
    end myXOR2;
    architecture model_conc3 of myXOR2 is
    begin 
    outXOR <= outnotA xor outnotB;
    end model_conc3;      

--3 input full adder      
library ieee;
use ieee.std_logic_1164.all;
    entity fulladder is
        port(CarryIn,outnotA,outnotB: in std_logic; sum,CarryOut: out std_logic);
    end fulladder;
    architecture model_conc4 of fulladder is
    begin
    CarryOut <= (outnotB and CarryIn) or (outnotA and CarryIn) or (outnotA and outnotB);
    sum <= (outnotA and not outnotB and not CarryIn) or (not outnotA and outnotB and not CarryIn) or (not outnotA and not outnotB and CarryIn) or (outnotA and outnotB and CarryIn);
    end model_conc4;

--1 input notA
library ieee;
use ieee.std_logic_1164.all;
    entity notA is
        port(a: in std_logic; signala:std_logic_vector(0 downto 0); outnotA: out std_logic);
    end notA;
    architecture model_conc6 of notA is
    begin
    with signala select
    outnotA <=  a when "0",
                        not a when others;
    end model_conc6;

--1 input notB    
library ieee;
use ieee.std_logic_1164.all;
    entity notB is
        port(b: in std_logic; signalb: std_logic_vector(0 downto 0); outnotB: out std_logic);
    end notB;
    architecture model_conc5 of notB is
    begin
    with signalb select
    outnotB <=  b when "0",
                        not b when others;
    end model_conc5;


--4 input MUX 
library ieee;
use ieee.std_logic_1164.all;
    entity mux4to1 is
        port(outAND, outOR, sum, outXOR: in std_logic; operation: in std_logic_vector(1 downto 0); Result: out std_logic);
    end mux4to1;
    architecture model_conc7 of mux4to1 is
    begin
    with operation select
        Result<= outAND when "00",
                 outOR  when "01",
              sum    when "10",
                   outXOR when OTHERS;
    end model_conc7 ; 
现在,对于困难的部分,我需要将1位ALU 16次用作组件,以创建一个16位ALU。保持控制电路独立于代码的其余部分是很重要的。我曾尝试使用std_逻辑_向量(15到0),但它不起作用,我想使用前面的代码段作为组件。有人能给出一些提示或想法来帮助将16位1位ALU连接到一个完整的16位ALU吗?提前感谢阅读这堵巨大的文字墙的读者。

您最近的评论

是的,我知道我的代码很奇怪,但我们被要求根据。至于重复的帖子,我在发布之前检查过,它们只是在结构上实现的,而在我的例子中,我也需要编写行为部分

解释了这个问题,把拼写错误放在一边。您会注意到实体结构的架构与上面1位alu图上显示的信号不匹配,该图不包含实例化的控制电路

如果要提供与上图匹配的设计单元,则可以连接1位alu进位链,同时从控制块推导lsb的进位,该控制块为减法提供+1和反转:

library ieee;
use ieee.std_logic_1164.all;

entity alu_16_bit is
    port (
        a:          in  std_logic_vector (15 downto 0);
        b:          in  std_logic_vector (15 downto 0);
        opcode:     in  std_logic_vector (2 downto 0);
        result:     out std_logic_vector (15 downto 0);
        carryout:   out std_logic
    );
end entity;

architecture foo of alu_16_bit is
    component alu_1_bit is
        port (
            a:          in  std_logic;
            b:          in  std_logic;
            ainvert:    in  std_logic;
            binvert:    in  std_logic;
            carryin:    in  std_logic;
            operation:  in  std_logic_vector (1 downto 0);
            result:     out std_logic;
            carryout:   out std_logic
        );
    end component;
    component controlcircuit is
        port (
            opcode:     in  std_logic_vector(2 downto 0);
            ainvert:    out std_logic;
            binvert:    out std_logic;
            operation:  out std_logic_vector(1 downto 0);
            carryin:    out std_logic  -- invert a or b, add + 1 for subtract
        );
    end component;

    signal ainvert:     std_logic;
    signal binvert:     std_logic;
    signal operation:   std_logic_vector (1 downto 0);
    signal carry:       std_logic_vector (16 downto 0);
begin

CONTROL_CIRCUIT:
    controlcircuit
        port map (
            opcode => opcode,
            ainvert => ainvert,
            binvert => binvert,
            operation => operation,
            carryin => carry(0)   -- for + 1 durring subtract
        );

GEN_ALU:
    for i in 0 to 15 generate
ALU:
        alu_1_bit
            port map (
                a => a(i),
                b => b(i),
                ainvert => ainvert,
                binvert => binvert,
                carryin => carry(i),
                operation => operation,
                result => result(i),
                carryout => carry(i + 1) 
            );
    end generate;

    carryout <= carry(16) when operation = "10" else '0';

end architecture;
ieee库;
使用ieee.std_logic_1164.all;
实体alu_16_位为
港口(
a:标准逻辑向量(15到0);
b:标准逻辑向量(15到0);
操作码:标准逻辑向量(2到0);
结果:输出标准逻辑向量(15到0);
执行:输出标准逻辑
);
终端实体;
alu_16_位的架构foo是
组件alu_1_位为
港口(
答:标准逻辑;
b:标准逻辑;
ainvert:标准逻辑中;
binvert:标准逻辑中;
carryin:标准逻辑;
操作:标准逻辑向量(1到0);
结果:输出std_逻辑;
执行:输出标准逻辑
);
端部元件;
元件控制电路
港口(
操作码:标准逻辑向量(2到0);
ainvert:输出标准逻辑;
binvert:输出标准逻辑;
操作:输出标准逻辑向量(1到0);
进位:输出标准逻辑——反转a或b,加+1表示减法
);
端部元件;
信号转换:标准逻辑;
信号binvert:std_逻辑;
信号操作:标准逻辑向量(1到0);
信号进位:标准逻辑向量(16至0);
开始
控制电路:
控制电路
港口地图(
操作码=>操作码,
ainvert=>ainvert,
binvert=>binvert,
操作=>操作,
进位=>进位(0)--对于+1减去
);
阿卢将军:
对于0到15中的i,生成
ALU:
alu_1_位
港口地图(
a=>a(i),
b=>b(i),
ainvert=>ainvert,
binvert=>binvert,
进位=>进位(i),
操作=>操作,
结果=>结果(i),
结转=>进位(i+1)
);
终端生成;

欢迎使用堆栈溢出。请阅读。你发布了这么多代码,却没有给出明确的问题陈述。您的一个问题似乎是“有人能给出任何有助于将16个1位ALU连接到一个完整的16位ALU的提示或想法吗?”。其余的似乎没有必要。你已经尝试了什么,在哪里失败了?附言,代码中有很多错误。。。。你测试过吗?还是只是尝试错误?嗨,谢谢你的回答,很抱歉发布了太多的代码。我对代码进行了测试,它按照1位计算部分的预期工作(我是这门语言的初学者,所以我不知道我的代码有多少错误)。为了更清楚地表达我的问题,我正在尝试使用已经创建的1位ALU来创建一个16位ALU,它在两个16位变量之间进行计算。我试图做的是对代码的所有元素使用“std_logic_vector(15到0)”,除了控制电路,它只需要一次使用来确定变量之间的计算(和、或、相加等)。这不起作用,我认为将控制电路代码附加到我需要重复的部分是一个错误。因此,我试图理解的是,我试图实现解决方案的方式是正确的,但执行是错误的,还是从一开始就完全错误。再次感谢您抽出时间!可能重复的,和许多其他发现使用Search感谢你这个非常详细的答案!我完全明白我一直做错了什么。非常感谢你!
  library IEEE;
use ieee.std_logic_1164.all;
use work.erotima2.all;

entity structural is 
    port (a,b: in std_logic;
            opcode : in std_logic_vector ( 2 downto 0);
            Result,CarryOut : out std_logic);
end structural;

architecture alu of structural is 
    signal outAND,outOR,outXOR,sum,outnotA,outnotB,CarryIn : std_logic;
    signal signala,signalb : std_logic_vector (0 downto 0);
    signal operation : std_logic_vector (1 downto 0);
begin 

u0 : myAND2 port map (outnotA,outnotB,outAND);
u1 : myOR2 port map (outnotA,outnotB,outOR);
u2 : myXOR2 port map (outnotA,outnotB,outXOR);
u3 : fulladder port map (CarryIn,outnotA,outnotB,sum,CarryOut);
u4 : notA port map (a,signala,outnotA);
u5 : notB port map (b,signalb,outnotB);
u6 : mux4to1 port map (outAND, outOR,sum, outXOR, operation, Result );
u8 : ControlCircuit port map(opcode,signala,signalb,operation,CarryIn);
end alu; 
library ieee;
use ieee.std_logic_1164.all;

entity alu_16_bit is
    port (
        a:          in  std_logic_vector (15 downto 0);
        b:          in  std_logic_vector (15 downto 0);
        opcode:     in  std_logic_vector (2 downto 0);
        result:     out std_logic_vector (15 downto 0);
        carryout:   out std_logic
    );
end entity;

architecture foo of alu_16_bit is
    component alu_1_bit is
        port (
            a:          in  std_logic;
            b:          in  std_logic;
            ainvert:    in  std_logic;
            binvert:    in  std_logic;
            carryin:    in  std_logic;
            operation:  in  std_logic_vector (1 downto 0);
            result:     out std_logic;
            carryout:   out std_logic
        );
    end component;
    component controlcircuit is
        port (
            opcode:     in  std_logic_vector(2 downto 0);
            ainvert:    out std_logic;
            binvert:    out std_logic;
            operation:  out std_logic_vector(1 downto 0);
            carryin:    out std_logic  -- invert a or b, add + 1 for subtract
        );
    end component;

    signal ainvert:     std_logic;
    signal binvert:     std_logic;
    signal operation:   std_logic_vector (1 downto 0);
    signal carry:       std_logic_vector (16 downto 0);
begin

CONTROL_CIRCUIT:
    controlcircuit
        port map (
            opcode => opcode,
            ainvert => ainvert,
            binvert => binvert,
            operation => operation,
            carryin => carry(0)   -- for + 1 durring subtract
        );

GEN_ALU:
    for i in 0 to 15 generate
ALU:
        alu_1_bit
            port map (
                a => a(i),
                b => b(i),
                ainvert => ainvert,
                binvert => binvert,
                carryin => carry(i),
                operation => operation,
                result => result(i),
                carryout => carry(i + 1) 
            );
    end generate;

    carryout <= carry(16) when operation = "10" else '0';

end architecture;