【问题标题】:Creating 1-bit ALU in vhdl在 vhdl 中创建 1 位 ALU
【发布时间】:2019-09-18 00:42:47
【问题描述】:

以下问题是家庭作业。

我需要创建一个 1 位切片 ALU,它可以在两个 1 位输入之间执行以下操作: 和,或者,加法使用全加器,减法使用加法和反转输入,xor。我需要一个 4 对 1 多路复用器来在 alu 的这些功能之间进行选择。

这张图总结了我需要创建

我被要求通过分层设计(结构)来做到这一点。所以,我需要创建组件。这是整个项目的第一部分。在第二部分中,我需要使用这个 1 位 ALU 来创建一个 16 位 ALU。但我现在的问题集中在第一部分。

我创建了一个与门或门,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;

所以我的问题是:我怎样才能使用组件,然后将所有这些放在一起来创建一个功能正常的 1 位 alu?另外,我不确定 A 逆变器和 B 逆变器,因为图中有 2 个 2 对 1 的多路复用器。

【问题讨论】:

  • 如果您使用 UNSIGNED 类型,则不必实现加法器。但是您将不得不进行一些转换。但是,也许您必须这样做,因为您正在进行指导练习?
  • @AyoubBargach 教授要求制作一个用于 add 和 sub 的全加法器,并解释了如何做到这一点,因此我必须对加法器进行 impelement。

标签: vhdl hierarchical quartus


【解决方案1】:

使用结构 COMPONENT 在最终实体的 ARCHITECTURE 和 BEGIN 关键字之间添加您刚刚描述的实体。

完成此操作后,您必须使用信号在它们之间绑定组件。在您提供的图表中,您的信号与电线一样多。

这里是一个例子: https://www.doulos.com/knowhow/vhdl_designers_guide/components_and_port_maps/

【讨论】:

  • 谢谢!我要定义组件,我想我知道如何发出信号。你对 AInverter 和 BInverter 有什么建议吗,因为我不太确定。
  • 是的!我有一些 cmets:您只需执行一次逆变器。之后,只需声明两个组件“AInverter”和“BInverter”。因为它是一个练习,所以直接使用您构建的实体来完成您的全加器。祝你好运!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多