Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VHDL 32位ALU代码_Vhdl_Alu - Fatal编程技术网

VHDL 32位ALU代码

VHDL 32位ALU代码,vhdl,alu,Vhdl,Alu,我需要创建一个32位ALU,带有ALU函数、加法器/子程序、移位器和比较器。 当alu函数为0001时,它进入加法器, 当alu函数为0010时,它转到sub, 当alu函数为1001时,它转到逻辑移位器左b-alu位, 当alu函数为1010时,它进入逻辑移位器右b-alu位,依此类推 我已经有32位加法器/子和32位移位器代码 包装c31L\u包装为 library ieee; use ieee.std_logic_1164.all; package c31L_pack is consta

我需要创建一个32位ALU,带有ALU函数、加法器/子程序、移位器和比较器。 当alu函数为0001时,它进入加法器, 当alu函数为0010时,它转到sub, 当alu函数为1001时,它转到逻辑移位器左b-alu位, 当alu函数为1010时,它进入逻辑移位器右b-alu位,依此类推

我已经有32位加法器/子和32位移位器代码

包装c31L\u包装为

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
ieee库;
使用ieee.std_logic_1164.all;
实体加法器是
端口(a:标准_逻辑中;
b:标准逻辑;
cin:标准逻辑;
求和定义:输出标准逻辑;
执行(借用:执行标准逻辑);
结束;
加法器的结构逻辑是
开始
工艺(a、b、cin)
开始
总和定义为“0”);
信号oz:std_逻辑;
开始
排他_或:对于BW-1中的i,向下至0生成
开始
xor_out(i)a3_32(0),b=>xor_out(0),cin=>sub,sum_def=>sum_32(0),carry_borrow=>carry_i(0));
将1中的i添加到BW-2生成
add1:adder1端口映射(a=>a3_32(i),b=>xor_out(i),cin=>carry_i(i-1),sum_def=>sum_32(i),carry_borrow=>carry_i(i));
终端生成;
add32:adder1端口映射(a=>a3_32(BW-1),b=>xor_out(BW-1),cin=>carry_i(BW-2),sum_def=>sum_32(BW-1),carry_借入=>cout);
ozb_alu32,cin=>“0”,sub=>“1”,sum_32=>o1,cout=>c1,ov=>ov1);
adder32端口映射(a3_32=>a_alu32,b3_32=>b_alu32,cin=>0,sub=>0,sum_32=>o2,cout=>c2,ov=>ov2);
结束行为;
错误信息: 错误: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);

我将把体系结构留给您(您已经拥有了大部分体系结构,只需将其放到正确的位置即可)。

您的代码没有按照提供的方式进行分析。所选信号分配缺少其他选择,或应通过To_位(oz)select ov对其进行调节,从a中减去b将使用b的两个补码(不是b并反转LSB进位)。比较可能需要两个输出(等于和大于、等于和小于或大于和小于)。您还没有展示任何可以在加法器输出和基于操作的移位结果之间进行选择的移位。显示完整的操作集。@user1155120当前代码不工作,因此在代码检查时脱离主题。然而,一旦它起作用,OP就非常欢迎过来检查他的代码。VHDL在那里不是一个流行的标签,因此请确保问题高于平均水平,否则不会引起太多注意。缺少包c31L_包,(BW,alu_函数_类型)并发语句(生成)不会出现在所选信号分配语句的波形中。加法器32实际上看起来很实用。alu_32的体系结构主体是完全错误的。您只需要一个加法器,用case语句或选定的信号分配控制它的输入,反转b和进位进行减法运算。另请参见。您发布的错误消息是无用的,因为您没有指定它们出现在哪个发布的代码块中。要实现ALU,您应该首先绘制它的框图。这将包括所有子组件、输出多路复用器以及它们之间的连接。然后用VHDL编写代码。
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);