Browse Source

OK a tester

Paul Faure 2 years ago
parent
commit
78216ace0a
5 changed files with 242 additions and 88 deletions
  1. 4
    5
      al.lex
  2. 63
    64
      as.y
  3. 127
    11
      tables.c
  4. 10
    3
      tables.h
  5. 38
    5
      toto.asm

+ 4
- 5
al.lex View File

@@ -13,7 +13,7 @@ yyerror (char const *s)
13 13
 %%
14 14
 
15 15
 "ADD"     { return tADD ;} 
16
-"SUB"     { return tSUB;}
16
+"SOU"     { return tSUB;}
17 17
 "MUL"     { return tMUL; }
18 18
 "DIV"			{ return tDIV; }
19 19
 "INF"			{ return tINF; }
@@ -23,7 +23,6 @@ yyerror (char const *s)
23 23
 "AFC"    	{ return tAFC; }
24 24
 "COP"     { return tCPY; }
25 25
 "AFCA"    { return tAFCA; }
26
-"COPA"    { return tCPYA; }
27 26
 
28 27
 
29 28
 "READ"    { return tREAD; }
@@ -42,9 +41,9 @@ yyerror (char const *s)
42 41
 
43 42
 [0-9]+	  { yylval.nombre = atoi(yytext); return tNB; }
44 43
 
45
-"\n"
46
-" "
47
-"\t"
44
+"\n"	{}
45
+" "		{}
46
+"\t"	{}
48 47
 
49 48
 %%
50 49
 

+ 63
- 64
as.y View File

@@ -6,11 +6,12 @@
6 6
 #include <stdio.h> 
7 7
 
8 8
 FILE * file;
9
+FILE * file2;
9 10
 
10 11
 %}
11 12
 
12 13
 %token tMUL tDIV tADD tSUB tINF tSUP tEQU
13
-%token tAFC tCPY tAFCA tCPYA
14
+%token tAFC tCPY tAFCA
14 15
 %token tREAD tWR
15 16
 %token tJMP tJMF
16 17
 %token tGET tPRI
@@ -25,134 +26,132 @@ Programme : Instruction;
25 26
 
26 27
 Instruction : tMUL tNB tNB tNB {increment_time();
27 28
 																int added_instruction = 0;
28
-																int reg_dest = get_reg_write($2, file, &added_instruction);
29
-																int reg_src1 = get_reg_read($3, file, &added_instruction);
30
-																int reg_src2 = get_reg_read($4, file, &added_instruction);
31
-																fprintf(file, "MUL %d %d %d\n", reg_dest, reg_src1, reg_src2);
29
+																int reg_dest = get_reg_write($2, &added_instruction);
30
+																int reg_src1 = get_reg_read($3, &added_instruction);
31
+																int reg_src2 = get_reg_read($4, &added_instruction);
32
+																add_instruction(MUL, reg_dest, reg_src1, reg_src2);
32 33
 																new_instruction(added_instruction + 1);};
33 34
 Instruction : tADD tNB tNB tNB {increment_time();
34 35
 																int added_instruction = 0;
35
-																int reg_dest = get_reg_write($2, file, &added_instruction);
36
-																int reg_src1 = get_reg_read($3, file, &added_instruction);
37
-																int reg_src2 = get_reg_read($4, file, &added_instruction);
38
-																fprintf(file, "ADD %d %d %d\n", reg_dest, reg_src1, reg_src2);
36
+																int reg_dest = get_reg_write($2, &added_instruction);
37
+																int reg_src1 = get_reg_read($3, &added_instruction);
38
+																int reg_src2 = get_reg_read($4, &added_instruction);
39
+																add_instruction(ADD, reg_dest, reg_src1, reg_src2);
39 40
 																new_instruction(added_instruction + 1);};
