Browse Source

Début Nettoyage

Paul Faure 2 years ago
parent
commit
5f88839a5b
16 changed files with 349 additions and 4055 deletions
  1. 0
    0
      LexYacc/al.lex
  2. 0
    0
      LexYacc/as.y
  3. 54
    7
      Makefile
  4. 216
    170
      Tables/tables.c
  5. 79
    0
      Tables/tables.h
  6. 0
    1707
      as.tab.c
  7. 0
    93
      as.tab.h
  8. BIN
      as.tab.o
  9. 0
    1896
      lex.yy.c
  10. BIN
      lex.yy.o
  11. 0
    84
      output.asm
  12. 0
    1
      output.bin
  13. BIN
      rondoudou_cross_assembleur
  14. 0
    35
      tables.h
  15. BIN
      tables.o
  16. 0
    62
      toto.asm

al.lex → LexYacc/al.lex View File


as.y → LexYacc/as.y View File


+ 54
- 7
Makefile View File

@@ -1,7 +1,54 @@
1
-build :
2
-	gcc -Wall -c tables.c -o tables.o
3
-	bison -d -t as.y
4
-	flex -o lex.yy.c al.lex
5
-	gcc -Wall -c as.tab.c -o as.tab.o
6
-	gcc -Wall -c lex.yy.c -o lex.yy.o
7
-	gcc as.tab.o lex.yy.o tables.o -ll -o rondoudou_cross_assembleur
1
+default : 
2
+	@echo "Spécifiez une cible"
3
+
4
+
5
+
6
+###########################
7
+###      NETTOYAGE      ###
8
+###########################
9
+clean_all : clean clean_Inputs clean_Outputs
10
+
11
+clean: clean_Lex_Yacc clean_Tables
12
+	@rm -f rondoudou_cross_assembleur
13
+
14
+clean_Tables:
15
+	@rm -f Tables/*.o
16
+
17
+clean_Lex_Yacc:
18
+	@rm -f Lex_Yacc/as.output Lex_Yacc/as.tab.* Lex_Yacc/lex.yy.*
19
+
20
+clean_Inputs:
21
+	@rm -f Inputs/*
22
+
23
+clean_Outputs:
24
+	@rm -f Outputs/*
25
+
26
+
27
+
28
+###########################
29
+###     COMPILATION     ###
30
+###########################
31
+build : clean build_Tables build_Lex_Yacc
32
+	gcc Lex_Yacc/as.tab.o Lex_Yacc/lex.yy.o Tables/tables.o -ll -o rondoudou_cross_assembleur
33
+
34
+build_Tables: clean_Tables
35
+	gcc -c Tables/tables.c -o Tables/tables.o
36
+
37
+build_Lex_Yacc: clean_Lex_Yacc
38
+	bison -g -v -d -t -b Lex_Yacc/as Lex_Yacc/as.y
39
+	flex -o Lex_Yacc/lex.yy.c Lex_Yacc/al.lex
40
+	gcc -c Lex_Yacc/as.tab.c -o Lex_Yacc/as.tab.o
41
+	gcc -c Lex_Yacc/lex.yy.c -o Lex_Yacc/lex.yy.o
42
+
43
+
44
+
45
+###########################
46
+###       EDITION       ###
47
+###########################
48
+edit_Lex_Yacc: 
49
+	pluma Lex_Yacc/al.lex Lex_Yacc/as.y &
50
+
51
+edit_Tables: 
52
+	pluma Tables/tables.c Tables/tables.h &
53
+
54
+edit: edit_Lex_Yacc edit_Tables

tables.c → Tables/tables.c View File

@@ -1,26 +1,24 @@
1
-
2
-/* 
3
-----------------------------------------
4
-|  Adresse   |  Registre  |  Modifié   | 
5
-----------------------------------------
6
-|            |            |            |            
7
-|            |            |            |            
8
-|            |            |            |            
9
-|      i     | 0x777756b8 |     int    |       
10
-|    size    | 0x777756b8 |     int    |        
11
-----------------------------------------
12
-*/
13
-
14 1
 #include "tables.h"
15 2
 #define NB_REG 4
16 3
 #define MEM_SIZE 16
17
-#define NB_INSTRUCTIONS 128
18 4
 #define MEM_INST_SIZE 128
19 5
 #define NB_BITS_INSTRUCTION 5
