- 实验题目
1.四位并行加法器的设计及仿真
2.16位ALU的设计及仿真
- 实验目的
1.熟悉quartus的使用方法;
2.掌握全加器的特点及设计方法;
3.掌握串行进位链的并行加法器的设计方法;
4.熟悉VHDL模块化设计方法;
5.熟悉ALU的设计方法。
- 实验要求
1. 基于QuartusⅡ,设计实现一位全加器。
2. 利用VHDL模块化设计方法,以设计完成的一位全加器为基础,设计实现4位并行加法器,QuartusⅡ下编译并仿真。。
3. 设计实现能完成8种算术运算和8逻辑运算的16位ALU,要求:
(1)具有4位的功能选择端,其中的1位用来选择算术运算/逻辑运算,其余3位具体 给出是哪一种算术/逻辑运算。8种算术运算中必须包含加法、减法、加1、减1四种运算,其余自定。8种逻辑运算必须有与、或、非和传递四种运算,其余自定。固定的8种运算功能如表1所示。
表1 运算类型及操作列表
运 算 | 操 作 | 对标识位Z和C的影响 |
加 法 | result ←A+B | 影响标志位Z和C |
减 法 | result ←A-B | 影响标志位Z和C |
加 1 | result ←A+1 | 影响标志位Z和C |
减 1 | result ←A-1 | 影响标志位Z和C |
与 | result←A and B | 影响标志位Z |
或 | result←A or B | 影响标志位Z |
非 | result← not B | 影响标志位Z |
传 递 | result←B | 不影响标志位Z和C |
其中,A、B是参与运算的两个16位操作数,result是运算结果(16位),Z是零标志位,当运算结果result=“0000000000000000”时,Z=‘1’,否则Z=‘0’。 C为进位标志位,当运算结果向高位(第16位)有进位时,C=‘1’,否则C=‘0’。
(2)用VHDL编程实现,QuartusⅡ下编译并仿真。
四位并行加法器代码实现:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36--------一位加法器 library ieee; use ieee.std_logic_1164.all; entity adder is port( A,B,C: in std_logic; S,CO: out std_logic ); end adder; architecture isadder of adder is begin S <= A xor B xor C; CO <= (A and C) or (B and C) or (A and B); end isadder; --------四位加法器 library ieee; use ieee.std_logic_1164.all; entity adder_4 is port( A,B: in std_logic_vector(3 downto 0); CI: in std_logic; S: out std_logic_vector(3 downto 0); CO: out std_logic ); end adder_4; architecture isadder_4 of adder_4 is component adder port( A,B,C: in std_logic; S,CO: out std_logic ); end component; signal temp: std_logic_vector(4 downto 0); begin temp(0) <= CI; CO <= temp(4); G: for I in 0 to 3 generate U: adder port map(A=>A(I),B=>B(I),C=>TEMP(I),S=>S(I),CO=>temp(I+1)); end generate; end isadder_4;
16位ALU代码实现:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity alu is port( a,b: in std_logic_vector(15 downto 0); --a,b是两个操作数 sel: in std_logic_vector(3 downto 0); --sel是选择控制端(选择某种运算,最高位是为了选择逻辑运算或者算术运算) cin: in std_logic; --cin是原来的进位值 q: out std_logic_vector(15 downto 0); --q是运算结果 cout: out std_logic ); --cout是运算后的进位值 end alu; architecture isalu of alu is signal result:std_logic_vector(16 downto 0); begin process(a,b,sel,cin,result) begin if sel(3)='0' then --当sel的最高位是0则选择算术运算 case sel(2 downto 0) is when "000" => --加法 result <= ('0'&a)+('0'&b); q <= result(15 downto 0); cout <= result(16); when "001" => --减法 result <= ('0'&a)-('0'&b); q <= result(15 downto 0); cout <= result(16); when "010" => --a+1 result <= ('0'&a)+"00000000000000001"; q <= result(15 downto 0); cout <= result(16); when "011" => --a-1 result <= ('0'&a)-"00000000000000001"; q <= result(15 downto 0); cout <= result(16); when "100" => --b+2 result <= ('0'&b)+"00000000000000010"; q <= result(15 downto 0); cout <= result(16); when "101" => --b-2 result <= ('0'&b)-"00000000000000010"; q <= result(15 downto 0); cout <= result(16); when "110" => --a+3 result <= ('0'&a)+"00000000000000011"; q <= result(15 downto 0); cout <= result(16); when "111" => --a-3 result <= ('0'&a)-"00000000000000011"; q <= result(15 downto 0); cout <= result(16); end case; else --否则选择逻辑运算 case sel(2 downto 0) is when "000" => --与 q <= a and b; cout <= cin; when "001" => --或 q <= a or b; cout <= cin; when "010" => --非 q <= not a; when "011" => --传递 q <= a; cout <= cin; when "100" => --与非 q <= a nand b; cout <= cin; when "101" => --或非 q <= a nor b; cout <= cin; when "110" => --异或 q <= a xor b; cout <= cin; when "111" => --同或 q <= a xnor b; cout <= cin; end case; end if; end process; end isalu;
以上就是我给大家分享的全部内容啦!
最后
以上就是无奈板凳最近收集整理的关于VHDL:设计一个四位并行加法器和16位ALU(代码思路清晰易懂)四位并行加法器代码实现:16位ALU代码实现:的全部内容,更多相关VHDL内容请搜索靠谱客的其他文章。
发表评论 取消回复