40 41
 Instruction : tDIV tNB tNB tNB {increment_time();
41 42
 																int added_instruction = 0;
42
-																int reg_dest = get_reg_write($2, file, &added_instruction);
43
-																int reg_src1 = get_reg_read($3, file, &added_instruction);
44
-																int reg_src2 = get_reg_read($4, file, &added_instruction);
45
-																fprintf(file, "DIV %d %d %d\n", reg_dest, reg_src1, reg_src2);
43
+																int reg_dest = get_reg_write($2, &added_instruction);
44
+																int reg_src1 = get_reg_read($3, &added_instruction);
45
+																int reg_src2 = get_reg_read($4, &added_instruction);
46
+																add_instruction(DIV, reg_dest, reg_src1, reg_src2);
46 47
 																new_instruction(added_instruction + 1);};
47 48
 Instruction : tSUB tNB tNB tNB {increment_time();
48 49
 																int added_instruction = 0;
49
-																int reg_dest = get_reg_write($2, file, &added_instruction);
50
-																int reg_src1 = get_reg_read($3, file, &added_instruction);
51
-																int reg_src2 = get_reg_read($4, file, &added_instruction);
52
-																fprintf(file, "SUB %d %d %d\n", reg_dest, reg_src1, reg_src2);
50
+																int reg_dest = get_reg_write($2, &added_instruction);
51
+																int reg_src1 = get_reg_read($3, &added_instruction);
52
+																int reg_src2 = get_reg_read($4, &added_instruction);
53
+																add_instruction(SUB, reg_dest, reg_src1, reg_src2);
53 54
 																new_instruction(added_instruction + 1);};
54 55
 Instruction : tINF tNB tNB tNB {increment_time();
55 56
 																int added_instruction = 0;
56
-																int reg_dest = get_reg_write($2, file, &added_instruction);
57
-																int reg_src1 = get_reg_read($3, file, &added_instruction);
58
-																int reg_src2 = get_reg_read($4, file, &added_instruction);
59
-																fprintf(file, "INF %d %d %d\n", reg_dest, reg_src1, reg_src2);
57
+																int reg_dest = get_reg_write($2, &added_instruction);
58
+																int reg_src1 = get_reg_read($3, &added_instruction);
59
+																int reg_src2 = get_reg_read($4, &added_instruction);
60
+																add_instruction(INF, reg_dest, reg_src1, reg_src2);
60 61
 																new_instruction(added_instruction + 1);};
61 62
 Instruction : tSUP tNB tNB tNB {increment_time();
62 63
 																int added_instruction = 0;
63
-																int reg_dest = get_reg_write($2, file, &added_instruction);
64
-																int reg_src1 = get_reg_read($3, file, &added_instruction);
65
-																int reg_src2 = get_reg_read($4, file, &added_instruction);
66
-																fprintf(file, "SUP %d %d %d\n", reg_dest, reg_src1, reg_src2);
64
+																int reg_dest = get_reg_write($2, &added_instruction);
65
+																int reg_src1 = get_reg_read($3, &added_instruction);
66
+																int reg_src2 = get_reg_read($4, &added_instruction);
67
+																add_instruction(SUP, reg_dest, reg_src1, reg_src2);
67 68
 																new_instruction(added_instruction + 1);};
68 69
 Instruction : tEQU tNB tNB tNB {increment_time();
69 70
 																int added_instruction = 0;
70
-																int reg_dest = get_reg_write($2, file, &added_instruction);
71
-																int reg_src1 = get_reg_read($3, file, &added_instruction);
72
-																int reg_src2 = get_reg_read($4, file, &added_instruction);
73
-																fprintf(file, "EQU %d %d %d\n", reg_dest, reg_src1, reg_src2);
71
+																int reg_dest = get_reg_write($2, &added_instruction);
72
+																int reg_src1 = get_reg_read($3, &added_instruction);
73
+																int reg_src2 = get_reg_read($4, &added_instruction);
74
+																add_instruction(EQU, reg_dest, reg_src1, reg_src2);
74 75
 																new_instruction(added_instruction + 1);};
75 76
 
76 77
 
