-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory.h
93 lines (74 loc) · 1.43 KB
/
memory.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef _MEMORY_H_
#define _MEMORY_H_
#include <memory.h>
typedef unsigned int word_t;
bool is_compile_mode();
class ram_memory
{
word_t mem[1024 * 10];
int counter;
int execution_address;
int finish;
public:
word_t get_current_address()
{
return counter;
}
word_t get()
{
word_t w;
w = mem[counter++];
return w;
}
word_t get(word_t a)
{
// Äîáàâèòü ïðîâåðêó ãðàíèö ìàññèâà
return mem[a];
}
void set(word_t addr, word_t val)
{
mem[addr] = val;
}
void put(word_t w)
{
mem[counter++] = w;
}
void jump(word_t addr)
{
counter = addr;
}
void update_execution_address()
{
execution_address = counter;
}
word_t get_execution_address()
{
return execution_address;
}
word_t get_finish()
{
return finish;
}
bool may_run()
{
bool run = (execution_address != counter) && !is_compile_mode();
finish = counter;
if (run)
counter = execution_address;
return run;
}
bool running()
{
bool run = counter != finish;
if (!run)
counter = execution_address;
return run;
}
ram_memory()
{
memset(mem, 0, sizeof(mem));
counter = 0;
execution_address = 0;
}
};
#endif