diff --git a/as.tab.c b/as.tab.c index bef2ea1..f5c4a00 100644 --- a/as.tab.c +++ b/as.tab.c @@ -456,7 +456,7 @@ static const yytype_uint8 yyrline[] = { 0, 24, 24, 25, 27, 34, 41, 48, 55, 62, 69, 78, 83, 89, 98, 101, 109, 115, 123, 128, - 135, 141, 146 + 135, 139, 144 }; #endif @@ -1441,33 +1441,31 @@ yyreduce: case 20: #line 135 "as.y" /* yacc.c:1646 */ {increment_time(); - print(); int added_instruction = flush_and_init(file); - print(); add_instruction(CALL, (yyvsp[-1].nombre), (yyvsp[0].nombre), 0); new_instruction(added_instruction + 1);} -#line 1450 "as.tab.c" /* yacc.c:1646 */ +#line 1448 "as.tab.c" /* yacc.c:1646 */ break; case 21: -#line 141 "as.y" /* yacc.c:1646 */ +#line 139 "as.y" /* yacc.c:1646 */ {increment_time(); int added_instruction = flush_and_init(file); add_instruction(RET, 0, 0, 0); new_instruction(added_instruction + 1);} -#line 1459 "as.tab.c" /* yacc.c:1646 */ +#line 1457 "as.tab.c" /* yacc.c:1646 */ break; case 22: -#line 146 "as.y" /* yacc.c:1646 */ +#line 144 "as.y" /* yacc.c:1646 */ {increment_time(); add_instruction(STOP, (yyvsp[0].nombre), 0, 0); new_instruction(1);} -#line 1467 "as.tab.c" /* yacc.c:1646 */ +#line 1465 "as.tab.c" /* yacc.c:1646 */ break; -#line 1471 "as.tab.c" /* yacc.c:1646 */ +#line 1469 "as.tab.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1695,16 +1693,15 @@ yyreturn: #endif return yyresult; } -#line 150 "as.y" /* yacc.c:1906 */ +#line 148 "as.y" /* yacc.c:1906 */ int main(void) { file = fopen("output.asm", "w"); file2 = fopen("output.bin", "w"); - file = stdout; init(); yyparse(); write_asm(file); - write_code_machine(file2); + write_code_machine_compact(file2); return 0; } diff --git a/as.tab.o b/as.tab.o index a3caabd..8456aab 100644 Binary files a/as.tab.o and b/as.tab.o differ diff --git a/as.y b/as.y index d938ea7..0cc9995 100644 --- a/as.y +++ b/as.y @@ -133,9 +133,7 @@ Instruction : tPRI tNB {increment_time(); Instruction : tCALL tNB tNB {increment_time(); - print(); int added_instruction = flush_and_init(file); - print(); add_instruction(CALL, $2, $3, 0); new_instruction(added_instruction + 1);}; Instruction : tRET {increment_time(); @@ -152,10 +150,9 @@ Instruction : tSTOP tNB {increment_time(); int main(void) { file = fopen("output.asm", "w"); file2 = fopen("output.bin", "w"); - file = stdout; init(); yyparse(); write_asm(file); - write_code_machine(file2); + write_code_machine_compact(file2); return 0; } diff --git a/output.asm b/output.asm index e69de29..4262c76 100644 --- a/output.asm +++ b/output.asm @@ -0,0 +1,84 @@ +JMP 48 +AFC 0 1 +LOAD 1 0 +CPY 2 1 +AFC 3 1 +MUL 0 3 0 +ADD 0 2 0 +LOADI 0 0 +PRI 0 +AFC 0 0 +CPY 2 1 +AFC 3 1 +MUL 0 3 0 +ADD 0 2 0 +AFC 2 14 +STOREI 0 2 +AFC 0 2 +CPY 1 0 +STORE 0 1 +STORE 1 0 +STORE 2 2 +STORE 3 3 +RET +AFC 0 0 +LOAD 1 0 +CPY 2 1 +AFC 3 1 +MUL 0 3 0 +ADD 0 2 0 +LOADI 0 0 +PRI 0 +AFC 0 1 +CPY 2 1 +AFC 3 1 +MUL 0 3 0 +ADD 0 2 0 +AFC 2 10 +STOREI 0 2 +CPY 0 1 +STORE 1 0 +STORE 2 2 +STORE 3 3 +CALL 1 1 +AFC 0 1 +CPY 1 0 +STORE 0 1 +STORE 1 0 +RET +AFC 0 0 +AFC 1 0 +STOREA 3 1 +AFC 1 1 +MUL 0 1 0 +LOAD 2 3 +ADD 0 2 0 +AFC 3 1 +STOREI 0 3 +AFC 2 1 +STORE 5 1 +AFC 1 0 +STOREA 4 1 +AFC 1 1 +MUL 2 1 2 +STORE 2 0 +LOAD 0 4 +ADD 2 0 2 +AFC 3 12 +STOREI 2 3 +STORE 6 1 +AFC 1 0 +STOREA 4 1 +STORE 3 2 +STORE 5 3 +CALL 23 4 +AFC 0 0 +AFC 1 0 +STOREA 5 1 +AFC 1 1 +MUL 0 1 0 +LOAD 2 5 +ADD 0 2 0 +LOADI 0 0 +PRI 0 +STOP 0 diff --git a/output.bin b/output.bin index a214a39..1d3fc57 100644 --- a/output.bin +++ b/output.bin @@ -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" & "10101000000000000000000000000" & "10001000000000000000000000000" & "01100000000000000000000000000" & "00001000000000000001000000000" & "01010000000100000010100000000" & "00010000000000000000100000000" & "01001000000010000000100000000" & "01110000001010000000100000000" & "01001000000010000000000000000" & "01001000000000000000000000000" & "10011000101110000010000000000" & "01011000001010000001100000000" & "01011000000110000001000000000" & "01110000001000000000100000000" & "01001000000010000000000000000" & "01011000001100000000100000000" & "01101000000100000001100000000" & "01001000000110000110000000000" & "00001000000100000000000000010" & "01010000000000000010000000000" & "01011000000100000000000000000" & "00010000000100000000100000010" & "01001000000010000000100000000" & "01110000001000000000100000000" & "01001000000010000000000000000" & "01011000001010000000100000000" & "01001000000100000000100000000" & "01101000000000000001100000000" & "01001000000110000000100000000" & "00001000000000000001000000000" & "01010000000100000001100000000" & "00010000000000000000100000000" & "01001000000010000000100000000" & "01110000000110000000100000000" & "01001000000010000000000000000" & "01001000000000000000000000000" & "10100000000000000000000000000" & "01011000000010000000000000000" & "01011000000000000000100000000" & "01000000000010000000000000000" & "01001000000000000000100000000" & "10011000000010000000100000000" & "01011000000110000001100000000" & "01011000000100000001000000000" & "01011000000010000000000000000" & "01000000000000000000100000000" & "01101000000000000001000000000" & "01001000000100000101000000000" & "00001000000000000001000000000" & "00010000000000000001100000000" & "01001000000110000000100000000" & "01000000000100000000100000000" & "01001000000000000000100000000" & "10001000000000000000000000000" & "01100000000000000000000000000" & "00001000000000000001000000000" & "00010000000000000001100000000" & "01001000000110000000100000000" & "01000000000100000000100000000" & "01010000000010000000000000000" & "01001000000000000000000000000" & "10100000000000000000000000000" & "01011000000110000001100000000" & "01011000000100000001000000000" & "01011000000010000000000000000" & "01011000000000000000100000000" & "01000000000010000000000000000" & "01001000000000000001000000000" & "01101000000000000001000000000" & "01001000000100000111000000000" & "00001000000000000001000000000" & "00010000000000000001100000000" & "01001000000110000000100000000" & "01000000000100000000100000000" & "01001000000000000000000000000" & "10001000000000000000000000000" & "01100000000000000000000000000" & "00001000000000000001000000000" & "00010000000000000001100000000" & "01001000000110000000100000000" & "01000000000100000000100000000" & "01010000000010000000000000000" & "01001000000000000000100000000" & "01111001100000000000000000000" & \ No newline at end of file +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101010000000000000000000000001000100000000000000000000000001100000000000000000000000000000010000000000000010000000000101000000010000001010000000000010000000000000000100000000010010000000100000001000000000111000000101000000010000000001001000000010000000000000000010010000000000000000000000001001100010111000001000000000001011000001010000001100000000010110000001100000010000000000111000000100000000010000000001001000000010000000000000000010110000011000000001000000000110100000010000000110000000001001000000110000110000000000000010000001000000000000000100101000000000000001000000000001011000000100000000000000000000100000001000000001000000100100100000001000000010000000001110000001000000000100000000010010000000100000000000000000101100000101000000010000000001001000000100000000100000000011010000000000000011000000000100100000011000000010000000000001000000000000001000000000010100000001000000011000000000001000000000000000010000000001001000000010000000100000000011100000001100000001000000000100100000001000000000000000001001000000000000000000000000101000000000000000000000000000101100000001000000000000000001011000000000000000100000000010000000000100000000000000000100100000000000000010000000010011000000010000000100000000010110000001100000011000000000101100000010000000100000000001011000000010000000000000000010000000000000000001000000000110100000000000000100000000001001000000100000101000000000000010000000000000010000000000001000000000000000110000000001001000000110000000100000000010000000001000000001000000000100100000000000000010000000010001000000000000000000000000011000000000000000000000000000000100000000000000100000000000010000000000000001100000000010010000001100000001000000000100000000010000000010000000001010000000010000000000000000010010000000000000000000000001010000000000000000000000000001011000000110000001100000000010110000001000000010000000000101100000001000000000000000001011000000000000000100000000010000000000100000000000000000100100000000000000100000000001101000000000000001000000000010010000001000001110000000000000100000000000000100000000000010000000000000001100000000010010000001100000001000000000100000000010000000010000000001001000000000000000000000000100010000000000000000000000000110000000000000000000000000000001000000000000001000000000000100000000000000011000000000100100000011000000010000000001000000000100000000100000000010100000000100000000000000000100100000000000000010000000001111001100000000000000000000 \ No newline at end of file diff --git a/rondoudou_cross_assembleur b/rondoudou_cross_assembleur index 1f084e3..1bd0599 100755 Binary files a/rondoudou_cross_assembleur and b/rondoudou_cross_assembleur differ diff --git a/tables.c b/tables.c index e272fb6..10f0c9d 100644 --- a/tables.c +++ b/tables.c @@ -109,7 +109,7 @@ void convert_to_binary_on_N(int value, int N, char * buff) { buff[N] = '\0'; } -void write_instruction_binary(FILE * file, struct str_instruction instr) { +void write_instruction_binary(FILE * file, struct str_instruction instr, char compact) { char buff1[33]; char buff2[33]; char buff3[33]; @@ -122,18 +122,32 @@ void write_instruction_binary(FILE * file, struct str_instruction instr) { } convert_to_binary_on_N(instr.param2, NB_BITS, buff3); convert_to_binary_on_N(instr.param3, NB_BITS, buff4); - fprintf(file, "\"%s%s%s%s\" & ", buff1, buff2, buff3, buff4); + if (compact) { + fprintf(file, "%s%s%s%s", buff1, buff2, buff3, buff4); + } else { + fprintf(file, "\"%s%s%s%s\" & ", buff1, buff2, buff3, buff4); + } } void write_code_machine(FILE * file) { int i = MEM_INST_SIZE - 1; while (i>=0) { - write_instruction_binary(file, buffer[i]); + write_instruction_binary(file, buffer[i], 0); i--; } } +void write_code_machine_compact(FILE * file) { + printf(file, "\""); + int i = MEM_INST_SIZE - 1; + while (i>=0) { + write_instruction_binary(file, buffer[i], 1); + i--; + } + printf(file, "\"\n"); +} + struct case_adresse { int adresse; diff --git a/tables.o b/tables.o index 1d4ba25..e8b1ecf 100644 Binary files a/tables.o and b/tables.o differ