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