20 6
 #define NB_BITS 8
21 7
 
22
-int traduction_JMP[NB_INSTRUCTIONS];
23 8
 
9
+
10
+/**************************************************/
11
+/**************************************************/
12
+/***************** Initialisation *****************/
13
+/**************************************************/
14
+/**************************************************/
15
+
16
+// Buffer to patch Jumps difference due to adding LOAD and STORE
17
+int traduction_JMP[MEM_INST_SIZE];
18
+// Index of the buffer
19
+int last_instruction = 0;
20
+
21
+// Structure coding an instruction
24 22
 struct str_instruction {
25 23
 	enum instruction_t instruction;
26 24
 	int param1;
@@ -28,136 +26,23 @@ struct str_instruction {
28 26
 	int param3;
29 27
 };
30 28
 
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, char compact) {
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
-	if (instr.instruction == JMP || instr.instruction == JMZ || instr.instruction == CALL) {
119
-		convert_to_binary_on_N(traduction_JMP[instr.param1], NB_BITS, buff2);
120
-	} else {
121
-		convert_to_binary_on_N(instr.param1, NB_BITS, buff2);
122
-	}
123
-	convert_to_binary_on_N(instr.param2, NB_BITS, buff3);
124
-	convert_to_binary_on_N(instr.param3, NB_BITS, buff4);
125
-	if (compact) {
126
-		fprintf(file, "%s%s%s%s", buff1, buff2, buff3, buff4);
127
-	} else {
128
-		fprintf(file, "\"%s%s%s%s\" & ", buff1, buff2, buff3, buff4);
129
-	}
130
-}
131
-
132
-
133
-void write_code_machine(FILE * file) {
134
-	int i = MEM_INST_SIZE - 1;
135
-	while (i>=0) {
136
-		write_instruction_binary(file, buffer[i], 0);
137
-		i--;
138
-	}
139
-}
140
-
141
-void write_code_machine_compact(FILE * file) {
142
-	printf(file, "\"");
143
-	int i = MEM_INST_SIZE - 1;
144
-	while (i>=0) {
145
-		write_instruction_binary(file, buffer[i], 1);
146
-		i--;
147
-	}
148
-	printf(file, "\"\n");
149
-}
150
-
29
+// Buffer to store registers oriented instructions
30
+struct str_instruction buffer[3*MEM_INST_SIZE];
151 31
 
32
+// Structure coding an address and the correpondance with a register 
152 33
 struct case_adresse {
153 34
 	int adresse;
154 35
 	int registre;
155 36
 	char modifie;
156 37
 };
157 38
 
39
+// Buffer of addresses (Memory)
158 40
 struct case_adresse tableau[MEM_SIZE];
41
+
42
+// Buffer to manage priority policy
159 43
 int registres[NB_REG];
160 44
 
45
+// Initialise all : the addresses-registers association table, the registers priority table, the instructions buffer, the instruction address association table
161 46
 void init (void) {
162 47
   int i;
163 48
 	struct case_adresse case_courante = {0, -1, 0};
@@ -174,10 +59,20 @@ void init (void) {
174 59
 	}
175 60
 }
176 61
 
62
+
63
+/**************************************************/
64
+/**************************************************/
65
+/************** Registers Management **************/
66
+/**************************************************/
67
+/**************************************************/
68
+
69
+// INTERN FUNCTION
70
+// Print a case address
177 71
 void print_case_adresse(struct case_adresse case_courante) {
178 72
 	printf("{addr : %d ; reg : %d ; modi : %d}\n", case_courante.adresse, case_courante.registre, (int)case_courante.modifie);
179 73
 }
180 74
 
75
+// Print the adresses-registers correspondance table
181 76
 void print() {
182 77
   int i;
183 78
 	for (i=0; i<MEM_SIZE; i++) {
@@ -185,11 +80,14 @@ void print() {
185 80
 	}
186 81
 }
187 82
 
188
-
83
+// INTERN FUNCTION
84
+// return the case corresponding to the given address
189 85
 struct case_adresse get_info(int adresse) {
190 86
 	return tableau[adresse];
191 87
 }
192 88
 
89
+// INTERN FUNCTION
90
+// return the address corresponding to the given register
193 91
 int get_adresse (int registre) {
194 92
 	int i = 0;
195 93
 	while (i < MEM_SIZE && tableau[i].registre != registre) {
@@ -202,14 +100,19 @@ int get_adresse (int registre) {
202 100
 	}
203 101
 }
204 102
 
103
+// INTERN FUNCTION
104
+// Set the given register to the given address
205 105
 void set_registre(int adresse, int registre) {
206 106
 	tableau[adresse].registre = registre;
207 107
 }
208 108
 
109
+// INTERN FUNCTION
110
+// Set modifie to the address (0 the value in the memory is up to date, 1 the value in the register is more recent)
209 111
 void set_modifie(int adresse, char modifie) {
210 112
 	tableau[adresse].modifie = modifie;
211 113
 }
212 114
 
115
+// Increment the register priority policy buffer
213 116
 void increment_time() {
214 117
 	int i;
215 118
 	for (i=0; i<NB_REG; i++) {
@@ -217,10 +120,14 @@ void increment_time() {
217 120
 	}
218 121
 }
219 122
 
123
+// INTERN FUNCTION
124
+// Specifie that the given register have been used
220 125
 void refresh_registre(int registre) {
221 126
 	registres[registre] = 0;
222 127
 }
223 128
 
129
+// INTERN FUNCTION
130
+// Return the LRU register
224 131
 int get_register() {
225 132
 	int i;
226 133
 	int index_max = 0;
@@ -232,6 +139,48 @@ int get_register() {
232 139
 	return index_max;
233 140
 }
234 141
 
142
+/* Ask for a register to read the value
143
+
144
+	@param  : 
145
+			- adresse : The address of value wanted
146
+			- added_instruction : Address of an int storing the number of added_instructions
147
+	@return : The number of the register corresponding to the given address
148
+*/
149
+int get_reg_read(int adresse, int * added_instruction) {
150
+	struct case_adresse ma_case = get_info(adresse);
151
+	if (ma_case.registre == -1) {
152
+		int dispo = get_register();
153
+		int previous_addr = get_adresse(dispo);
154
+		if (previous_addr != -1) {
155
+			struct case_adresse ancienne_case = get_info(previous_addr);
156
+			if (ancienne_case.modifie == 1) {
157
+				*added_instruction = (*added_instruction) + 1;
158
+				add_instruction(STORE, previous_addr, dispo, 0);
159
+				set_modifie(previous_addr, 0);
160
+			}
161
+			set_registre(previous_addr, -1);
162
+		}
163
+		*added_instruction = (*added_instruction) + 1;
164
+		add_instruction(LOAD, dispo, adresse, 0);
165
+		set_registre(adresse, dispo);
166
+		refresh_registre(dispo);
167
+		return dispo;
168
+	} else {
169
+		refresh_registre(ma_case.registre);
170
+		return ma_case.registre;
171
+	}
172
+}
173
+
174
+/* Ask for a register to write the value
175
+
176
+	@param  : 
177
+			- adresse : The address of value (if -1 return a free register without associating it to any address)
178
+			- added_instruction : Address of an int storing the number of added_instructions
179
+	@return : The number of the register corresponding to the given address
180
+
181
+	WARNING : The value of the address will not be LOADED in the register
182
+						Always ask READ registers before the WRITE register
183
+*/
235 184
 int get_reg_write(int adresse, int * added_instruction) {
236 185
 	if (adresse == -1) {
237 186
 		int dispo = get_register();
@@ -271,35 +220,12 @@ int get_reg_write(int adresse, int * added_instruction) {
271 220
 	}
272 221
 }
273 222
 
274
-int get_reg_read(int adresse, int * added_instruction) {
275
-	struct case_adresse ma_case = get_info(adresse);
276
-	if (ma_case.registre == -1) {
277
-		int dispo = get_register();
278
-		int previous_addr = get_adresse(dispo);
279
-		if (previous_addr != -1) {
280
-			struct case_adresse ancienne_case = get_info(previous_addr);
281
-			if (ancienne_case.modifie == 1) {
282
-				*added_instruction = (*added_instruction) + 1;
283
-				add_instruction(STORE, previous_addr, dispo, 0);
284
-				set_modifie(previous_addr, 0);
285
-			}
286
-			set_registre(previous_addr, -1);
287
-		}
288
-		*added_instruction = (*added_instruction) + 1;
289
-		add_instruction(LOAD, dispo, adresse, 0);
290
-		set_registre(adresse, dispo);
291
-		refresh_registre(dispo);
292
-		return dispo;
293
-	} else {
294
-		refresh_registre(ma_case.registre);
295
-		return ma_case.registre;
296
-	}
297
-}
298
-
223
+// Broke the association between adresse and its corresponding register
299 224
 void unlink(int adresse) {
300 225
 	set_registre(adresse, -1);
301 226
 }
302 227
 
228
+// Store used register, init the association table between addresses and registers
303 229
 int flush_and_init() {
304 230
 	int i;
305 231
 	int added_instruction = 0;
@@ -321,28 +247,148 @@ int flush_and_init() {
321 247
 	return added_instruction;
322 248
 }
323 249
 
324
-void new_instruction(int nb_inst) {
325
-	static int last_intruction_adresse = 0;
326
-	static int current_instruction = 0; 
327
-	traduction_JMP[current_instruction] = last_intruction_adresse;
328
-	current_instruction++;
329
-	last_intruction_adresse += nb_inst;
330
-}
331 250
 	
332 251
 
333 252
 
334 253
 
335 254
 
255
+/**************************************************/
256
+/**************************************************/
257
+/************** Instructions Writing **************/
258
+/**************************************************/
259
+/**************************************************/
336 260
 
261
+// Add a new Registers oriented instruction
262
+void add_instruction(enum instruction_t inst, int param1, int param2, int param3) {
263
+	struct str_instruction my_instruction = {inst, param1, param2, param3};
264
+	buffer[last_instruction] = my_instruction;
265
+	last_instruction++;
266
+}
337 267
 
268
+// Specifie the number of Register oriented instructions corresponding to the memory oriented instruction
269
+void new_instruction(int nb_inst) {
270
+	static int last_intruction_adresse = 0;
271
+	static int current_instruction = 0; 
272
+	traduction_JMP[current_instruction] = last_intruction_adresse;
273
+	current_instruction++;
274
+	last_intruction_adresse += nb_inst;
275
+}
338 276
 
277
+// Write the new assembly in the given file
278
+void write_asm(FILE * file) {
279
+	int i = 0;
280
+	while (i<MEM_INST_SIZE) {
281
+		if (buffer[i].instruction == ADD) {
282
+			fprintf(file, "ADD %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
283
+		} else if (buffer[i].instruction == SUB) {
284
+			fprintf(file, "SUB %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
285
+		} else if (buffer[i].instruction == MUL) {
286
+			fprintf(file, "MUL %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
287
+		} else if (buffer[i].instruction == DIV) {
288
+			fprintf(file, "DIV %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
289
+		} else if (buffer[i].instruction == INF) {
290
+			fprintf(file, "INF %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
291
+		} else if (buffer[i].instruction == SUP) {
292
+			fprintf(file, "SUP %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
293
+		} else if (buffer[i].instruction == EQU) {
294
+			fprintf(file, "EQU %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
339 295
 
296
+		} else if (buffer[i].instruction == AFC) {
297
+			fprintf(file, "AFC %d %d\n", buffer[i].param1, buffer[i].param2);
298
+		} else if (buffer[i].instruction == CPY) {
299
+			fprintf(file, "CPY %d %d\n", buffer[i].param1, buffer[i].param2);
340 300
 
301
+		} else if (buffer[i].instruction == LOAD) {
302
+			fprintf(file, "LOAD %d %d\n", buffer[i].param1, buffer[i].param2);
303
+		} else if (buffer[i].instruction == STORE) {
304
+			fprintf(file, "STORE %d %d\n", buffer[i].param1, buffer[i].param2);
305
+		} else if (buffer[i].instruction == LOADI) {
306
+			fprintf(file, "LOADI %d %d\n", buffer[i].param1, buffer[i].param2);
307
+		} else if (buffer[i].instruction == STOREI) {
308
+			fprintf(file, "STOREI %d %d\n", buffer[i].param1, buffer[i].param2);
309
+		} else if (buffer[i].instruction == STOREA) {
310
+			fprintf(file, "STOREA %d %d\n", buffer[i].param1, buffer[i].param2);
341 311
 
312
+		} else if (buffer[i].instruction == JMP) {
313
+			fprintf(file, "JMP %d\n", traduction_JMP[buffer[i].param1]);
314
+		} else if (buffer[i].instruction == JMZ) {
315
+			fprintf(file, "JMZ %d\n", traduction_JMP[buffer[i].param1]);
316
+		} else if (buffer[i].instruction == GET) {
317
+			fprintf(file, "GET %d\n", buffer[i].param1);
318
+		} else if (buffer[i].instruction == PRI) {
319
+			fprintf(file, "PRI %d\n", buffer[i].param1);
342 320
 
321
+		} else if (buffer[i].instruction == CALL) {
322
+			fprintf(file, "CALL %d %d\n", traduction_JMP[buffer[i].param1], buffer[i].param2);
323
+		} else if (buffer[i].instruction == RET) {
324
+			fprintf(file, "RET\n");
325
+		} else if (buffer[i].instruction == STOP) {
326
+			fprintf(file, "STOP %d\n", buffer[i].param1);
327
+		} 
328
+		i++;
329
+	}
330
+}
343 331
 
332
+// INTERN FUNCTION
333
+// Write binary value of n in buff
334
+void int_2_bin(char * buff, int n) {
335
+	int _m = n; 
336
+	for (int i = 0; i < 32; i++) { 
337
+		buff[31 - i] = ((_m & (1 << 31)) ? '1' : '0'); 
338
+		_m = _m << 1; 
339
+	} 
340
+}
344 341
 
342
+// INTERN FUNCTION
343
+// Write binary value of value in buff on N bits
344
+void convert_to_binary_on_N(int value, int N, char * buff) {
345
+	char tampon[33];
346
+	int_2_bin(tampon, value);
347
+	int i;
348
+	for (i = N-1; i>=0; i--) {
349
+		buff[N-1-i] = tampon[i];
350
+	}
351
+	buff[N] = '\0';
352
+}
345 353
 
354
+// INTERN FUNCTION
355
+// Write a binary instruction in the given file
356
+// If not compact ("010..10" & ) else only (010..10)
357
+void write_instruction_binary(FILE * file, struct str_instruction instr, char compact) {
358
+	char buff1[33];
359
+	char buff2[33];
360
+	char buff3[33];
361
+	char buff4[33];
362
+	convert_to_binary_on_N(instr.instruction, NB_BITS_INSTRUCTION, buff1);
363
+	if (instr.instruction == JMP || instr.instruction == JMZ || instr.instruction == CALL) {
364
+		convert_to_binary_on_N(traduction_JMP[instr.param1], NB_BITS, buff2);
365
+	} else {
366
+		convert_to_binary_on_N(instr.param1, NB_BITS, buff2);
367
+	}
368
+	convert_to_binary_on_N(instr.param2, NB_BITS, buff3);
369
+	convert_to_binary_on_N(instr.param3, NB_BITS, buff4);
370
+	if (compact) {
371
+		fprintf(file, "%s%s%s%s", buff1, buff2, buff3, buff4);
372
+	} else {
373
+		fprintf(file, "\"%s%s%s%s\" & ", buff1, buff2, buff3, buff4);
374
+	}
375
+}
346 376
 
347
-
348
-
377
+// Write the binary code in the given file
378
+void write_code_machine(FILE * file, char compact) {
379
+	if (compact) {
380
+		int i = MEM_INST_SIZE - 1;
381
+		while (i>=0) {
382
+			write_instruction_binary(file, buffer[i], 0);
383
+			i--;
384
+		}
385
+	} else {
386
+		printf(file, "\"");
387
+		int i = MEM_INST_SIZE - 1;
388
+		while (i>=0) {
389
+			write_instruction_binary(file, buffer[i], 1);
390
+			i--;
391
+		}
392
+		printf(file, "\"\n");
393
+	}
394
+}

+ 79
- 0
Tables/tables.h View File

@@ -0,0 +1,79 @@
1
+#ifndef TABLE_H
2
+#define TABLE_H
3
+
4
+#include <stdint.h>
5
+#include <stdio.h>
6
+
7
+
8
+// Initialise all : the addresses-registers association table, the registers priority table, the instructions buffer, the instruction address association table
9
+void init(void);
10
+
11
+
12
+
13
+
14
+/**************************************************/
15
+/**************************************************/
16
+/************** Registers Management **************/
17
+/**************************************************/
18
+/**************************************************/
19
+
20
+// Print the addresses-registers association table
21
+void print();
22
+
23
+// Increment the input instruction counter
24
+void increment_time();
25
+
26
+/* Ask for a register to read the value
27
+
28
+	@param  : 
29
+			- adresse : The address of value wanted
30
+			- added_instruction : Address of an int storing the number of added_instructions
31
+	@return : The number of the register corresponding to the given address
32
+*/
33
+int get_reg_read(int adresse, int * added_instruction);
34
+
35
+/* Ask for a register to write the value
36
+
37
+	@param  : 
38
+			- adresse : The address of value (if -1 return a free register without associating it to any address)
39
+			- added_instruction : Address of an int storing the number of added_instructions
40
+	@return : The number of the register corresponding to the given address
41
+
42
+	WARNING : The value of the address will not be LOADED in the register
43
+						Always ask READ registers before the WRITE register
44
+*/
45
+int get_reg_write(int adresse, int * added_instruction);
46
+
47
+// Broke the association between adresse and its corresponding register
48
+void unlink(int adresse);
49
+
50
+// Store used register, init the association table between addresses and registers 
51
+int flush_and_init();
52
+
53
+
54
+
55
+
56
+
57
+/**************************************************/
58
+/**************************************************/
59
+/************** Instructions Writing **************/
60
+/**************************************************/
61
+/**************************************************/
62
+
63
+
64
+// Enum of the register oriented instruction (warning order correspond to the binary code)
65
+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};
66
+
67
+// Add a new Registers oriented instruction
68
+void add_instruction(enum instruction_t inst, int param1, int param2, int param3);
69
+
70
+// Specifie the number of Register oriented instructions corresponding to the memory oriented instruction
71
+void new_instruction(int nb_inst);
72
+
73
+// Write the new assembly in the given file
74
+void write_asm(FILE * file);
75
+
76
+// Write the binary code in the given file
77
+void write_code_machine(FILE * file, char compact);
78
+
79
+#endif

+ 0
- 1707
as.tab.c
File diff suppressed because it is too large
View File


+ 0
- 93
as.tab.h View File

@@ -1,93 +0,0 @@
1
-/* A Bison parser, made by GNU Bison 3.0.4.  */
2
-
3
-/* Bison interface for Yacc-like parsers in C
4
-
5
-   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6
-
7
-   This program is free software: you can redistribute it and/or modify
8
-   it under the terms of the GNU General Public License as published by
9
-   the Free Software Foundation, either version 3 of the License, or
10
-   (at your option) any later version.
11
-
12
-   This program is distributed in the hope that it will be useful,
13
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-   GNU General Public License for more details.
16
-
17
-   You should have received a copy of the GNU General Public License
18
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
-
20
-/* As a special exception, you may create a larger work that contains
21
-   part or all of the Bison parser skeleton and distribute that work
22
-   under terms of your choice, so long as that work isn't itself a
23
-   parser generator using the skeleton or a modified version thereof
24
-   as a parser skeleton.  Alternatively, if you modify or redistribute
25
-   the parser skeleton itself, you may (at your option) remove this
26
-   special exception, which will cause the skeleton and the resulting
27
-   Bison output files to be licensed under the GNU General Public
28
-   License without this special exception.
29
-
30
-   This special exception was added by the Free Software Foundation in
31
-   version 2.2 of Bison.  */
32
-
33
-#ifndef YY_YY_AS_TAB_H_INCLUDED
34
-# define YY_YY_AS_TAB_H_INCLUDED
35
-/* Debug traces.  */
36
-#ifndef YYDEBUG
37
-# define YYDEBUG 1
38
-#endif
39
-#if YYDEBUG
40
-extern int yydebug;
41
-#endif
42
-
43
-/* Token type.  */
44
-#ifndef YYTOKENTYPE
45
-# define YYTOKENTYPE
46
-  enum yytokentype
47
-  {
48
-    tMUL = 258,
49
-    tDIV = 259,
50
-    tADD = 260,
51
-    tSUB = 261,
52
-    tINF = 262,
53
-    tSUP = 263,
54
-    tEQU = 264,
55
-    tAFC = 265,
56
-    tCPY = 266,
57
-    tAFCA = 267,
58
-    tREAD = 268,
59
-    tWR = 269,
60
-    tJMP = 270,
61
-    tJMF = 271,
62
-    tGET = 272,
63
-    tPRI = 273,
64
-    tCALL = 274,
65
-    tRET = 275,
66
-    tSTOP = 276,
67
-    tNB = 277
68
-  };
69
-#endif
70
-
71
-/* Value type.  */
72
-#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
73
-
74
-union YYSTYPE
75
-{
76
-#line 1 "as.y" /* yacc.c:1909  */
77
-
78
-	int nombre;
79
-
80
-#line 81 "as.tab.h" /* yacc.c:1909  */
81
-};
82
-
83
-typedef union YYSTYPE YYSTYPE;
84
-# define YYSTYPE_IS_TRIVIAL 1
85
-# define YYSTYPE_IS_DECLARED 1
86
-#endif
87
-
88
-
89
-extern YYSTYPE yylval;
90
-
91
-int yyparse (void);
92
-
93
-#endif /* !YY_YY_AS_TAB_H_INCLUDED  */

BIN
as.tab.o View File


+ 0
- 1896
lex.yy.c
File diff suppressed because it is too large
View File


BIN
lex.yy.o View File


+ 0
- 84
output.asm View File

@@ -1,84 +0,0 @@
1
-JMP 48
2
-AFC 0 1
3
-LOAD 1 0
4
-CPY 2 1
5
-AFC 3 1
6
-MUL 0 3 0
7
-ADD 0 2 0
8
-LOADI 0 0
9
-PRI 0
10
-AFC 0 0
11
-CPY 2 1
12
-AFC 3 1
13
-MUL 0 3 0
14
-ADD 0 2 0
15
-AFC 2 14
16
-STOREI 0 2
17
-AFC 0 2
18
-CPY 1 0
19
-STORE 0 1
20
-STORE 1 0
21
-STORE 2 2
22
-STORE 3 3
23
-RET
24
-AFC 0 0
25
-LOAD 1 0
26
-CPY 2 1
27
-AFC 3 1
28
-MUL 0 3 0
29
-ADD 0 2 0
30
-LOADI 0 0
31
-PRI 0
32
-AFC 0 1
33
-CPY 2 1
34
-AFC 3 1
35
-MUL 0 3 0
36
-ADD 0 2 0
37
-AFC 2 10
38
-STOREI 0 2
39
-CPY 0 1
40
-STORE 1 0
41
-STORE 2 2
42
-STORE 3 3
43
-CALL 1 1
44
-AFC 0 1
45
-CPY 1 0
46
-STORE 0 1
47
-STORE 1 0
48
-RET
49
-AFC 0 0
50
-AFC 1 0
51
-STOREA 3 1
52
-AFC 1 1
53
-MUL 0 1 0
54
-LOAD 2 3
55
-ADD 0 2 0
56
-AFC 3 1
57
-STOREI 0 3
58
-AFC 2 1
59
-STORE 5 1
60
-AFC 1 0
61
-STOREA 4 1
62
-AFC 1 1
63
-MUL 2 1 2
64
-STORE 2 0
65
-LOAD 0 4
66
-ADD 2 0 2
67
-AFC 3 12
68
-STOREI 2 3
69
-STORE 6 1
70
-AFC 1 0
71
-STOREA 4 1
72
-STORE 3 2
73
-STORE 5 3
74
-CALL 23 4
75
-AFC 0 0
76
-AFC 1 0
77
-STOREA 5 1
78
-AFC 1 1
79
-MUL 0 1 0
80
-LOAD 2 5
81
-ADD 0 2 0
82
-LOADI 0 0
83
-PRI 0
84
-STOP 0

+ 0
- 1
output.bin View File

@@ -1 +0,0 @@
1
-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101010000000000000000000000001000100000000000000000000000001100000000000000000000000000000010000000000000010000000000101000000010000001010000000000010000000000000000100000000010010000000100000001000000000111000000101000000010000000001001000000010000000000000000010010000000000000000000000001001100010111000001000000000001011000001010000001100000000010110000001100000010000000000111000000100000000010000000001001000000010000000000000000010110000011000000001000000000110100000010000000110000000001001000000110000110000000000000010000001000000000000000100101000000000000001000000000001011000000100000000000000000000100000001000000001000000100100100000001000000010000000001110000001000000000100000000010010000000100000000000000000101100000101000000010000000001001000000100000000100000000011010000000000000011000000000100100000011000000010000000000001000000000000001000000000010100000001000000011000000000001000000000000000010000000001001000000010000000100000000011100000001100000001000000000100100000001000000000000000001001000000000000000000000000101000000000000000000000000000101100000001000000000000000001011000000000000000100000000010000000000100000000000000000100100000000000000010000000010011000000010000000100000000010110000001100000011000000000101100000010000000100000000001011000000010000000000000000010000000000000000001000000000110100000000000000100000000001001000000100000101000000000000010000000000000010000000000001000000000000000110000000001001000000110000000100000000010000000001000000001000000000100100000000000000010000000010001000000000000000000000000011000000000000000000000000000000100000000000000100000000000010000000000000001100000000010010000001100000001000000000100000000010000000010000000001010000000010000000000000000010010000000000000000000000001010000000000000000000000000001011000000110000001100000000010110000001000000010000000000101100000001000000000000000001011000000000000000100000000010000000000100000000000000000100100000000000000100000000001101000000000000001000000000010010000001000001110000000000000100000000000000100000000000010000000000000001100000000010010000001100000001000000000100000000010000000010000000001001000000000000000000000000100010000000000000000000000000110000000000000000000000000000001000000000000001000000000000100000000000000011000000000100100000011000000010000000001000000000100000000100000000010100000000100000000000000000100100000000000000010000000001111001100000000000000000000

BIN
rondoudou_cross_assembleur View File


+ 0
- 35
tables.h View File

@@ -1,35 +0,0 @@
1
-#ifndef TABLE_H
2
-#define TABLE_H
3
-
4
-/* 
5
-----------------------------------------
6
-|  Adresse   |  Registre  |  Modifié   | 
7
-----------------------------------------
8
-|            |            |            |            
9
-|            |            |            |            
10
-|            |            |            |            
11
-|      i     | 0x777756b8 |     int    |       
12
-|    size    | 0x777756b8 |     int    |        
13
-----------------------------------------
14
-*/
15
-
16
-
17
-
18
-#include <stdint.h>
19
-#include <stdio.h>
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
-
23
-void init(void);
24
-void print();
25
-void increment_time();
26
-int get_reg_read(int adresse, int * added_instruction);
27
-int get_reg_write(int adresse, int * added_instruction);
28
-void unlink(int adresse);
29
-int flush_and_init();
30
-void new_instruction(int nb_inst);
31
-void write_asm(FILE * file);
32
-void write_code_machine(FILE * file);
33
-void add_instruction(enum instruction_t inst, int param1, int param2, int param3);
34
-
35
-#endif

BIN
tables.o View File


+ 0
- 62
toto.asm View File

@@ -1,62 +0,0 @@
1
-JMP 37
2
-AFC 1 1
3
-COP 2 0
4
-AFC 3 1
5
-MUL 1 3 1
6
-ADD 1 2 1
7
-READ 1 1
8
-PRI 1
9
-AFC 1 0
10
-COP 2 0
11
-AFC 3 1
12
-MUL 1 3 1
13
-ADD 1 2 1
14
-AFC 2 14
15
-WR 1 2
16
-AFC 1 2
17
-COP 0 1
18
-RET
19
-AFC 1 0
20
-COP 2 0
21
-AFC 3 1
22
-MUL 1 3 1
23
-ADD 1 2 1
24
-READ 1 1
25
-PRI 1
26
-AFC 1 1
27
-COP 2 0
28
-AFC 3 1
29
-MUL 1 3 1
30
-ADD 1 2 1
31
-AFC 2 10
32
-WR 1 2
33
-COP 1 0
34
-CALL 1 1
35
-AFC 1 1
36
-COP 0 1
37
-RET
38
-AFC 2 0
39
-AFCA 3 0
40
-AFC 5 1
41
-MUL 2 5 2
42
-ADD 2 3 2
43
-AFC 4 1
44
-WR 2 4
45
-AFC 3 1
46
-AFCA 4 0
47
-AFC 6 1
48
-MUL 3 6 3
49
-ADD 3 4 3
50
-AFC 5 12
51
-WR 3 5
52
-AFCA 4 0
53
-CALL 18 4
54
-AFC 4 0
55
-AFCA 5 0
56
-AFC 6 1
57
-MUL 4 6 4
58
-ADD 4 5 4
59
-READ 4 4
60
-PRI 4
61
-STOP 0
62
-

Loading…
Cancel
Save