-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathram.vhd
More file actions
65 lines (60 loc) · 2.93 KB
/
ram.vhd
File metadata and controls
65 lines (60 loc) · 2.93 KB
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
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
entity ram is
port (
r_w, en, reset: in STD_LOGIC; --en是总线请求信号,1表示允许,0表示忙
aBus: in STD_LOGIC_VECTOR(7 downto 0); ----数据总线输入
dBus: inout STD_LOGIC_VECTOR(7 downto 0)
);
end ram;
architecture ramArch of ram is
type ram_typ is array(0 to 63) of STD_LOGIC_VECTOR(7 downto 0);
signal ram: ram_typ;
begin
process(
en, reset, r_w, aBus, dBus
) begin
-- 当reset信号为'1'时,存储器的前9个单元会被初始化为指定的值。这些值是用16进制表示的8位数据。
if reset = '1' then
-- ram(0) <= x"14";
-- ram(1) <= x"30";
-- ram(2) <= x"25";
-- ram(3) <= x"15";
-- ram(4) <= x"46";
-- ram(5) <= x"31";
-- ram(6) <= x"55";
-- ram(7) <= x"06";
-- ram(8) <= x"01";
ram(0) <= x"05"; -- LOAD 5 (加载23到累加器)
ram(1) <= x"26"; -- ADD 6 (将47加到累加器)
ram(2) <= x"37"; -- SUB 7(将累加器中的内容减去58)
ram(3) <= x"18"; -- STORE 8 (将结果存储到地址8的存储单元)
ram(4) <= x"B1"; -- HALT(停机指令)
ram(5) <= x"17"; -- 存放23的十六进制表示
ram(6) <= x"2F"; -- 存放47的十六进制表示
ram(7) <= x"3A"; -- 存放58的十六进制表示
ram(8) <= x"00"; -- 用于存放计算结果
-- -- 实现计算 [(25 + 37) * 68 - 22 ] / 34
-- ram(0) <= x"07"; -- LOAD 7, 将地址7的内容25加载到累加器
-- ram(1) <= x"28"; -- ADD 8, 将地址8的内容37加到累加器
-- ram(2) <= x"49"; -- MUL 9, 将累加器的内容和地址9的内容68相乘,低4位存储到累加器中
-- ram(3) <= x"3A"; -- SUB 10,将累加器的内容减去地址10的内容22
-- ram(4) <= x"5B"; -- DIV 11, 将累加器的内容除以地址11的内容34
-- ram(5) <= x"1C"; -- STORE 12,将累加器的内容存储到地址12的单元中
-- ram(6) <= x"B1"; -- HALT,停机
-- ram(7) <= x"19"; -- 存放数据,25的十六进制表示
-- ram(8) <= x"25"; -- 存放数据,37的十六进制表示
-- ram(9) <= x"44"; -- 存放数据,68的十六进制表示
-- ram(10) <= x"16"; -- 存放数据,22的十六进制表示
-- ram(11) <= x"22"; -- 存放数据,34的十六进制表示
-- ram(12) <= x"00"; -- 存放计算结果
elsif r_w = '0' then --写操作,将数据总线上的信号传输到地址总线上
ram(conv_integer(unsigned(aBus))) <= dBus;
end if;
end process;
dBus <= ram(conv_integer(unsigned(aBus))) -- 读操作,将地址总线上的信号传输到数据总线上
when reset = '0' and en = '1' and r_w = '1' else -- 将存储器中指定地址的数据输出到数据总线dBus
"ZZZZZZZZ"; -- 如果不满足这些条件,则dBus被设置为高阻态("ZZZZZZZZ"),表示数据总线处于未驱动状态。
end ramArch;
--支持读写操作和复位功能。存储器的大小为64个8位单元,通过地址总线aBus访问。数据通过数据总线dBus进行输入和输出。