我需要创建一个 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 行:“;”附近的语法错误。