Skip to content

Commit 3cad329

Browse files
committed
init
1 parent 8c28308 commit 3cad329

File tree

123 files changed

+112721
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+112721
-0
lines changed

alu.bsf

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
WARNING: Do NOT edit the input and output ports in this file in a text
3+
editor if you plan to continue editing the block that represents it in
4+
the Block Editor! File corruption is VERY likely to occur.
5+
*/
6+
/*
7+
Copyright (C) 1991-2009 Altera Corporation
8+
Your use of Altera Corporation's design tools, logic functions
9+
and other software and tools, and its AMPP partner logic
10+
functions, and any output files from any of the foregoing
11+
(including device programming or simulation files), and any
12+
associated documentation or information are expressly subject
13+
to the terms and conditions of the Altera Program License
14+
Subscription Agreement, Altera MegaCore Function License
15+
Agreement, or other applicable license agreement, including,
16+
without limitation, that your use is for the sole purpose of
17+
programming logic devices manufactured by Altera and sold by
18+
Altera or its authorized distributors. Please refer to the
19+
applicable agreement for further details.
20+
*/
21+
(header "symbol" (version "1.1"))
22+
(symbol
23+
(rect 16 16 200 144)
24+
(text "alu" (rect 5 0 19 12)(font "Arial" ))
25+
(text "inst" (rect 8 112 25 124)(font "Arial" ))
26+
(port
27+
(pt 0 32)
28+
(input)
29+
(text "cin" (rect 0 0 14 12)(font "Arial" ))
30+
(text "cin" (rect 21 27 35 39)(font "Arial" ))
31+
(line (pt 0 32)(pt 16 32)(line_width 1))
32+
)
33+
(port
34+
(pt 0 48)
35+
(input)
36+
(text "alu_a[7..0]" (rect 0 0 51 12)(font "Arial" ))
37+
(text "alu_a[7..0]" (rect 21 43 72 55)(font "Arial" ))
38+
(line (pt 0 48)(pt 16 48)(line_width 3))
39+
)
40+
(port
41+
(pt 0 64)
42+
(input)
43+
(text "alu_b[7..0]" (rect 0 0 51 12)(font "Arial" ))
44+
(text "alu_b[7..0]" (rect 21 59 72 71)(font "Arial" ))
45+
(line (pt 0 64)(pt 16 64)(line_width 3))
46+
)
47+
(port
48+
(pt 0 80)
49+
(input)
50+
(text "alu_func[2..0]" (rect 0 0 68 12)(font "Arial" ))
51+
(text "alu_func[2..0]" (rect 21 75 89 87)(font "Arial" ))
52+
(line (pt 0 80)(pt 16 80)(line_width 3))
53+
)
54+
(port
55+
(pt 184 32)
56+
(output)
57+
(text "alu_out[7..0]" (rect 0 0 61 12)(font "Arial" ))
58+
(text "alu_out[7..0]" (rect 102 27 163 39)(font "Arial" ))
59+
(line (pt 184 32)(pt 168 32)(line_width 3))
60+
)
61+
(port
62+
(pt 184 48)
63+
(output)
64+
(text "c" (rect 0 0 5 12)(font "Arial" ))
65+
(text "c" (rect 158 43 163 55)(font "Arial" ))
66+
(line (pt 184 48)(pt 168 48)(line_width 1))
67+
)
68+
(port
69+
(pt 184 64)
70+
(output)
71+
(text "z" (rect 0 0 4 12)(font "Arial" ))
72+
(text "z" (rect 159 59 163 71)(font "Arial" ))
73+
(line (pt 184 64)(pt 168 64)(line_width 1))
74+
)
75+
(port
76+
(pt 184 80)
77+
(output)
78+
(text "v" (rect 0 0 7 12)(font "Arial" ))
79+
(text "v" (rect 156 75 163 87)(font "Arial" ))
80+
(line (pt 184 80)(pt 168 80)(line_width 1))
81+
)
82+
(port
83+
(pt 184 96)
84+
(output)
85+
(text "s" (rect 0 0 5 12)(font "Arial" ))
86+
(text "s" (rect 158 91 163 103)(font "Arial" ))
87+
(line (pt 184 96)(pt 168 96)(line_width 1))
88+
)
89+
(drawing
90+
(rectangle (rect 16 16 168 112)(line_width 1))
91+
)
92+
)

alu.vhd

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
library ieee;
2+
use ieee.std_logic_1164.all;
3+
use ieee.numeric_std.all;
4+
5+
6+
-- ALU Entity Declaration
7+
entity alu is
8+
port(
9+
cin: in std_logic; -- 进位输入
10+
alu_a, alu_b: in std_logic_vector(7 downto 0); -- ALU的两个输入
11+
alu_func: in std_logic_vector(2 downto 0); -- ALU的功能选择信号
12+
alu_out: out std_logic_vector(7 downto 0); -- ALU的输出
13+
c, z, v, s: out std_logic -- 进位、零标志、溢出标志、符号标志输出
14+
);
15+
end alu;
16+
17+
-- ALU Architecture
18+
architecture behavioral of alu is
19+
signal a_in, b_in: std_logic_vector(7 downto 0);
20+
signal c_in: std_logic;
21+
signal result_add8: std_logic_vector(7 downto 0);
22+
signal flow_temp, co_flag: std_logic;
23+
24+
component adder8bit is
25+
port(
26+
a, b: in std_logic_vector(7 downto 0);
27+
s: out std_logic_vector(7 downto 0);
28+
ci: in std_logic;
29+
c7, zero, overflow, negative: out std_logic
30+
);
31+
end component;
32+
33+
begin
34+
a_in <= alu_a;
35+
b_in <= not alu_b when alu_func = "001" else
36+
"00000001" when alu_func = "010" else
37+
"11111110" when alu_func = "011" else
38+
alu_b;
39+
40+
c_in <= '1' when alu_func = "001" else
41+
'1' when alu_func = "011" else
42+
'0';
43+
44+
f_add: adder8bit port map(
45+
a => a_in,
46+
b => b_in,
47+
s => result_add8,
48+
ci => c_in,
49+
c7 => c,
50+
zero => z,
51+
overflow => v,
52+
negative => s
53+
);
54+
55+
process(alu_func)
56+
variable f_temp: std_logic_vector(7 downto 0);
57+
begin
58+
case alu_func is
59+
when "000" =>
60+
f_temp := a_in and b_in;
61+
when "001" =>
62+
f_temp := a_in or b_in;
63+
when "010" =>
64+
f_temp := not a_in;
65+
when "011" =>
66+
f_temp := a_in xor b_in;
67+
when others =>
68+
f_temp := result_add8;
69+
end case;
70+
71+
alu_out <= f_temp;
72+
end process;
73+
end behavioral;
74+
75+
library ieee;
76+
use ieee.std_logic_1164.all;
77+
-- Adder8bit Entity Declaration
78+
entity adder8bit is
79+
port(
80+
a, b: in std_logic_vector(7 downto 0);
81+
s: out std_logic_vector(7 downto 0);
82+
ci: in std_logic;
83+
c7, zero, overflow, negative: out std_logic
84+
);
85+
end adder8bit;
86+
87+
-- Adder8bit Architecture
88+
architecture structure of adder8bit is
89+
component fa is
90+
port(
91+
a, b, ci: in std_logic;
92+
s, co: out std_logic
93+
);
94+
end component;
95+
96+
signal s_temp, c: std_logic_vector(7 downto 0);
97+
signal overflow_temp: std_logic;
98+
begin
99+
f0: fa port map(a => a(0), b => b(0), ci => ci, s => s_temp(0), co => c(0));
100+
f1_7: for i in 1 to 7 generate
101+
fm: fa port map(a => a(i), b => b(i), ci => c(i-1), s => s_temp(i), co => c(i));
102+
end generate f1_7;
103+
104+
s <= s_temp;
105+
c7 <= c(7);
106+
zero <= '1' when s_temp = "00000000" else '0';
107+
overflow_temp <= c(7) xor c(6);
108+
overflow <= '1' when overflow_temp = '1' else '0';
109+
negative <= '1' when s_temp(7) = '1' else '0';
110+
end structure;
111+
112+
library ieee;
113+
use ieee.std_logic_1164.all;
114+
-- FA Entity Declaration
115+
entity fa is
116+
port(
117+
a, b, ci: in std_logic;
118+
s, co: out std_logic
119+
);
120+
end fa;
121+
122+
-- FA Architecture
123+
architecture b_fa of fa is
124+
begin
125+
s <= a xor b xor ci;
126+
co <= ((a xor b) and ci) or (a and b);
127+
end b_fa;

