簡體   English   中英

在 vhdl 中創建 1 位 ALU

[英]Creating 1-bit ALU in vhdl

下面的問題是一個家庭作業。

我需要創建一個 1 位切片 ALU,它可以在兩個 1 位輸入之間執行以下操作:和,或者,使用全加器進行加法,使用加法和反轉輸入進行減法,異或。 我需要一個 4 比 1 的多路復用器來在 alu 的這些功能之間進行選擇。

這張圖總結了我需要創建的內容1 位鋁

我被要求使用分層設計(結構)來做到這一點。 所以,我需要創建組件。 這是整個項目的第一部分。 在第二部分中,我需要使用這個 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM