Browse Source

Adapt cross-assembler to our asm

Simard Yohan 2 months ago
parent
commit
6631ca437b
17 changed files with 54 additions and 4004 deletions
  1. 6
    0
      .gitignore
  2. 1
    1
      Makefile
  3. 3
    21
      al.lex
  4. 0
    1707
      as.tab.c
  5. 0
    93
      as.tab.h
  6. BIN
      as.tab.o
  7. 5
    89
      as.y
  8. 9
    0
      input.asm
  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. 29
    49
      tables.c
  15. 1
    1
      tables.h
  16. BIN
      tables.o
  17. 0
    62
      toto.asm

+ 6
- 0
.gitignore View File

@@ -0,0 +1,6 @@
1
+*.o
2
+lex.yy.c
3
+as.tab.*
4
+output.asm
5
+output_bin.txt
6
+cross_assembleur

+ 1
- 1
Makefile View File

@@ -4,4 +4,4 @@ build :
4 4
 	flex -o lex.yy.c al.lex
5 5
 	gcc -Wall -c as.tab.c -o as.tab.o
6 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
7
+	gcc as.tab.o lex.yy.o tables.o -o cross_assembleur

+ 3
- 21
al.lex View File

@@ -13,31 +13,13 @@ yyerror (char const *s)
13 13
 %%
14 14
 
15 15
 "ADD"     { return tADD ;} 
16
-"SOU"     { return tSUB;}
17 16
 "MUL"     { return tMUL; }
18
-"DIV"			{ return tDIV; }
19
-"INF"			{ return tINF; }
20
-"SUP"     { return tSUP; }
21
-"EQU"     { return tEQU; }
17
+"SOU"     { return tSUB;}
18
+"DIV"	  { return tDIV; }
22 19
 
23
-"AFC"    	{ return tAFC; }
24 20
 "COP"     { return tCPY; }
25
-"AFCA"    { return tAFCA; }
26
-
27
-
28
-"READ"    { return tREAD; }
29
-"WR"    { return tWR; }
30
-
31
-"JMP"     { return tJMP; }
32
-"JMF"     { return tJMF; }
33
-
34
-"GET"     { return tGET; }
35
-"PRI"     { return tPRI; }
36
-
37
-"CALL"    { return tCALL; }
38
-"RET"     { return tRET; }
21
+"AFC"     { return tAFC; }
39 22
 
40
-"STOP"     { return tSTOP; }
41 23
 
42 24
 [0-9]+	  { yylval.nombre = atoi(yytext); return tNB; }
43 25
 

+ 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


+ 5
- 89
as.y View File

@@ -10,13 +10,8 @@ FILE * file2;
10 10
 
11 11
 %}
12 12
 
13
-%token tMUL tDIV tADD tSUB tINF tSUP tEQU
14
-%token tAFC tCPY tAFCA
15
-%token tREAD tWR
16
-%token tJMP tJMF
17
-%token tGET tPRI
18
-%token tCALL tRET
19
-%token tSTOP
13
+%token tMUL tDIV tADD tSUB
14
+%token tAFC tCPY
20 15
 %token<nombre> tNB
21 16
 
22 17
 %%
@@ -52,28 +47,6 @@ Instruction : tSUB tNB tNB tNB {increment_time();
52 47
 																int reg_dest = get_reg_write($2, &added_instruction);
53 48
 																add_instruction(SUB, reg_dest, reg_src1, reg_src2);
54 49
 																new_instruction(added_instruction + 1);};
55
-Instruction : tINF tNB tNB tNB {increment_time();
56
-																int added_instruction = 0;
57
-																int reg_src1 = get_reg_read($3, &added_instruction);
58
-																int reg_src2 = get_reg_read($4, &added_instruction);
59
-																int reg_dest = get_reg_write($2, &added_instruction);
60
-																add_instruction(INF, reg_dest, reg_src1, reg_src2);
61
-																new_instruction(added_instruction + 1);};
62
-Instruction : tSUP tNB tNB tNB {increment_time();
63
-																int added_instruction = 0;
64
-																int reg_src1 = get_reg_read($3, &added_instruction);
65
-																int reg_src2 = get_reg_read($4, &added_instruction);
66
-																int reg_dest = get_reg_write($2, &added_instruction);
67
-																add_instruction(SUP, reg_dest, reg_src1, reg_src2);
68
-																new_instruction(added_instruction + 1);};
69
-Instruction : tEQU tNB tNB tNB {increment_time();
70
-																int added_instruction = 0;
71
-																int reg_src1 = get_reg_read($3, &added_instruction);
72
-																int reg_src2 = get_reg_read($4, &added_instruction);
73
-																int reg_dest = get_reg_write($2, &added_instruction);
74
-																add_instruction(EQU, reg_dest, reg_src1, reg_src2);
75
-																new_instruction(added_instruction + 1);};
76
-
77 50
 
