-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreg.h
executable file
·68 lines (68 loc) · 1.15 KB
/
reg.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
#include "common.h"
#define REG_SIZE 3
class reg{
private:
void init(){
vt.clear();
vt.push_back("di");
vt.push_back("bx");
vt.push_back("cx");
memset(flag, sizeof(flag), 0);
}
reg(){
init();
}
public:
vector <string> vt;
void push(){
cout << "push esi" << endl;
cout << "push edi" << endl;
cout << "push ebx" << endl;
cout << "push ecx" << endl;
}
void pop(){
cout << "pop ecx" << endl;
cout << "pop ebx" << endl;
cout << "pop edi" << endl;
cout << "pop esi" << endl;
}
bool flag[REG_SIZE];
static shared_ptr <reg> single(){
static bool flag = false;
static shared_ptr <reg> res;
if(flag)
return res;
res.reset(new reg());
flag = true;
return res;
}
string find(int i){
return vt[i];
}
string finde(int i){
string res = "e";
//string res = "e";
res += vt[i];
return res;
}
void setflag(int i){
flag[i] = true;
}
void setfree(int i){
flag[i] = false;
}
int findfree(){
for(int i = 0; i < REG_SIZE; ++i){
if(!flag[i]){
return i;
}
}
cout << "no reg free" << endl;
return -1;
}
void clear(){
//why can't memset??
for(int i = 0; i < REG_SIZE; ++i)
flag[i] = false;
}
};