[英]Creating 1-bit ALU in vhdl
下面的问题是一个家庭作业。
我需要创建一个 1 位切片 ALU,它可以在两个 1 位输入之间执行以下操作:和,或者,使用全加器进行加法,使用加法和反转输入进行减法,异或。 我需要一个 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 位铝? 另外,我不确定 A 逆变器和 B 逆变器,因为图中有 2 个 2 比 1 多路复用器。
使用结构 COMPONENT 在最终实体的 ARCHITECTURE 和 BEGIN 关键字之间添加您刚刚描述的实体。
完成此操作后,您将必须使用信号在它们之间绑定组件。 您提供的图表中的信号与电线一样多。
这里有一个例子: https : //www.doulos.com/knowhow/vhdl_designers_guide/components_and_port_maps/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.