78 51
 Instruction : tAFC tNB tNB     {increment_time();
79 52
 																int added_instruction = 0;
@@ -86,73 +59,16 @@ Instruction : tCPY tNB tNB     {increment_time();
86 59
 																int reg_dest = get_reg_write($2, &added_instruction);
87 60
 																add_instruction(CPY, reg_dest, reg_src, 0);
88 61
 																new_instruction(added_instruction + 1);};
89
-Instruction : tAFCA tNB tNB     {increment_time();
90
-																int added_instruction = 0;
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
-																unlink($2);
95
-																new_instruction(added_instruction + 2);};
96
-
97
-
98
-Instruction : tJMP tNB         {increment_time();
99
-																add_instruction(JMP, $2, 0, 0);
100
-																new_instruction(1);};
101
-Instruction : tJMF tNB tNB     {increment_time();
102
-																int added_instruction = 0;
103
-																int reg_src = get_reg_read($2, &added_instruction);
104
-																int reg_aux = get_reg_write(-1, &added_instruction);
105
-																add_instruction(SUB, reg_aux, reg_aux, reg_src);
106
-																add_instruction(JMZ, $3, 0, 0);
107
-																new_instruction(added_instruction + 2);};
108
-
109
-Instruction : tREAD tNB tNB      {increment_time();
110
-																int added_instruction = 0;
111
-																int reg_addr = get_reg_read($3, &added_instruction);
112
-																int reg_dest = get_reg_write($2, &added_instruction);
113
-																add_instruction(LOADI, reg_dest, reg_addr, 0);
114
-																new_instruction(added_instruction + 1);};
115
-Instruction : tWR tNB tNB    {increment_time();
116
-																int added_instruction = 0;
117
-																int reg_addr = get_reg_read($2, &added_instruction);
118
-																int reg_value = get_reg_read($3, &added_instruction);
119
-																add_instruction(STOREI, reg_addr, reg_value, 0);
120
-																new_instruction(added_instruction + 1);};
121
-
122
-
123
-Instruction : tGET tNB         {increment_time();
124
-																int added_instruction = 0;
125
-																int reg_dest = get_reg_write($2, &added_instruction);
126
-																add_instruction(GET, reg_dest, 0, 0);
127
-																new_instruction(added_instruction + 1);};
128
-Instruction : tPRI tNB         {increment_time();
129
-																int added_instruction = 0;
130
-																int reg_src = get_reg_read($2, &added_instruction);
131
-																add_instruction(PRI, reg_src, 0, 0);
132
-																new_instruction(added_instruction + 1);};
133
-
134
-
135
-Instruction : tCALL tNB tNB    {increment_time();
136
-																int added_instruction = flush_and_init(file);
137
-																add_instruction(CALL, $2, $3, 0);
138
-																new_instruction(added_instruction + 1);};
139
-Instruction : tRET             {increment_time();
140
-																int added_instruction = flush_and_init(file);
141
-																add_instruction(RET, 0, 0, 0);
142
-																new_instruction(added_instruction + 1);};
143
-
144
-Instruction : tSTOP tNB         {increment_time();
145
-																add_instruction(STOP, $2, 0, 0);
146
-																new_instruction(1);};
147 62
 
148 63
 %%
149 64
 
150 65
 int main(void) {
151 66
 	file = fopen("output.asm", "w");
152
-	file2 = fopen("output.bin", "w");
67
+	file2 = fopen("output_bin.txt", "w");
153 68
   init();
154 69
 	yyparse();
70
+  flush_and_init();
155 71
 	write_asm(file);
156
-	write_code_machine_compact(file2);
72
+	write_code_machine(file2);
157 73
 	return 0;
158 74
 }

+ 9
- 0
input.asm View File

@@ -0,0 +1,9 @@
1
+AFC 99 2
2
+COP 0 99
3
+AFC 98 3
4
+AFC 97 3
5
+ADD 96 98 97
6
+ADD 95 96 0
7
+COP 1 95
8
+AFC 94 3
9
+COP 0 94

+ 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


+ 29
- 49
tables.c View File

@@ -12,11 +12,12 @@
12 12
 */
13 13
 
14 14
 #include "tables.h"
15
-#define NB_REG 4
16
-#define MEM_SIZE 16
17
-#define NB_INSTRUCTIONS 128
18
-#define MEM_INST_SIZE 128
19
-#define NB_BITS_INSTRUCTION 5
15
+#include <stdlib.h>
16
+#define NB_REG 16
17
+#define MEM_SIZE 256
18
+#define NB_INSTRUCTIONS 256
19
+#define MEM_INST_SIZE 256
20
+#define NB_BITS_INSTRUCTION 8
20 21
 #define NB_BITS 8
21 22
 
22 23
 int traduction_JMP[NB_INSTRUCTIONS];
@@ -40,53 +41,29 @@ void add_instruction(enum instruction_t inst, int param1, int param2, int param3
40 41
 void write_asm(FILE * file) {
41 42
 	int i = 0;
42 43
 	while (i<MEM_INST_SIZE) {
44
+        printf("Writing instruction: %d\n", buffer[i].instruction);
43 45
 		if (buffer[i].instruction == ADD) {
44 46
 			fprintf(file, "ADD %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
47
+		} else if (buffer[i].instruction == NOP) {
48
+			fprintf(file, "NOP 0 0 0\n");
45 49
 		} else if (buffer[i].instruction == SUB) {
46 50
 			fprintf(file, "SUB %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
47 51
 		} else if (buffer[i].instruction == MUL) {
48 52
 			fprintf(file, "MUL %d %d %d\n", buffer[i].param1, buffer[i].param2, buffer[i].param3);
49 53
 		} else if (buffer[i].instruction == DIV) {
50 54
 			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 55
 		} else if (buffer[i].instruction == AFC) {
59 56
 			fprintf(file, "AFC %d %d\n", buffer[i].param1, buffer[i].param2);
60 57
 		} else if (buffer[i].instruction == CPY) {
61 58
 			fprintf(file, "CPY %d %d\n", buffer[i].param1, buffer[i].param2);
62
-
63 59
 		} else if (buffer[i].instruction == LOAD) {
64 60
 			fprintf(file, "LOAD %d %d\n", buffer[i].param1, buffer[i].param2);
65 61
 		} else if (buffer[i].instruction == STORE) {
66 62
 			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
-		} 
63
+        } else {
64
+            printf("Error: unexpected instruction: %d\n", buffer[i].instruction);
65
+            exit(1);
66
+        }
90 67
 		i++;
91 68
 	}
92 69
 }
@@ -109,43 +86,46 @@ void convert_to_binary_on_N(int value, int N, char * buff) {
109 86
 	buff[N] = '\0';
110 87
 }
111 88
 
112
-void write_instruction_binary(FILE * file, struct str_instruction instr, char compact) {
89
+void write_instruction_binary(FILE * file, struct str_instruction instr, int compact, int printSeparator) {
113 90
 	char buff1[33];
114 91
 	char buff2[33];
115 92
 	char buff3[33];
116 93
 	char buff4[33];
117 94
 	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
-	}
95
+
96
+	convert_to_binary_on_N(instr.param1, NB_BITS, buff2);
97
+	
123 98
 	convert_to_binary_on_N(instr.param2, NB_BITS, buff3);
124 99
 	convert_to_binary_on_N(instr.param3, NB_BITS, buff4);
125 100
 	if (compact) {
126 101
 		fprintf(file, "%s%s%s%s", buff1, buff2, buff3, buff4);
127 102
 	} else {
128
-		fprintf(file, "\"%s%s%s%s\" & ", buff1, buff2, buff3, buff4);
103
+		fprintf(file, "\"%s%s%s%s\"", buff1, buff2, buff3, buff4);
104
+        if (printSeparator) {
105
+            fprintf(file, ", ");
106
+        }
129 107
 	}
130 108
 }
131 109
 
132 110
 
133 111
 void write_code_machine(FILE * file) {
134 112
 	int i = MEM_INST_SIZE - 1;
135
-	while (i>=0) {
136
-		write_instruction_binary(file, buffer[i], 0);
113
+    fprintf(file, "signal memory: MEMORY_TYPE := (");
114
+	while (i >= 0) {
115
+		write_instruction_binary(file, buffer[i], 0, i != 0);
137 116
 		i--;
138 117
 	}
118
+    fprintf(file, ");");
139 119
 }
140 120
 
141 121
 void write_code_machine_compact(FILE * file) {
142
-	printf(file, "\"");
122
+	fprintf(file, "\"");
143 123
 	int i = MEM_INST_SIZE - 1;
144
-	while (i>=0) {
145
-		write_instruction_binary(file, buffer[i], 1);
124
+	while (i >= 0) {
125
+		write_instruction_binary(file, buffer[i], 1, 0);
146 126
 		i--;
147 127
 	}
148
-	printf(file, "\"\n");
128
+	fprintf(file, "\"\n");
149 129
 }
150 130
 
151 131
 

+ 1
- 1
tables.h View File

@@ -18,7 +18,7 @@
18 18
 #include <stdint.h>
19 19
 #include <stdio.h>
20 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};
21
+enum instruction_t {NOP, ADD, MUL, SUB, DIV, CPY, AFC, LOAD, STORE};
22 22
 
23 23
 void init(void);
24 24
 void print();

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