77 78
 Instruction : tAFC tNB tNB     {increment_time();
78 79
 																int added_instruction = 0;
79
-																int reg_dest = get_reg_write($2, file, &added_instruction);
80
-															  fprintf(file, "AFC %d %d\n", reg_dest, $3);
80
+																int reg_dest = get_reg_write($2, &added_instruction);
81
+																add_instruction(AFC, reg_dest, $3, 0);
81 82
 																new_instruction(added_instruction + 1);};
82 83
 Instruction : tCPY tNB tNB     {increment_time();
83 84
 																int added_instruction = 0;
84
-																int reg_dest = get_reg_write($2, file, &added_instruction);
85
-																int reg_src = get_reg_read($3, file, &added_instruction);
86
-																fprintf(file, "CPY %d %d\n", reg_dest, reg_src);
85
+																int reg_dest = get_reg_write($2, &added_instruction);
86
+																int reg_src = get_reg_read($3, &added_instruction);
87
+																add_instruction(CPY, reg_dest, reg_src, 0);
87 88
 																new_instruction(added_instruction + 1);};
88 89
 Instruction : tAFCA tNB tNB     {increment_time();
89 90
 																int added_instruction = 0;
90
-																int reg_dest = get_reg_write($2, file, &added_instruction);
91
-															  fprintf(file, "AFCA %d %d\n", reg_dest, $3);
92
-																new_instruction(added_instruction + 1);};
93
-Instruction : tCPYA tNB tNB     {increment_time();
94
-																int added_instruction = 0;
95
-																int reg_dest = get_reg_write($2, file, &added_instruction);
96
-																int reg_src = get_reg_read($3, file, &added_instruction);
97
-																fprintf(file, "CPYA %d %d\n", reg_dest, reg_src);
98
-																new_instruction(added_instruction + 1);};
91
+																int reg_aux = get_reg_write(-1, &added_instruction);
92
+																add_instruction(AFC, reg_aux, $3, 0);
93
+																add_instruction(STOREA, $2, reg_aux, 0);
94
+																new_instruction(added_instruction + 2);};
99 95
 
100 96
 
101 97
 Instruction : tJMP tNB         {increment_time();
102
-																fprintf(file, "JMP %d\n", $2);
98
+																add_instruction(JMP, $2, 0, 0);
103 99
 																new_instruction(1);};
104 100
 Instruction : tJMF tNB tNB     {increment_time();
105 101
 																int added_instruction = 0;
106
-																int reg_src = get_reg_read($2, file, &added_instruction);
107
-																int reg_aux = get_reg_write(-1, file, &added_instruction);
108
-																fprintf(file, "SUB %d %d %d\n", reg_aux, reg_aux, reg_src);
109
-																fprintf(file, "JMZ %d\n", $3);
102
+																int reg_src = get_reg_read($2, &added_instruction);
103
+																int reg_aux = get_reg_write(-1, &added_instruction);
104
+																add_instruction(SUB, reg_aux, reg_aux, reg_src);
105
+																add_instruction(JMZ, $3, 0, 0);
110 106
 																new_instruction(added_instruction + 2);};
111 107
 
112 108
 Instruction : tWR tNB tNB      {increment_time();
113 109
 																int added_instruction = 0;
114
-																int reg_dest = get_reg_write($2, file, &added_instruction);
115
-																int reg_addr = get_reg_read($3, file, &added_instruction);
116
-																fprintf(file, "LOADA %d %d\n", reg_dest, reg_addr);
110
+																int reg_dest = get_reg_write($2, &added_instruction);
111
+																int reg_addr = get_reg_read($3, &added_instruction);
112
+																add_instruction(LOADI, reg_dest, reg_addr, 0);
117 113
 																new_instruction(added_instruction + 1);};
