-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassembly_functions.h
117 lines (81 loc) · 1.8 KB
/
assembly_functions.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include"support_functions.h"
void mov(int to, int from){
reg[to]=reg[from];
reg[pc]=reg[pc]+1;
}
void movv(int to,int from){
//printf("reg name = %s , address = %d\n",reg_names[to],from);
reg[to]=from;
reg[pc]=reg[pc]+1;
}
void load(int to,int from){
reg[to]=char_toint(memory[from]);
reg[pc]=reg[pc]+1;
}
void loadr(int to,int from){
reg[to]=char_toint(memory[reg[from]]);
reg[pc]=reg[pc]+1;
}
void store(int to,int from){
strcpy(memory[to],int_Tochar(reg[from]));
reg[pc]=reg[pc]+1;
}
void storer(int to,int from){
strcpy(memory[reg[to]],int_Tochar(reg[from]));
reg[pc]=reg[pc]+1;
}
void add(int reg1,int reg2){
reg[acc]=reg[reg1]+reg[reg2];
reg[pc]=reg[pc]+1;
}
void sub(int reg1,int reg2){
reg[acc]=reg[reg1]-reg[reg2];
reg[pc]=reg[pc]+1;
}
void mod(int reg1,int reg2){
reg[acc]=reg[reg1] % reg[reg2];
reg[pc]=reg[pc]+1;
}
void call(int address){
reg[sp]=reg[sp]+1;
strcpy(memory[reg[sp]],int_Tochar(reg[pc]+1));
reg[pc]=address;
}
void ret(){
reg[pc]=char_toint(memory[reg[sp]]);
reg[sp]=reg[sp]-1;
}
void out(int reg1){
//printf("%s = %d\n",reg_names[reg1],reg[reg1]);
printf("%d\n",reg[reg1]);
reg[pc]=reg[pc]+1;
}
void push(int reg1){
reg[sp]=reg[sp]+1;
strcpy(memory[reg[sp]],int_Tochar(reg[reg1]));
reg[pc]=reg[pc]+1;
}
void pop(int reg1){
reg[reg1]=char_toint(memory[reg[sp]]);
reg[sp]=reg[sp]-1;
reg[pc]=reg[pc]+1;
}
void jmp(int address){
reg[pc]=address;
}
void jnz(int address,int reg1){
if (reg[reg1]!=0){
reg[pc]=address;
}
else{
reg[pc]=reg[pc]+1;
}
}
void holt(){ // ---> holt = halt (conflict -> halt function & halt reg enum )...
reg[halt]=1;
reg[pc]=reg[pc]+1;
}
void print(char* word){
printf("%s",word);
reg[pc] = reg[pc]+1;
}