【发布时间】: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