alu.vhd.bak

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
library ieee;
2+
use ieee.std_logic_1164.all;
3+
use ieee.numeric_std.all;
4+
5+
6+
-- ALU Entity Declaration
7+
entity alu is
8+
port(
9+
cin: in std_logic; -- �����
10+
alu_a, alu_b: in std_logic_vector(7 downto 0); -- ALU����������
11+
alu_func: in std_logic_vector(2 downto 0); -- ALU�Ĺ���ѡ���ź�
12+
alu_out: out std_logic_vector(7 downto 0); -- ALU�����
13+
c, z, v, s: out std_logic -- ��λ�����־�������־�����ű�־���
14+
);
15+
end alu;
16+
17+
-- ALU Architecture
18+
architecture behavioral of alu is
19+
signal a_in, b_in: std_logic_vector(7 downto 0);
20+
signal c_in: std_logic;
21+
signal result_add8: std_logic_vector(7 downto 0);
22+
signal flow_temp, co_flag: std_logic;
23+
24+
component adder8bit is
25+
port(
26+
a, b: in std_logic_vector(7 downto 0);
27+
s: out std_logic_vector(7 downto 0);
28+
ci: in std_logic;
29+
c7, zero, overflow, negative: out std_logic
30+
);
31+
end component;
32+
33+
begin
34+
a_in <= alu_a;
35+
b_in <= not alu_b when alu_func = "001" else
36+
"00000001" when alu_func = "010" else
37+
"11111110" when alu_func = "011" else
38+
alu_b;
39+
40+
c_in <= '1' when alu_func = "001" else
41+
'1' when alu_func = "011" else
42+
'0';
43+
44+
f_add: adder8bit port map(
45+
a => a_in,
46+
b => b_in,
47+
s => result_add8,
48+
ci => c_in,
49+
c7 => c,
50+
zero => z,
51+
overflow => v,
52+
negative => s
53+
);
54+
55+
process(alu_func)
56+
variable f_temp: std_logic_vector(7 downto 0);
57+
begin
58+
case alu_func is
59+
when "000" =>
60+
f_temp := a_in and b_in;
61+
when "001" =>
62+
f_temp := a_in or b_in;
63+
when "010" =>
64+
f_temp := not a_in;
65+
when "011" =>
66+
f_temp := a_in xor b_in;
67+
when others =>
68+
f_temp := result_add8;
69+
end case;
70+
71+
alu_out <= f_temp;
72+
end process;
73+
end behavioral;
74+
75+
library ieee;
76+
use ieee.std_logic_1164.all;
77+
-- Adder8bit Entity Declaration
78+
entity adder8bit is
79+
port(
80+
a, b: in std_logic_vector(7 downto 0);
81+
s: out std_logic_vector(7 downto 0);
82+
ci: in std_logic;
83+
c7, zero, overflow, negative: out std_logic
84+
);
85+
end adder8bit;
86+
87+
-- Adder8bit Architecture
88+
architecture structure of adder8bit is
89+
component fa is
90+
port(
91+
a, b, ci: in std_logic;
92+
s, co: out std_logic
93+
);
94+
end component;
95+
96+
signal s_temp, c: std_logic_vector(7 downto 0);
97+
signal overflow_temp: std_logic;
98+
begin
99+
f0: fa port map(a => a(0), b => b(0), ci => ci, s => s_temp(0), co => c(0));
100+
f1_7: for i in 1 to 7 generate
101+
fm: fa port map(a => a(i), b => b(i), ci => c(i-1), s => s_temp(i), co => c(i));
102+
end generate f1_7;
103+
104+
s <= s_temp;
105+
c7 <= c(7);
106+
zero <= '1' when s_temp = "00000000" else '0';
107+
overflow_temp <= c(7) xor c(6);
108+
overflow <= '1' when overflow_temp = '1' else '0';
109+
negative <= '1' when s_temp(7) = '1' else '0';
110+
end structure;
111+
112+
-- FA Entity Declaration
113+
entity fa is
114+
port(
115+
a, b, ci: in std_logic;
116+
s, co: out std_logic
117+
);
118+
end fa;
119+
120+
-- FA Architecture
121+
architecture b_fa of fa is
122+
begin
123+
s <= a xor b xor ci;
124+
co <= ((a xor b) and ci) or (a and b);
125+
end b_fa;

0 commit comments

Comments
 (0)