118 114
 Instruction : tREAD tNB tNB    {increment_time();
119 115
 																int added_instruction = 0;
120
-																int reg_addr = get_reg_read($2, file, &added_instruction);
121
-																int reg_value = get_reg_read($3, file, &added_instruction);
122
-																fprintf(file, "STOREA %d %d\n", reg_addr, reg_value);
116
+																int reg_addr = get_reg_read($2, &added_instruction);
117
+																int reg_value = get_reg_read($3, &added_instruction);
118
+																add_instruction(STOREI, reg_addr, reg_value, 0);
123 119
 																new_instruction(added_instruction + 1);};
124 120
 
125 121
 
126 122
 Instruction : tGET tNB         {increment_time();
127 123
 																int added_instruction = 0;
128
-																int reg_dest = get_reg_write($2, file, &added_instruction);
129
-																fprintf(file, "GET %d\n", reg_dest);
124
+																int reg_dest = get_reg_write($2, &added_instruction);
125
+																add_instruction(GET, reg_dest, 0, 0);
130 126
 																new_instruction(added_instruction + 1);};
131 127
 Instruction : tPRI tNB         {increment_time();
132 128
 																int added_instruction = 0;
133
-																int reg_src = get_reg_read($2, file, &added_instruction);
134
-																fprintf(file, "PRI %d\n", reg_src);
129
+																int reg_src = get_reg_read($2, &added_instruction);
130
+																add_instruction(PRI, reg_src, 0, 0);
135 131
 																new_instruction(added_instruction + 1);};
136 132
 
137 133
 
138 134
 Instruction : tCALL tNB tNB    {increment_time();
139 135
 																int added_instruction = flush_and_init(file);
140
-																fprintf(file, "CALL %d %d\n", $2, $3);
136
+																add_instruction(STOP, $2, $3, 0);
141 137
 																new_instruction(added_instruction + 1);};
142 138
 Instruction : tRET             {increment_time();
143 139
 																int added_instruction = flush_and_init(file);
144
-																fprintf(file, "RET\n");
140
+																add_instruction(RET, 0, 0, 0);
145 141
 																new_instruction(added_instruction + 1);};
146 142
 
