[英]VHDL 32 bit ALU code
我需要創建一個 32 位 ALU,帶有 alu 函數、加法器/子、移位器和比較器。 當alu函數為0001時,進入加法器,當alu函數為0010時,進入sub,當alu函數為1001時,進入邏輯移位器左b-alu位,當alu函數為1010時,進入邏輯移位器正確的 b-alu 位等等。
我已經有了 32 位加法器/子和 32 位移位器代碼。
包 c31L_pack 是
library ieee;
use ieee.std_logic_1164.all;
package c31L_pack is
constant ZERO : std_logic_vector(31 downto 0) :=
"00000000000000000000000000000000";
constant ONES : std_logic_vector(31 downto 0) :=
"11111111111111111111111111111111";
constant BW : integer:=32;
constant SEL3 : integer:=3;
constant SEL1 : integer:=1;
constant OP : integer:=16;
constant reg_field: integer:=6;
constant immediate_size: integer:=15;
subtype alu_function_type is std_logic_vector(3 downto 0);
constant alu_nop : alu_function_type := "0000";
constant alu_add : alu_function_type := "0001";
constant alu_sub : alu_function_type := "0010";
constant alu_comp : alu_function_type := "0011";
constant alu_slt : alu_function_type := "0100";
constant alu_and : alu_function_type := "0101";
constant alu_or : alu_function_type := "0110";
constant alu_not : alu_function_type := "0111";
constant alu_xor : alu_function_type := "1000";
constant alu_shift_logic_left : alu_function_type := "1001";
constant alu_shift_logic_right : alu_function_type := "1010";
constant alu_shift_arith_left : alu_function_type := "1011";
constant alu_shift_arith_right : alu_function_type := "1100";
constant alu_mov : alu_function_type := "1101";
type mux_in_16 is array((OP-1) downto 0) of std_logic_vector(BW-1 downto 0);
type mux_in_2 is array(1 downto 0) of std_logic_vector(BW-1 downto 0);
end;
1 位:
library ieee;
use ieee.std_logic_1164.all;
entity adder1 is
port(a : in std_logic;
b : in std_logic;
cin : in std_logic;
sum_def : out std_logic;
carry_borrow : out std_logic);
end;
architecture logic of adder1 is
begin
process(a,b,cin)
begin
sum_def <=a xor b xor cin;
carry_borrow<=(a and b) or (a and cin) or (b and cin);
end process;
end architecture; --architecture logic
和 32 位加法器/子
library ieee;
use ieee.std_logic_1164.all;
use work.c31L_pack.all;
entity adder32 is
port(a3_32 : in std_logic_vector(BW-1 downto 0);
b3_32 : in std_logic_vector(BW-1 downto 0);
cin : in std_logic;
sub : in std_logic;
sum_32 : out std_logic_vector(BW-1 downto 0);
cout : inout std_logic;
ov : out std_logic);
end;
architecture logic of adder32 is
component adder1
port(a : in std_logic;
b : in std_logic;
cin : in std_logic;
sum_def : out std_logic;
carry_borrow : out std_logic);
end component;
for add1: adder1 use entity work.adder1(logic);
signal carry_i :std_logic_vector(BW-2 downto 0):=(others=>'0');
signal xor_out :std_logic_vector(BW-1 downto 0):=(others=>'0');
signal oz :std_logic;
begin
Exclusive_or:for i in BW-1 downto 0 generate
begin
xor_out(i)<=b3_32(i) xor sub after 19ns;
end generate;
add1: adder1 port map(a=>a3_32(0),b=>xor_out(0),cin=>sub,sum_def=>sum_32(0),carry_borrow=>carry_i(0));
add_2_31 : for i in 1 to BW-2 generate
add1 :adder1 port map(a=>a3_32(i),b=>xor_out(i),cin=>carry_i(i-1),sum_def=>sum_32(i),carry_borrow=>carry_i(i));
end generate;
add32: adder1 port map(a=>a3_32(BW-1),b=>xor_out(BW-1),cin=>carry_i(BW-2),sum_def=>sum_32(BW-1),carry_borrow=>cout);
oz<=carry_i(BW-2) xor cout after 19 ns;
with oz select
ov <= 'Z' when "1",
'0' when "0";
end architecture; --architecture logic
我試圖在使用函數代碼找出輸出之后得到每個結果,我遇到了很多錯誤,我試圖找到解決這個問題的方法。 我該怎么辦? 感謝你的幫助。 我只想先獲取 add 和 sub,以便我知道我應該做什么。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use work.c31L_pack.all;
ENTITY alu32 IS
GENERIC (BW : INTEGER :=32);
PORT ( a_alu32 : in STD_LOGIC_VECTOR (BW -1 downto 0);
b_alu32 : in STD_LOGIC_VECTOR (BW -1 downto 0);
alu_op : in alu_function_type ;
g : out STD_LOGIC ;
e : out STD_LOGIC ;
l : out STD_LOGIC ;
o_alu32 : out STD_LOGIC_VECTOR (BW -1 downto 0);
c_alu32 : inout STD_LOGIC ;
ov_alu32 : out STD_LOGIC );
end alu32;
architecture Behavioral of alu_32 is
component adder32
port(a3_32 : in std_logic_vector(BW-1 downto 0);-<std_logic_vector> is not declared.
b3_32 : in std_logic_vector(BW-1 downto 0);-<std_logic_vector> is not declared.
cin : in std_logic;-<std_logic> is not declared.
sub : in std_logic;-<std_logic> is not declared.
sum_32 : out std_logic_vector(BW-1 downto 0);
cout : inout std_logic;
ov : out std_logic);
end component;
signal o1:std_logic_vector(BW-1 downto 0);
signal c1:std_logic;
signal ov1:std_logic;
signal o2:std_logic_vector(BW-1 downto 0);
signal c2:std_logic;
signal ov2:std_logic;
begin
adder32 port map(a3_32=>a_alu32,b3_32=>b_alu32,cin=>"0",sub=>"1",sum_32=>o1,cout=>c1,ov=>ov1);
adder32 port map(a3_32=>a_alu32,b3_32=>b_alu32,cin=>"0",sub=>"0",sum_32=>o2,cout=>c2,ov=>ov2);
end Behavioral;
錯誤消息:ERROR:HDLCompiler:374 第 37 行:實體尚未編譯。
錯誤:HDLCompiler:69 第 40 行:未聲明。
錯誤:HDLCompiler:69 第 41 行:未聲明。
錯誤:HDLCompiler:69 第 42 行:未聲明。
錯誤:HDLCompiler:69 第 43 行:未聲明。
錯誤:HDLCompiler:69 第 45 行:未聲明。
錯誤:HDLCompiler:69 第 46 行:未聲明。
錯誤:HDLCompiler:69 第 47 行:未聲明。
錯誤:HDLCompiler:69 第 50 行:未聲明。
錯誤:HDLCompiler:69 第 51 行:未聲明。
錯誤:HDLCompiler:69 第 52 行:未聲明。
錯誤:HDLCompiler:69 第 53 行:未聲明。
錯誤:HDLCompiler:69 第 54 行:未聲明。
錯誤:HDLCompiler:69 第 55 行:未聲明。
錯誤:HDLCompiler:806 第 58 行:“端口”附近的語法錯誤。
錯誤:HDLCompiler:806 第 59 行:“;”附近的語法錯誤。
根據定義,ALU 有兩個數據輸入: a
和b
,一個功能代碼輸入,一個狀態輸出以及結果輸出。 這將導致像這樣的實體定義
entity alu is
generic
(
width : integer
);
port
(
a : in std_logic_vector(width - 1 downto 0);
b : in std_logic_vector(width - 1 downto 0);
fc : in fc_t;
status : out sc_t;
result : out std_logic_vector(width downto 0)
);
(這看起來與您的完全不同)。
除此之外,您還需要兩種枚舉類型來編碼狀態和功能代碼:
type fc_t is (fc_add, fc_add, fc_shift, fc_compare);
type sc_t is (sc_ne, sc_eq, sc_err);
我會把架構留給你(你已經擁有了大部分,你只需要把它放在正確的地方)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.