简体   繁体   English

在 vhdl 中创建 1 位 ALU

[英]Creating 1-bit ALU in vhdl

The following problem is a homework.下面的问题是一个家庭作业。

I need to create an 1-bit slice ALU that can do the following between two 1 bit inputs: and, or, addition using full adder, subtraction by using addition and inverting the inputs, xor.我需要创建一个 1 位切片 ALU,它可以在两个 1 位输入之间执行以下操作:和,或者,使用全加器进行加法,使用加法和反转输入进行减法,异或。 I need a 4 to 1 multiplexer to choose between the those functions of the alu.我需要一个 4 比 1 的多路复用器来在 alu 的这些功能之间进行选择。

This picture summarizes what I need to create这张图总结了我需要创建的内容1 位铝

I am asked to do this with with hierarchical design(structural).我被要求使用分层设计(结构)来做到这一点。 So, I need to create components.所以,我需要创建组件。 This is the part one of the whole project.这是整个项目的第一部分。 In the second part I need to use this 1 bit ALU to create a 16 bit ALU.在第二部分中,我需要使用这个 1 位 ALU 来创建一个 16 位 ALU。 But my question for now is focused on the first part.但我现在的问题集中在第一部分。

I have created an and gate, or gate, ADD for full adder, two not gates to invert inputs and mux 4 to 1.我为全加器创建了一个和门,或门,ADD,两个非门来反转输入和多路复用器 4 到 1。

library IEEE;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

-- Entity or & and 

ENTITY orGate IS
    PORT( a, b: in std_logic;
        s: out std_logic);
END orGate;

ARCHITECTURE structure OF orGate IS
BEGIN
    s <= a OR b;
END structure;

ENTITY andGate IS
    PORT( a, b: in std_logic;
        s: out std_logic);
END andGate;

ARCHITECTURE structure OF andGate IS
BEGIN
    s <= a AND b;
END structure;

--Entity add 

ENTITY ADD IS
PORT(   cin, a, b : in std_logic;
        s, cout     : out std_logic)
END ADD;

ARCHITECTURE structure OF ADD IS
BEGIN
    s <= (a AND (NOT b) AND (NOT cin)) OR ((NOT a) AND b AND (NOT 
cin)) OR ((NOT a) AND (NOT b) AND cin) OR (a AND b AND cin);
    cout <=( a AND b) OR (cin AND a) OR (cin AND b);
END ADD

-- Inverter, Sub, nor

ENTITY notB IS
    PORT( b: in std_logic;
        s: out std_logic);
END notB;

ARCHITECTURE structure OF notB IS
BEGIN
    s <= NOT b;
END structure;

ENTITY notA IS
    PORT( a: in std_logic;
        s: out std_logic);
END notA;

ARCHITECTURE structure OF notA IS
BEGIN
    s <= NOT a;
END structure;

ENTITY xorGate IS
    PORT( a, b: in std_logic;
        s: out std_logic);
END xorGate;

ARCHITECTURE structure OF xorGate IS
BEGIN
    s <= a XOR b;
END structure;

-- MUX 4 TO 1

ENTITY mux4 IS
PORT(
    andGate      : in  std_logic_vector(2 downto 0);
    orGate      : in  std_logic_vector(2 downto 0);
    sum      : in  std_logic_vector(2 downto 0);
    xorGate      : in  std_logic_vector(2 downto 0);
    operation     : in  std_logic_vector(1 downto 0);
    rslt       : out std_logic_vector(2 downto 0));
END mux4;

ARCHITECTURE rtl OF mux4 IS
BEGIN
WITH operation SELECT
        rslt <= andGate WHEN "00",
        orGate WHEN "01",
        sum WHEN "10",
        xorGate WHEN OTHERS;
end rtl;

So my question is: How can I use components and then put all these together to create a functioning 1 bit alu?所以我的问题是:如何使用组件,然后将所有这些组合在一起以创建一个功能正常的 1 位铝? Also, I am not sure about A inverter and B inverter because in the picture there are 2 mux of 2 to 1.另外,我不确定 A 逆变器和 B 逆变器,因为图中有 2 个 2 比 1 多路复用器。

Use the structure COMPONENT to add the entities you just described between the ARCHITECTURE and BEGIN keywords of your final entity.使用结构 COMPONENT 在最终实体的 ARCHITECTURE 和 BEGIN 关键字之间添加您刚刚描述的实体。

Once you've done that, you will have to bind the components between them using signals.完成此操作后,您将必须使用信号在它们之间绑定组件。 You have as much signals as wires in your provided graph.您提供的图表中的信号与电线一样多。

Here an example : https://www.doulos.com/knowhow/vhdl_designers_guide/components_and_port_maps/这里有一个例子: https : //www.doulos.com/knowhow/vhdl_designers_guide/components_and_port_maps/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM