2 Commits

Author SHA1 Message Date
  Elies Tali 1cb970ec2d Merge branch 'master' of https://git.etud.insa-toulouse.fr/pfaure/CrossAssembleur 3 years ago
  Elies Tali 1f7cd371e5 Modifs 3 years ago
13 changed files with 3849 additions and 57 deletions
  1. 1809
    0
      as.tab.c
  2. 96
    0
      as.tab.h
  3. BIN
      as.tab.o
  4. 19
    16
      as.y
  5. 1896
    0
      lex.yy.c
  6. BIN
      lex.yy.o
  7. 0
    0
      output.asm
  8. 1
    0
      output.bin
  9. BIN
      rondoudou_cross_assembleur
  10. 7
    3
      tables.c
  11. 1
    0
      tables.h
  12. BIN
      tables.o
  13. 20
    38
      toto.asm

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


+ 96
- 0
as.tab.h View File

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

BIN
as.tab.o View File


+ 19
- 16
as.y View File

@@ -3,7 +3,7 @@
3 3
 }
4 4
 %{
5 5
 #include "tables.h"
6
-#include <stdio.h> 
6
+#include <stdio.h>
7 7
 
8 8
 FILE * file;
9 9
 FILE * file2;
@@ -21,56 +21,56 @@ FILE * file2;
21 21
 
22 22
 %%
23 23
 
24
-Programme : Instruction Programme; 
24
+Programme : Instruction Programme;
25 25
 Programme : Instruction;
26 26
 
27 27
 Instruction : tMUL tNB tNB tNB {increment_time();
28 28
 																int added_instruction = 0;
29
-																int reg_dest = get_reg_write($2, &added_instruction);
30 29
 																int reg_src1 = get_reg_read($3, &added_instruction);
31 30
 																int reg_src2 = get_reg_read($4, &added_instruction);
31
+																int reg_dest = get_reg_write($2, &added_instruction);
32 32
 																add_instruction(MUL, reg_dest, reg_src1, reg_src2);
33 33
 																new_instruction(added_instruction + 1);};
34 34
 Instruction : tADD tNB tNB tNB {increment_time();
35 35
 																int added_instruction = 0;
36
-																int reg_dest = get_reg_write($2, &added_instruction);
37 36
 																int reg_src1 = get_reg_read($3, &added_instruction);
38 37
 																int reg_src2 = get_reg_read($4, &added_instruction);
38
+																int reg_dest = get_reg_write($2, &added_instruction);
39 39
 																add_instruction(ADD, reg_dest, reg_src1, reg_src2);
40 40
 																new_instruction(added_instruction + 1);};
41 41
 Instruction : tDIV tNB tNB tNB {increment_time();
42 42
 																int added_instruction = 0;
43
-																int reg_dest = get_reg_write($2, &added_instruction);
44 43
 																int reg_src1 = get_reg_read($3, &added_instruction);
45 44
 																int reg_src2 = get_reg_read($4, &added_instruction);
45
+																int reg_dest = get_reg_write($2, &added_instruction);
46 46
 																add_instruction(DIV, reg_dest, reg_src1, reg_src2);
47 47
 																new_instruction(added_instruction + 1);};
48 48
 Instruction : tSUB tNB tNB tNB {increment_time();
49 49
 																int added_instruction = 0;
50
-																int reg_dest = get_reg_write($2, &added_instruction);
51 50
 																int reg_src1 = get_reg_read($3, &added_instruction);
52 51
 																int reg_src2 = get_reg_read($4, &added_instruction);
52
+																int reg_dest = get_reg_write($2, &added_instruction);
53 53
 																add_instruction(SUB, reg_dest, reg_src1, reg_src2);
54 54
 																new_instruction(added_instruction + 1);};
55 55
 Instruction : tINF tNB tNB tNB {increment_time();
56 56
 																int added_instruction = 0;
57
-																int reg_dest = get_reg_write($2, &added_instruction);
58 57
 																int reg_src1 = get_reg_read($3, &added_instruction);
59 58
 																int reg_src2 = get_reg_read($4, &added_instruction);
59
+																int reg_dest = get_reg_write($2, &added_instruction);
60 60
 																add_instruction(INF, reg_dest, reg_src1, reg_src2);
61 61
 																new_instruction(added_instruction + 1);};
62 62
 Instruction : tSUP tNB tNB tNB {increment_time();
63 63
 																int added_instruction = 0;
64
-																int reg_dest = get_reg_write($2, &added_instruction);
65 64
 																int reg_src1 = get_reg_read($3, &added_instruction);
66 65
 																int reg_src2 = get_reg_read($4, &added_instruction);
66
+																int reg_dest = get_reg_write($2, &added_instruction);
67 67
 																add_instruction(SUP, reg_dest, reg_src1, reg_src2);
68 68
 																new_instruction(added_instruction + 1);};
69 69
 Instruction : tEQU tNB tNB tNB {increment_time();
70 70
 																int added_instruction = 0;
71
-																int reg_dest = get_reg_write($2, &added_instruction);
72 71
 																int reg_src1 = get_reg_read($3, &added_instruction);
73 72
 																int reg_src2 = get_reg_read($4, &added_instruction);
73
+																int reg_dest = get_reg_write($2, &added_instruction);
74 74
 																add_instruction(EQU, reg_dest, reg_src1, reg_src2);
75 75
 																new_instruction(added_instruction + 1);};
76 76
 
@@ -82,8 +82,8 @@ Instruction : tAFC tNB tNB     {increment_time();
82 82
 																new_instruction(added_instruction + 1);};
83 83
 Instruction : tCPY tNB tNB     {increment_time();
84 84
 																int added_instruction = 0;
85
-																int reg_dest = get_reg_write($2, &added_instruction);
86 85
 																int reg_src = get_reg_read($3, &added_instruction);
86
+																int reg_dest = get_reg_write($2, &added_instruction);
87 87
 																add_instruction(CPY, reg_dest, reg_src, 0);
88 88
 																new_instruction(added_instruction + 1);};
89 89
 Instruction : tAFCA tNB tNB     {increment_time();
@@ -105,17 +105,17 @@ Instruction : tJMF tNB tNB     {increment_time();
105 105
 																add_instruction(JMZ, $3, 0, 0);
106 106
 																new_instruction(added_instruction + 2);};
107 107
 
108
-Instruction : tWR tNB tNB      {increment_time();
108
+Instruction : tREAD tNB tNB      {increment_time();
109 109
 																int added_instruction = 0;
110
-																int reg_dest = get_reg_write($2, &added_instruction);
111 110
 																int reg_addr = get_reg_read($3, &added_instruction);
112
-																add_instruction(STOREI, reg_dest, reg_addr, 0);
111
+																int reg_dest = get_reg_write($2, &added_instruction);
112
+																add_instruction(LOADI, reg_dest, reg_addr, 0);
113 113
 																new_instruction(added_instruction + 1);};
114
-Instruction : tREAD tNB tNB    {increment_time();
114
+Instruction : tWR tNB tNB    {increment_time();
115 115
 																int added_instruction = 0;
116 116
 																int reg_addr = get_reg_read($2, &added_instruction);
117 117
 																int reg_value = get_reg_read($3, &added_instruction);
118
-																add_instruction(LOADI, reg_addr, reg_value, 0);
118
+																add_instruction(STOREI, reg_addr, reg_value, 0);
119 119
 																new_instruction(added_instruction + 1);};
120 120
 
121 121
 
@@ -132,8 +132,10 @@ Instruction : tPRI tNB         {increment_time();
132 132
 
133 133
 
134 134
 Instruction : tCALL tNB tNB    {increment_time();
135
+																print();
135 136
 																int added_instruction = flush_and_init(file);
136
-																add_instruction(STOP, $2, $3, 0);
137
+																print();
138
+																add_instruction(CALL, $2, $3, 0);
137 139
 																new_instruction(added_instruction + 1);};
138 140
 Instruction : tRET             {increment_time();
139 141
 																int added_instruction = flush_and_init(file);
@@ -149,6 +151,7 @@ Instruction : tSTOP tNB         {increment_time();
149 151
 int main(void) {
150 152
 	file = fopen("output.asm", "w");
151 153
 	file2 = fopen("output.bin", "w");
154
+	file = stdout;
152 155
   init();
153 156
 	yyparse();
154 157
 	write_asm(file);

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


BIN
lex.yy.o View File


+ 0
- 0
output.asm View File


+ 1
- 0
output.bin View File

@@ -0,0 +1 @@
1
+"00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "00000000000000000000000000000" & "10101000000000000000000000000" & "10001000000110000000000000000" & "01101000000110000001100000000" & "00001000000110000000000000011" & "00010000000110000000100000011" & "01001000000010000000100000000" & "01110000001010000000100000000" & "01001000000010000000000000000" & "01011000001100000000100000000" & "01001000000110000000000000000" & "01100000000100000000000000000" & "01001000000000000110000000000" & "01011000000100000000000000000" & "00001000000100000001100000010" & "00010000000100000000100000010" & "01001000000010000000100000000" & "01110000001000000000100000000" & "01001000000010000000000000000" & "01011000001010000000100000000" & "01001000000100000000100000000" & "01100000000000000001100000000" & "01001000000110000000100000000" & "00001000000000000001000000000" & "01010000000100000001100000000" & "00010000000000000000100000000" & "01001000000010000000100000000" & "01110000000110000000100000000" & "01001000000010000000000000000" & "01001000000000000000000000000" & "01111000000010000000000000000" & 

BIN
rondoudou_cross_assembleur View File


+ 7
- 3
tables.c View File

@@ -14,8 +14,8 @@
14 14
 #include "tables.h"
15 15
 #define NB_REG 4
16 16
 #define MEM_SIZE 16
17
-#define NB_INSTRUCTIONS 64
18
-#define MEM_INST_SIZE 64
17
+#define NB_INSTRUCTIONS 128
18
+#define MEM_INST_SIZE 128
19 19
 #define NB_BITS_INSTRUCTION 5
20 20
 #define NB_BITS 8
21 21
 
@@ -115,7 +115,11 @@ void write_instruction_binary(FILE * file, struct str_instruction instr) {
115 115
 	char buff3[33];
116 116
 	char buff4[33];
117 117
 	convert_to_binary_on_N(instr.instruction, NB_BITS_INSTRUCTION, buff1);
118
-	convert_to_binary_on_N(instr.param1, NB_BITS, buff2);
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
+	}
119 123
 	convert_to_binary_on_N(instr.param2, NB_BITS, buff3);
120 124
 	convert_to_binary_on_N(instr.param3, NB_BITS, buff4);
121 125
 	fprintf(file, "\"%s%s%s%s\" & ", buff1, buff2, buff3, buff4);

+ 1
- 0
tables.h View File

@@ -21,6 +21,7 @@
21 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 22
 
23 23
 void init(void);
24
+void print();
24 25
 void increment_time();
25 26
 int get_reg_read(int adresse, int * added_instruction);
26 27
 int get_reg_write(int adresse, int * added_instruction);

BIN
tables.o View File


+ 20
- 38
toto.asm View File

@@ -1,41 +1,23 @@
1
-JMP 31
2
-AFC 1 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
1
+JMP 1
2
+AFC 2 0
3
+AFCA 3 0
4
+AFC 5 1
5
+MUL 2 5 2
6
+ADD 2 3 2
7
+AFC 4 1
8
+WR 2 4
22 9
 AFC 3 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
10
+AFCA 4 0
11
+AFC 6 1
12
+MUL 3 6 3
13
+ADD 3 4 3
14
+AFC 5 12
15
+WR 3 5
16
+AFC 4 0
32 17
 AFCA 5 0
33
-CALL 19 5
34
-AFC 5 1
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
18
+AFC 6 1
19
+MUL 4 6 4
20
+ADD 4 5 4
21
+READ 4 4
22
+PRI 4
41 23
 STOP 0

Loading…
Cancel
Save