147
-Instruction : tSTOP             {increment_time();
148
-																fprintf(file, "STOP\n");
143
+Instruction : tSTOP tNB         {increment_time();
144
+																add_instruction(STOP, $2, 0, 0);
149 145
 																new_instruction(1);};
150 146
 
151 147
 %%
152 148
 
153 149
 int main(void) {
154
-	file = stdout;
155
-    init();
150
+	file = fopen("output.asm", "w");
151
+	file2 = fopen("output.bin", "w");
152
+  init();
156 153
 	yyparse();
154
+	write_asm(file);
155
+	write_code_machine(file2);
157 156
 	return 0;
158 157
 }

+ 127
- 11
tables.c View File

@@ -13,9 +13,122 @@
13 13
 
14 14
 #include "tables.h"
15 15
 #define NB_REG 4
16
-#define MEM_SIZE 1024
17
-#define NB_INSTRUCTIONS 1024
16
+#define MEM_SIZE 16
17
+#define NB_INSTRUCTIONS 64
18
+#define MEM_INST_SIZE 64
19
+#define NB_BITS_INSTRUCTION 5
20
+#define NB_BITS 8
18 21
 
22
+int traduction_JMP[NB_INSTRUCTIONS];
23
+
24
+struct str_instruction {
25
+	enum instruction_t instruction;
26
+	int param1;
27
+	int param2;
28
+	int param3;
29
+};
30
+
31
+int last_instruction = 0;
32
+struct str_instruction buffer[3*NB_INSTRUCTIONS];
33
+
34
+void add_instruction(enum instruction_t inst, int param1, int param2, int param3) {
35
+	struct str_instruction my_instruction = {inst, param1, param2, param3};
36
+	buffer[last_instruction] = my_instruction;
37
+	last_instruction++;
38
+}
39
+
40
+void write_asm(FILE * file) {
41
+	int i = 0;
42
+	while (i<MEM_INST_SIZE) {
43
+		if (buffer[i].instruction == ADD) {
44
+			fprintf(file, "ADD %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
45
+		} else if (buffer[i].instruction == SUB) {
46
+			fprintf(file, "SUB %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
47
+		} else if (buffer[i].instruction == MUL) {
48
+			fprintf(file, "MUL %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
49
+		} else if (buffer[i].instruction == DIV) {
50
+			fprintf(file, "DIV %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
51
+		} else if (buffer[i].instruction == INF) {
52
+			fprintf(file, "INF %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
53
+		} else if (buffer[i].instruction == SUP) {
54
+			fprintf(file, "SUP %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
55
+		} else if (buffer[i].instruction == EQU) {
56
+			fprintf(file, "EQU %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
57
+
58
+		} else if (buffer[i].instruction == AFC) {
59
+			fprintf(file, "AFC %d %d\n", buffer[i].param1, buffer[i].param2);
60
+		} else if (buffer[i].instruction == CPY) {
61
+			fprintf(file, "CPY %d %d\n", buffer[i].param1, buffer[i].param2);
62
+
63
+		} else if (buffer[i].instruction == LOAD) {
64
+			fprintf(file, "LOAD %d %d\n", buffer[i].param1, buffer[i].param2);
65
+		} else if (buffer[i].instruction == STORE) {
66
+			fprintf(file, "STORE %d %d\n", buffer[i].param1, buffer[i].param2);
67
+		} else if (buffer[i].instruction == LOADI) {
68
+			fprintf(file, "LOADI %d %d\n", buffer[i].param1, buffer[i].param2);
69
+		} else if (buffer[i].instruction == STOREI) {
70
+			fprintf(file, "STOREI %d %d\n", buffer[i].param1, buffer[i].param2);
71
+		} else if (buffer[i].instruction == STOREA) {
72
+			fprintf(file, "STOREA %d %d\n", buffer[i].param1, buffer[i].param2);
73
+
74
+		} else if (buffer[i].instruction == JMP) {
75
+			fprintf(file, "JMP %d\n", traduction_JMP[buffer[i].param1]);
76
+		} else if (buffer[i].instruction == JMZ) {
77
+			fprintf(file, "JMZ %d\n", traduction_JMP[buffer[i].param1]);
78
+		} else if (buffer[i].instruction == GET) {
79
+			fprintf(file, "GET %d\n", buffer[i].param1);
80
+		} else if (buffer[i].instruction == PRI) {
81
+			fprintf(file, "PRI %d\n", buffer[i].param1);
82
+
83
+		} else if (buffer[i].instruction == CALL) {
84
+			fprintf(file, "CALL %d %d\n", traduction_JMP[buffer[i].param1], buffer[i].param2);
85
+		} else if (buffer[i].instruction == RET) {
86
+			fprintf(file, "RET\n");
87
+		} else if (buffer[i].instruction == STOP) {
88
+			fprintf(file, "STOP %d\n", buffer[i].param1);
89
+		} 
90
+		i++;
91
+	}
92
+}
93
+
94
+void int_2_bin(char * buff, int n) {
95
+	int _m = n; 
96
+	for (int i = 0; i < 32; i++) { 
97
+		buff[31 - i] = ((_m & (1 << 31)) ? '1' : '0'); 
98
+		_m = _m << 1; 
99
+	} 
100
+}
101
+
102
+void convert_to_binary_on_N(int value, int N, char * buff) {
103
+	char tampon[33];
104
+	int_2_bin(tampon, value);
105
+	int i;
106
+	for (i = N-1; i>=0; i--) {
107
+		buff[N-1-i] = tampon[i];
108
+	}
109
+	buff[N] = '\0';
110
+}
111
+
112
+void write_instruction_binary(FILE * file, struct str_instruction instr) {
113
+	char buff1[33];
114
+	char buff2[33];
115
+	char buff3[33];
116
+	char buff4[33];
117
+	convert_to_binary_on_N(instr.instruction, NB_BITS_INSTRUCTION, buff1);
118
+	convert_to_binary_on_N(instr.param1, NB_BITS, buff2);
119
+	convert_to_binary_on_N(instr.param2, NB_BITS, buff3);
120
+	convert_to_binary_on_N(instr.param3, NB_BITS, buff4);
121
+	fprintf(file, "\"%s%s%s%s\" & ", buff1, buff2, buff3, buff4);
122
+}
123
+
124
+
125
+void write_code_machine(FILE * file) {
126
+	int i = MEM_INST_SIZE - 1;
127
+	while (i>=0) {
128
+		write_instruction_binary(file, buffer[i]);
129
+		i--;
130
+	}
131
+}
19 132
 
20 133
 
21 134
 struct case_adresse {
@@ -26,7 +139,6 @@ struct case_adresse {
26 139
 
27 140
 struct case_adresse tableau[MEM_SIZE];
28 141
 int registres[NB_REG];
29
-int traduction_JMP[NB_INSTRUCTIONS];
30 142
 
31 143
 void init (void) {
32 144
   int i;
@@ -38,6 +150,10 @@ void init (void) {
38 150
 	for (i=0; i<NB_REG; i++) {
39 151
 		registres[i] = 0;
40 152
 	}	
153
+	struct str_instruction nop = {NOP, 0, 0, 0};
154
+	for (i=0; i<MEM_INST_SIZE; i++) {
155
+		buffer[i] = nop;
156
+	}
41 157
 }
42 158
 
43 159
 void print_case_adresse(struct case_adresse case_courante) {
@@ -98,14 +214,14 @@ int get_register() {
98 214
 	return index_max;
99 215
 }
100 216
 
101
-int get_reg_write(int adresse, FILE * file, int * added_instruction) {
217
+int get_reg_write(int adresse, int * added_instruction) {
102 218
 	if (adresse == -1) {
103 219
 		int dispo = get_register();
104 220
 		int previous_addr = get_adresse(dispo);
105 221
 		if (previous_addr != -1) {
106 222
 			struct case_adresse ancienne_case = get_info(previous_addr);
107 223
 			if (ancienne_case.modifie == 1) {
108
-				fprintf(file, "STORE %d %d\n", previous_addr, dispo);
224
+				add_instruction(STORE, previous_addr, dispo, 0);
109 225
 				*added_instruction = (*added_instruction) + 1;
110 226
 				set_modifie(previous_addr, 0);
111 227
 			}
@@ -122,7 +238,7 @@ int get_reg_write(int adresse, FILE * file, int * added_instruction) {
122 238
 				struct case_adresse ancienne_case = get_info(previous_addr);
123 239
 				if (ancienne_case.modifie == 1) {
124 240
 					*added_instruction = (*added_instruction) + 1;
125
-					fprintf(file, "STORE %d %d\n", previous_addr, dispo);
241
+					add_instruction(STORE, previous_addr, dispo, 0);
126 242
 					set_modifie(previous_addr, 0);
127 243
 				}
128 244
 				set_registre(previous_addr, -1);
@@ -137,7 +253,7 @@ int get_reg_write(int adresse, FILE * file, int * added_instruction) {
137 253
 	}
138 254
 }
139 255
 
140
-int get_reg_read(int adresse, FILE * file, int * added_instruction) {
256
+int get_reg_read(int adresse, int * added_instruction) {
141 257
 	struct case_adresse ma_case = get_info(adresse);
142 258
 	if (ma_case.registre == -1) {
143 259
 		int dispo = get_register();
@@ -146,13 +262,13 @@ int get_reg_read(int adresse, FILE * file, int * added_instruction) {
146 262
 			struct case_adresse ancienne_case = get_info(previous_addr);
147 263
 			if (ancienne_case.modifie == 1) {
148 264
 				*added_instruction = (*added_instruction) + 1;
149
-				fprintf(file, "STORE %d %d\n", previous_addr, dispo);
265
+				add_instruction(STORE, previous_addr, dispo, 0);
150 266
 				set_modifie(previous_addr, 0);
151 267
 			}
152 268
 			set_registre(previous_addr, -1);
153 269
 		}
154 270
 		*added_instruction = (*added_instruction) + 1;
155
-		fprintf(file, "LOAD %d %d\n", dispo, adresse);
271
+		add_instruction(LOAD, dispo, adresse, 0);
156 272
 		set_registre(adresse, dispo);
157 273
 		refresh_registre(dispo);
158 274
 		return dispo;
@@ -163,7 +279,7 @@ int get_reg_read(int adresse, FILE * file, int * added_instruction) {
163 279
 }
164 280
 
165 281
 
166
-int flush_and_init(FILE * file) {
282
+int flush_and_init() {
167 283
 	int i;
168 284
 	int added_instruction = 0;
169 285
 	for (i = 0; i<MEM_SIZE; i++) {
@@ -171,7 +287,7 @@ int flush_and_init(FILE * file) {
171 287
 			if (tableau[i].modifie == 0) {
172 288
 				tableau[i].registre = -1;
173 289
 			} else {
174
-				fprintf(file, "STORE %d %d\n", i, tableau[i].registre);
290
+				add_instruction(STORE, i, tableau[i].registre, 0);
175 291
 				added_instruction++;
176 292
 				tableau[i].registre = -1;
177 293
 				tableau[i].modifie = 0;

+ 10
- 3
tables.h View File

@@ -13,14 +13,21 @@
13 13
 ----------------------------------------
14 14
 */
15 15
 
16
+
17
+
16 18
 #include <stdint.h>
17 19
 #include <stdio.h>
18 20
 
21
+enum instruction_t {NOP, ADD, MUL, SUB, DIV, INF, SUP, EQU, CPY, AFC, LOAD, STORE, LOADI, STOREI, STOREA, JMP, JMZ, PRI, GET, CALL, RET, STOP};
22
+
19 23
 void init(void);
20 24
 void increment_time();
21
-int get_reg_read(int adresse, FILE * file, int * added_instruction);
22
-int get_reg_write(int adresse, FILE * file, int * added_instruction);
23
-int flush_and_init(FILE * file);
25
+int get_reg_read(int adresse, int * added_instruction);
26
+int get_reg_write(int adresse, int * added_instruction);
27
+int flush_and_init();
24 28
 void new_instruction(int nb_inst);
29
+void write_asm(FILE * file);
30
+void write_code_machine(FILE * file);
31
+void add_instruction(enum instruction_t inst, int param1, int param2, int param3);
25 32
 
26 33
 #endif

+ 38
- 5
toto.asm View File

@@ -1,8 +1,41 @@
1
-AFC 0 1
1
+JMP 31
2 2
 AFC 1 1
3
-AFC 2 1
3
+COP 2 0
4
+AFC 3 1
5
+MUL 1 3 1
6
+ADD 1 2 1
7
+AFC 2 10
8
+WR 1 2
9
+AFC 1 0
10
+COP 2 0
11
+AFC 3 1
12
+MUL 1 3 1
13
+ADD 1 2 1
14
+READ 1 1
15
+PRI 1
16
+STOP 15
17
+AFC 1 2
18
+COP 0 1
19
+RET
20
+AFC 1 0
21
+COP 2 0
4 22
 AFC 3 1
5
-AFC 4 1
23
+MUL 1 3 1
24
+ADD 1 2 1
25
+AFC 2 1
26
+WR 1 2
27
+COP 1 0
28
+CALL 1 1
29
+AFC 1 1
30
+COP 0 1
31
+RET
32
+AFCA 5 0
33
+CALL 19 5
6 34
 AFC 5 1
7
-AFC 6 1
8
-MUL 0 1 2 
35
+AFCA 6 0
36
+AFC 7 1
37
+MUL 5 7 5
38
+ADD 5 6 5
39
+READ 5 5
40
+PRI 5
41
+STOP 0

Loading…
Cancel
Save