Rev 624 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 624 | Rev 992 | ||
---|---|---|---|
1 | ; flat assembler core |
1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2007, Tomasz Grysztar. |
2 | ; Copyright (c) 1999-2007, Tomasz Grysztar. |
3 | ; All rights reserved. |
3 | ; All rights reserved. |
4 | 4 | ||
5 | parser: |
5 | parser: |
6 | mov eax,[memory_end] |
6 | mov eax,[memory_end] |
7 | mov [labels_list],eax |
7 | mov [labels_list],eax |
8 | mov eax,[additional_memory] |
8 | mov eax,[additional_memory] |
9 | mov [free_additional_memory],eax |
9 | mov [free_additional_memory],eax |
10 | xor eax,eax |
10 | xor eax,eax |
11 | mov [current_locals_prefix],eax |
11 | mov [current_locals_prefix],eax |
12 | mov [anonymous_reverse],eax |
12 | mov [anonymous_reverse],eax |
13 | mov [anonymous_forward],eax |
13 | mov [anonymous_forward],eax |
14 | mov [hash_tree],eax |
14 | mov [hash_tree],eax |
15 | mov [blocks_stack],eax |
15 | mov [blocks_stack],eax |
16 | mov [parsed_lines],eax |
16 | mov [parsed_lines],eax |
17 | mov esi,[memory_start] |
17 | mov esi,[memory_start] |
18 | mov edi,[source_start] |
18 | mov edi,[source_start] |
19 | parser_loop: |
19 | parser_loop: |
20 | mov [current_line],esi |
20 | mov [current_line],esi |
21 | lea eax,[edi+100h] |
21 | lea eax,[edi+100h] |
22 | cmp eax,[labels_list] |
22 | cmp eax,[labels_list] |
23 | jae out_of_memory |
23 | jae out_of_memory |
24 | cmp byte [esi+16],0 |
24 | cmp byte [esi+16],0 |
25 | je empty_line |
25 | je empty_line |
26 | mov al,0Fh |
26 | cmp byte [esi+16],3Bh |
- | 27 | je empty_line |
|
- | 28 | mov al,0Fh |
|
27 | stos byte [edi] |
29 | stos byte [edi] |
28 | mov eax,esi |
30 | mov eax,esi |
29 | stos dword [edi] |
31 | stos dword [edi] |
30 | inc [parsed_lines] |
32 | inc [parsed_lines] |
31 | add esi,16 |
33 | add esi,16 |
32 | parse_line: |
34 | parse_line: |
33 | cmp byte [esi],1Ah |
35 | cmp byte [esi],1Ah |
34 | jne empty_instruction |
36 | jne empty_instruction |
35 | push edi |
37 | push edi |
36 | add esi,2 |
38 | add esi,2 |
37 | movzx ecx,byte [esi-1] |
39 | movzx ecx,byte [esi-1] |
38 | cmp byte [esi+ecx],':' |
40 | cmp byte [esi+ecx],':' |
39 | je simple_label |
41 | je simple_label |
40 | cmp byte [esi+ecx],'=' |
42 | cmp byte [esi+ecx],'=' |
41 | je constant_label |
43 | je constant_label |
42 | call get_instruction |
44 | call get_instruction |
43 | jnc main_instruction_identified |
45 | jnc main_instruction_identified |
44 | cmp byte [esi+ecx],1Ah |
46 | cmp byte [esi+ecx],1Ah |
45 | jne no_data_label |
47 | jne no_data_label |
46 | push esi ecx |
48 | push esi ecx |
47 | lea esi,[esi+ecx+2] |
49 | lea esi,[esi+ecx+2] |
48 | movzx ecx,byte [esi-1] |
50 | movzx ecx,byte [esi-1] |
49 | call get_data_directive |
51 | call get_data_directive |
50 | jnc data_label |
52 | jnc data_label |
51 | pop ecx esi |
53 | pop ecx esi |
52 | no_data_label: |
54 | no_data_label: |
53 | call get_data_directive |
55 | call get_data_directive |
54 | jnc main_instruction_identified |
56 | jnc main_instruction_identified |
55 | pop edi |
57 | pop edi |
56 | sub esi,2 |
58 | sub esi,2 |
57 | xor bx,bx |
59 | xor bx,bx |
58 | call parse_line_contents |
60 | call parse_line_contents |
59 | jmp parse_next_line |
61 | jmp parse_next_line |
60 | simple_label: |
62 | simple_label: |
61 | pop edi |
63 | pop edi |
62 | call identify_label |
64 | call identify_label |
63 | mov byte [edi],2 |
65 | mov byte [edi],2 |
64 | inc edi |
66 | inc edi |
65 | stos dword [edi] |
67 | stos dword [edi] |
66 | inc esi |
68 | inc esi |
67 | xor al,al |
69 | xor al,al |
68 | stos byte [edi] |
70 | stos byte [edi] |
69 | jmp parse_line |
71 | jmp parse_line |
70 | constant_label: |
72 | constant_label: |
71 | pop edi |
73 | pop edi |
72 | call get_label_id |
74 | call get_label_id |
73 | mov byte [edi],3 |
75 | mov byte [edi],3 |
74 | inc edi |
76 | inc edi |
75 | stos dword [edi] |
77 | stos dword [edi] |
76 | xor al,al |
78 | xor al,al |
77 | stos byte [edi] |
79 | stos byte [edi] |
78 | inc esi |
80 | inc esi |
79 | xor bx,bx |
81 | xor bx,bx |
80 | call parse_line_contents |
82 | call parse_line_contents |
81 | jmp parse_next_line |
83 | jmp parse_next_line |
82 | data_label: |
84 | data_label: |
83 | pop ecx edx |
85 | pop ecx edx |
84 | pop edi |
86 | pop edi |
85 | push eax ebx esi |
87 | push eax ebx esi |
86 | mov esi,edx |
88 | mov esi,edx |
87 | movzx ecx,byte [esi-1] |
89 | movzx ecx,byte [esi-1] |
88 | call identify_label |
90 | call identify_label |
89 | mov byte [edi],2 |
91 | mov byte [edi],2 |
90 | inc edi |
92 | inc edi |
91 | stos dword [edi] |
93 | stos dword [edi] |
92 | pop esi ebx eax |
94 | pop esi ebx eax |
93 | stos byte [edi] |
95 | stos byte [edi] |
94 | push edi |
96 | push edi |
95 | main_instruction_identified: |
97 | main_instruction_identified: |
96 | pop edi |
98 | pop edi |
97 | mov dl,al |
99 | mov dl,al |
98 | mov al,1 |
100 | mov al,1 |
99 | stos byte [edi] |
101 | stos byte [edi] |
100 | mov ax,bx |
102 | mov ax,bx |
101 | stos word [edi] |
103 | stos word [edi] |
102 | mov al,dl |
104 | mov al,dl |
103 | stos byte [edi] |
105 | stos byte [edi] |
104 | cmp bx,if_directive-assembler |
106 | cmp bx,if_directive-assembler |
105 | je parse_block |
107 | je parse_block |
106 | cmp bx,repeat_directive-assembler |
108 | cmp bx,repeat_directive-assembler |
107 | je parse_block |
109 | je parse_block |
108 | cmp bx,while_directive-assembler |
110 | cmp bx,while_directive-assembler |
109 | je parse_block |
111 | je parse_block |
110 | cmp bx,end_directive-assembler |
112 | cmp bx,end_directive-assembler |
111 | je parse_end_directive |
113 | je parse_end_directive |
112 | cmp bx,else_directive-assembler |
114 | cmp bx,else_directive-assembler |
113 | je parse_else |
115 | je parse_else |
114 | common_parse: |
116 | common_parse: |
115 | call parse_line_contents |
117 | call parse_line_contents |
116 | jmp parse_next_line |
118 | jmp parse_next_line |
117 | empty_instruction: |
119 | empty_instruction: |
118 | lods byte [esi] |
120 | lods byte [esi] |
119 | or al,al |
121 | or al,al |
120 | jz parse_next_line |
122 | jz parse_next_line |
121 | cmp al,':' |
123 | cmp al,':' |
122 | je invalid_name |
124 | je invalid_name |
123 | cmp al,3Bh |
125 | dec esi |
124 | je skip_preprocessed_symbol |
- | |
125 | dec esi |
- | |
126 | call parse_argument |
126 | cmp al,3Bh |
- | 127 | je skip_rest_of_line |
|
- | 128 | call parse_argument |
|
127 | jmp parse_next_line |
129 | jmp parse_next_line |
128 | skip_preprocessed_symbol: |
130 | empty_line: |
129 | lods byte [esi] |
- | |
130 | movzx eax,al |
- | |
131 | add esi,eax |
- | |
132 | skip_next: |
- | |
133 | lods byte [esi] |
- | |
134 | or al,al |
- | |
135 | jz parse_next_line |
- | |
136 | cmp al,1Ah |
- | |
137 | je skip_preprocessed_symbol |
- | |
138 | cmp al,3Bh |
- | |
139 | je skip_preprocessed_symbol |
- | |
140 | cmp al,22h |
- | |
141 | je skip_preprocessed_string |
- | |
142 | jmp skip_next |
- | |
143 | skip_preprocessed_string: |
- | |
144 | lods dword [esi] |
- | |
145 | add esi,eax |
- | |
146 | jmp skip_next |
- | |
147 | empty_line: |
- | |
148 | add esi,17 |
131 | add esi,16 |
149 | parse_next_line: |
132 | skip_rest_of_line: |
- | 133 | call skip_foreign_line |
|
- | 134 | parse_next_line: |
|
150 | cmp esi,[source_start] |
135 | cmp esi,[source_start] |
151 | jb parser_loop |
136 | jb parser_loop |
152 | source_parsed: |
137 | source_parsed: |
153 | cmp [blocks_stack],0 |
138 | cmp [blocks_stack],0 |
154 | je blocks_stack_ok |
139 | je blocks_stack_ok |
155 | pop eax |
140 | pop eax |
156 | pop [current_line] |
141 | pop [current_line] |
157 | jmp missing_end_directive |
142 | jmp missing_end_directive |
158 | blocks_stack_ok: |
143 | blocks_stack_ok: |
159 | xor al,al |
144 | xor al,al |
160 | stos byte [edi] |
145 | stos byte [edi] |
161 | ;mov eax,[error_line] |
146 | add edi,0Fh |
162 | ;mov [current_line],eax |
- | |
163 | ;cmp [anonymous_forward],0 |
- | |
164 | ;jne invalid_value |
- | |
165 | add edi,0Fh |
- | |
166 | and edi,not 0Fh |
147 | and edi,not 0Fh |
167 | mov [code_start],edi |
148 | mov [code_start],edi |
168 | ret |
149 | ret |
169 | parse_block: |
150 | parse_block: |
170 | mov eax,esp |
151 | mov eax,esp |
171 | sub eax,100h |
152 | sub eax,100h |
172 | jc stack_overflow |
153 | jc stack_overflow |
173 | cmp eax,[stack_limit] |
154 | cmp eax,[stack_limit] |
174 | jb stack_overflow |
155 | jb stack_overflow |
175 | push [current_line] |
156 | push [current_line] |
176 | mov ax,bx |
157 | mov ax,bx |
177 | shl eax,16 |
158 | shl eax,16 |
178 | push eax |
159 | push eax |
179 | inc [blocks_stack] |
160 | inc [blocks_stack] |
180 | cmp bx,if_directive-assembler |
161 | cmp bx,if_directive-assembler |
181 | je parse_if |
162 | je parse_if |
182 | cmp bx,while_directive-assembler |
163 | cmp bx,while_directive-assembler |
183 | je parse_while |
164 | je parse_while |
184 | call parse_line_contents |
165 | call parse_line_contents |
185 | jmp parse_next_line |
166 | jmp parse_next_line |
186 | parse_end_directive: |
167 | parse_end_directive: |
187 | cmp byte [esi],1Ah |
168 | cmp byte [esi],1Ah |
188 | jne common_parse |
169 | jne common_parse |
189 | push edi |
170 | push edi |
190 | inc esi |
171 | inc esi |
191 | movzx ecx,byte [esi] |
172 | movzx ecx,byte [esi] |
192 | inc esi |
173 | inc esi |
193 | call get_instruction |
174 | call get_instruction |
194 | pop edi |
175 | pop edi |
195 | jnc parse_end_block |
176 | jnc parse_end_block |
196 | sub esi,2 |
177 | sub esi,2 |
197 | jmp common_parse |
178 | jmp common_parse |
198 | parse_end_block: |
179 | parse_end_block: |
199 | mov dl,al |
180 | mov dl,al |
200 | mov al,1 |
181 | mov al,1 |
201 | stos byte [edi] |
182 | stos byte [edi] |
202 | mov ax,bx |
183 | mov ax,bx |
203 | stos word [edi] |
184 | stos word [edi] |
204 | mov al,dl |
185 | mov al,dl |
205 | stos byte [edi] |
186 | stos byte [edi] |
206 | lods byte [esi] |
187 | lods byte [esi] |
207 | or al,al |
188 | or al,al |
208 | jnz extra_characters_on_line |
189 | jnz extra_characters_on_line |
209 | cmp bx,if_directive-assembler |
190 | cmp bx,if_directive-assembler |
210 | je close_parsing_block |
191 | je close_parsing_block |
211 | cmp bx,repeat_directive-assembler |
192 | cmp bx,repeat_directive-assembler |
212 | je close_parsing_block |
193 | je close_parsing_block |
213 | cmp bx,while_directive-assembler |
194 | cmp bx,while_directive-assembler |
214 | je close_parsing_block |
195 | je close_parsing_block |
215 | jmp parse_next_line |
196 | jmp parse_next_line |
216 | close_parsing_block: |
197 | close_parsing_block: |
217 | cmp [blocks_stack],0 |
198 | cmp [blocks_stack],0 |
218 | je unexpected_instruction |
199 | je unexpected_instruction |
219 | cmp bx,[esp+2] |
200 | cmp bx,[esp+2] |
220 | jne unexpected_instruction |
201 | jne unexpected_instruction |
221 | dec [blocks_stack] |
202 | dec [blocks_stack] |
222 | pop eax edx |
203 | pop eax edx |
223 | cmp bx,if_directive-assembler |
204 | cmp bx,if_directive-assembler |
224 | jne parse_next_line |
205 | jne parse_next_line |
225 | test al,1100b |
206 | test al,1100b |
226 | jz parse_next_line |
207 | jz parse_next_line |
227 | test al,10000b |
208 | test al,10000b |
228 | jnz parse_next_line |
209 | jnz parse_next_line |
229 | sub edi,8 |
210 | sub edi,8 |
230 | jmp parse_next_line |
211 | jmp parse_next_line |
231 | parse_if: |
212 | parse_if: |
232 | push edi |
213 | push edi |
233 | call parse_line_contents |
214 | call parse_line_contents |
234 | xor al,al |
215 | xor al,al |
235 | stos byte [edi] |
216 | stos byte [edi] |
236 | xchg esi,[esp] |
217 | xchg esi,[esp] |
237 | mov edi,esi |
218 | mov edi,esi |
238 | call preevaluate_logical_expression |
219 | call preevaluate_logical_expression |
239 | pop esi |
220 | pop esi |
240 | cmp al,'0' |
221 | cmp al,'0' |
241 | je parse_false_condition_block |
222 | je parse_false_condition_block |
242 | cmp al,'1' |
223 | cmp al,'1' |
243 | je parse_true_condition_block |
224 | je parse_true_condition_block |
244 | or byte [esp],10000b |
225 | or byte [esp],10000b |
245 | jmp parse_next_line |
226 | jmp parse_next_line |
246 | parse_while: |
227 | parse_while: |
247 | push edi |
228 | push edi |
248 | call parse_line_contents |
229 | call parse_line_contents |
249 | xor al,al |
230 | xor al,al |
250 | stos byte [edi] |
231 | stos byte [edi] |
251 | xchg esi,[esp] |
232 | xchg esi,[esp] |
252 | mov edi,esi |
233 | mov edi,esi |
253 | call preevaluate_logical_expression |
234 | call preevaluate_logical_expression |
254 | pop esi |
235 | pop esi |
255 | cmp al,'0' |
236 | cmp al,'0' |
256 | je parse_false_condition_block |
237 | je parse_false_condition_block |
257 | cmp al,'1' |
238 | cmp al,'1' |
258 | jne parse_next_line |
239 | jne parse_next_line |
259 | stos byte [edi] |
240 | stos byte [edi] |
260 | jmp parse_next_line |
241 | jmp parse_next_line |
261 | parse_false_condition_block: |
242 | parse_false_condition_block: |
262 | or byte [esp],1 |
243 | or byte [esp],1 |
263 | sub edi,4 |
244 | sub edi,4 |
264 | jmp skip_parsing |
245 | jmp skip_parsing |
265 | parse_true_condition_block: |
246 | parse_true_condition_block: |
266 | or byte [esp],100b |
247 | or byte [esp],100b |
267 | sub edi,4 |
248 | sub edi,4 |
268 | jmp parse_next_line |
249 | jmp parse_next_line |
269 | parse_else: |
250 | parse_else: |
270 | cmp [blocks_stack],0 |
251 | cmp [blocks_stack],0 |
271 | je unexpected_instruction |
252 | je unexpected_instruction |
272 | cmp word [esp+2],if_directive-assembler |
253 | cmp word [esp+2],if_directive-assembler |
273 | jne unexpected_instruction |
254 | jne unexpected_instruction |
274 | lods byte [esi] |
255 | lods byte [esi] |
275 | or al,al |
256 | or al,al |
276 | jz parse_pure_else |
257 | jz parse_pure_else |
277 | cmp al,1Ah |
258 | cmp al,1Ah |
278 | jne extra_characters_on_line |
259 | jne extra_characters_on_line |
279 | push edi |
260 | push edi |
280 | movzx ecx,byte [esi] |
261 | movzx ecx,byte [esi] |
281 | inc esi |
262 | inc esi |
282 | call get_instruction |
263 | call get_instruction |
283 | jc extra_characters_on_line |
264 | jc extra_characters_on_line |
284 | pop edi |
265 | pop edi |
285 | cmp bx,if_directive-assembler |
266 | cmp bx,if_directive-assembler |
286 | jne extra_characters_on_line |
267 | jne extra_characters_on_line |
287 | test byte [esp],100b |
268 | test byte [esp],100b |
288 | jnz skip_true_condition_else |
269 | jnz skip_true_condition_else |
289 | mov dl,al |
270 | mov dl,al |
290 | mov al,1 |
271 | mov al,1 |
291 | stos byte [edi] |
272 | stos byte [edi] |
292 | mov ax,bx |
273 | mov ax,bx |
293 | stos word [edi] |
274 | stos word [edi] |
294 | mov al,dl |
275 | mov al,dl |
295 | stos byte [edi] |
276 | stos byte [edi] |
296 | jmp parse_if |
277 | jmp parse_if |
297 | skip_true_condition_else: |
278 | skip_true_condition_else: |
298 | sub edi,4 |
279 | sub edi,4 |
299 | or byte [esp],1 |
280 | or byte [esp],1 |
300 | jmp skip_parsing_contents |
281 | jmp skip_parsing_contents |
301 | parse_pure_else: |
282 | parse_pure_else: |
302 | bts dword [esp],1 |
283 | bts dword [esp],1 |
303 | jc unexpected_instruction |
284 | jc unexpected_instruction |
304 | test byte [esp],100b |
285 | test byte [esp],100b |
305 | jz parse_next_line |
286 | jz parse_next_line |
306 | sub edi,4 |
287 | sub edi,4 |
307 | or byte [esp],1 |
288 | or byte [esp],1 |
308 | jmp skip_parsing |
289 | jmp skip_parsing |
309 | skip_parsing: |
290 | skip_parsing: |
310 | cmp esi,[source_start] |
291 | cmp esi,[source_start] |
311 | jae source_parsed |
292 | jae source_parsed |
312 | mov [current_line],esi |
293 | mov [current_line],esi |
313 | add esi,16 |
294 | add esi,16 |
314 | skip_parsing_line: |
295 | skip_parsing_line: |
315 | cmp byte [esi],1Ah |
296 | cmp byte [esi],1Ah |
316 | jne skip_parsing_contents |
297 | jne skip_parsing_contents |
317 | inc esi |
298 | inc esi |
318 | movzx ecx,byte [esi] |
299 | movzx ecx,byte [esi] |
319 | inc esi |
300 | inc esi |
320 | cmp byte [esi+ecx],':' |
301 | cmp byte [esi+ecx],':' |
321 | je skip_parsing_label |
302 | je skip_parsing_label |
322 | push edi |
303 | push edi |
323 | call get_instruction |
304 | call get_instruction |
324 | pop edi |
305 | pop edi |
325 | jnc skip_parsing_instruction |
306 | jnc skip_parsing_instruction |
326 | add esi,ecx |
307 | add esi,ecx |
327 | jmp skip_parsing_contents |
308 | jmp skip_parsing_contents |
328 | skip_parsing_label: |
309 | skip_parsing_label: |
329 | lea esi,[esi+ecx+1] |
310 | lea esi,[esi+ecx+1] |
330 | jmp skip_parsing_line |
311 | jmp skip_parsing_line |
331 | skip_parsing_instruction: |
312 | skip_parsing_instruction: |
332 | cmp bx,if_directive-assembler |
313 | cmp bx,if_directive-assembler |
333 | je skip_parsing_block |
314 | je skip_parsing_block |
334 | cmp bx,repeat_directive-assembler |
315 | cmp bx,repeat_directive-assembler |
335 | je skip_parsing_block |
316 | je skip_parsing_block |
336 | cmp bx,while_directive-assembler |
317 | cmp bx,while_directive-assembler |
337 | je skip_parsing_block |
318 | je skip_parsing_block |
338 | cmp bx,end_directive-assembler |
319 | cmp bx,end_directive-assembler |
339 | je skip_parsing_end_directive |
320 | je skip_parsing_end_directive |
340 | cmp bx,else_directive-assembler |
321 | cmp bx,else_directive-assembler |
341 | je skip_parsing_else |
322 | je skip_parsing_else |
342 | skip_parsing_contents: |
323 | skip_parsing_contents: |
343 | lods byte [esi] |
324 | lods byte [esi] |
344 | or al,al |
325 | or al,al |
345 | jz skip_parsing |
326 | jz skip_parsing |
346 | cmp al,1Ah |
327 | cmp al,1Ah |
347 | je skip_parsing_symbol |
328 | je skip_parsing_symbol |
348 | cmp al,3Bh |
329 | cmp al,3Bh |
349 | je skip_parsing_symbol |
330 | je skip_parsing_symbol |
350 | cmp al,22h |
331 | cmp al,22h |
351 | je skip_parsing_string |
332 | je skip_parsing_string |
352 | jmp skip_parsing_contents |
333 | jmp skip_parsing_contents |
353 | skip_parsing_symbol: |
334 | skip_parsing_symbol: |
354 | lods byte [esi] |
335 | lods byte [esi] |
355 | movzx eax,al |
336 | movzx eax,al |
356 | add esi,eax |
337 | add esi,eax |
357 | jmp skip_parsing_contents |
338 | jmp skip_parsing_contents |
358 | skip_parsing_string: |
339 | skip_parsing_string: |
359 | lods dword [esi] |
340 | lods dword [esi] |
360 | add esi,eax |
341 | add esi,eax |
361 | jmp skip_parsing_contents |
342 | jmp skip_parsing_contents |
362 | skip_parsing_block: |
343 | skip_parsing_block: |
363 | mov eax,esp |
344 | mov eax,esp |
364 | sub eax,100h |
345 | sub eax,100h |
365 | jc stack_overflow |
346 | jc stack_overflow |
366 | cmp eax,[stack_limit] |
347 | cmp eax,[stack_limit] |
367 | jb stack_overflow |
348 | jb stack_overflow |
368 | push [current_line] |
349 | push [current_line] |
369 | mov ax,bx |
350 | mov ax,bx |
370 | shl eax,16 |
351 | shl eax,16 |
371 | push eax |
352 | push eax |
372 | inc [blocks_stack] |
353 | inc [blocks_stack] |
373 | jmp skip_parsing_contents |
354 | jmp skip_parsing_contents |
374 | skip_parsing_end_directive: |
355 | skip_parsing_end_directive: |
375 | cmp byte [esi],1Ah |
356 | cmp byte [esi],1Ah |
376 | jne skip_parsing_contents |
357 | jne skip_parsing_contents |
377 | push edi |
358 | push edi |
378 | inc esi |
359 | inc esi |
379 | movzx ecx,byte [esi] |
360 | movzx ecx,byte [esi] |
380 | inc esi |
361 | inc esi |
381 | call get_instruction |
362 | call get_instruction |
382 | pop edi |
363 | pop edi |
383 | jnc skip_parsing_end_block |
364 | jnc skip_parsing_end_block |
384 | add esi,ecx |
365 | add esi,ecx |
385 | jmp skip_parsing_contents |
366 | jmp skip_parsing_contents |
386 | skip_parsing_end_block: |
367 | skip_parsing_end_block: |
387 | lods byte [esi] |
368 | lods byte [esi] |
388 | or al,al |
369 | or al,al |
389 | jnz extra_characters_on_line |
370 | jnz extra_characters_on_line |
390 | cmp bx,if_directive-assembler |
371 | cmp bx,if_directive-assembler |
391 | je close_skip_parsing_block |
372 | je close_skip_parsing_block |
392 | cmp bx,repeat_directive-assembler |
373 | cmp bx,repeat_directive-assembler |
393 | je close_skip_parsing_block |
374 | je close_skip_parsing_block |
394 | cmp bx,while_directive-assembler |
375 | cmp bx,while_directive-assembler |
395 | je close_skip_parsing_block |
376 | je close_skip_parsing_block |
396 | jmp skip_parsing |
377 | jmp skip_parsing |
397 | close_skip_parsing_block: |
378 | close_skip_parsing_block: |
398 | cmp [blocks_stack],0 |
379 | cmp [blocks_stack],0 |
399 | je unexpected_instruction |
380 | je unexpected_instruction |
400 | cmp bx,[esp+2] |
381 | cmp bx,[esp+2] |
401 | jne unexpected_instruction |
382 | jne unexpected_instruction |
402 | dec [blocks_stack] |
383 | dec [blocks_stack] |
403 | pop eax edx |
384 | pop eax edx |
404 | test al,1 |
385 | test al,1 |
405 | jz skip_parsing |
386 | jz skip_parsing |
406 | cmp bx,if_directive-assembler |
387 | cmp bx,if_directive-assembler |
407 | jne parse_next_line |
388 | jne parse_next_line |
408 | test al,10000b |
389 | test al,10000b |
409 | jz parse_next_line |
390 | jz parse_next_line |
410 | mov al,0Fh |
391 | mov al,0Fh |
411 | stos byte [edi] |
392 | stos byte [edi] |
412 | mov eax,[current_line] |
393 | mov eax,[current_line] |
413 | stos dword [edi] |
394 | stos dword [edi] |
414 | inc [parsed_lines] |
395 | inc [parsed_lines] |
415 | mov eax,1 + (end_directive-assembler) shl 8 |
396 | mov eax,1 + (end_directive-assembler) shl 8 |
416 | stos dword [edi] |
397 | stos dword [edi] |
417 | mov eax,1 + (if_directive-assembler) shl 8 |
398 | mov eax,1 + (if_directive-assembler) shl 8 |
418 | stos dword [edi] |
399 | stos dword [edi] |
419 | jmp parse_next_line |
400 | jmp parse_next_line |
420 | skip_parsing_else: |
401 | skip_parsing_else: |
421 | cmp [blocks_stack],0 |
402 | cmp [blocks_stack],0 |
422 | je unexpected_instruction |
403 | je unexpected_instruction |
423 | cmp word [esp+2],if_directive-assembler |
404 | cmp word [esp+2],if_directive-assembler |
424 | jne unexpected_instruction |
405 | jne unexpected_instruction |
425 | lods byte [esi] |
406 | lods byte [esi] |
426 | or al,al |
407 | or al,al |
427 | jz skip_parsing_pure_else |
408 | jz skip_parsing_pure_else |
428 | cmp al,1Ah |
409 | cmp al,1Ah |
429 | jne extra_characters_on_line |
410 | jne extra_characters_on_line |
430 | push edi |
411 | push edi |
431 | movzx ecx,byte [esi] |
412 | movzx ecx,byte [esi] |
432 | inc esi |
413 | inc esi |
433 | call get_instruction |
414 | call get_instruction |
434 | jc extra_characters_on_line |
415 | jc extra_characters_on_line |
435 | pop edi |
416 | pop edi |
436 | cmp bx,if_directive-assembler |
417 | cmp bx,if_directive-assembler |
437 | jne extra_characters_on_line |
418 | jne extra_characters_on_line |
438 | mov al,[esp] |
419 | mov al,[esp] |
439 | test al,1 |
420 | test al,1 |
440 | jz skip_parsing_contents |
421 | jz skip_parsing_contents |
441 | test al,100b |
422 | test al,100b |
442 | jnz skip_parsing_contents |
423 | jnz skip_parsing_contents |
443 | test al,10000b |
424 | test al,10000b |
444 | jnz parse_else_if |
425 | jnz parse_else_if |
445 | xor al,al |
426 | xor al,al |
446 | mov [esp],al |
427 | mov [esp],al |
447 | mov al,0Fh |
428 | mov al,0Fh |
448 | stos byte [edi] |
429 | stos byte [edi] |
449 | mov eax,[current_line] |
430 | mov eax,[current_line] |
450 | stos dword [edi] |
431 | stos dword [edi] |
451 | inc [parsed_lines] |
432 | inc [parsed_lines] |
452 | parse_else_if: |
433 | parse_else_if: |
453 | mov eax,1 + (if_directive-assembler) shl 8 |
434 | mov eax,1 + (if_directive-assembler) shl 8 |
454 | stos dword [edi] |
435 | stos dword [edi] |
455 | jmp parse_if |
436 | jmp parse_if |
456 | skip_parsing_pure_else: |
437 | skip_parsing_pure_else: |
457 | bts dword [esp],1 |
438 | bts dword [esp],1 |
458 | jc unexpected_instruction |
439 | jc unexpected_instruction |
459 | mov al,[esp] |
440 | mov al,[esp] |
460 | test al,1 |
441 | test al,1 |
461 | jz skip_parsing |
442 | jz skip_parsing |
462 | test al,100b |
443 | test al,100b |
463 | jnz skip_parsing |
444 | jnz skip_parsing |
464 | and al,not 1 |
445 | and al,not 1 |
465 | or al,1000b |
446 | or al,1000b |
466 | mov [esp],al |
447 | mov [esp],al |
467 | jmp parse_next_line |
448 | jmp parse_next_line |
468 | 449 | ||
469 | parse_line_contents: |
450 | parse_line_contents: |
470 | mov [parenthesis_stack],0 |
451 | mov [parenthesis_stack],0 |
471 | parse_instruction_arguments: |
452 | parse_instruction_arguments: |
472 | cmp bx,prefix_instruction-assembler |
453 | cmp bx,prefix_instruction-assembler |
473 | je allow_embedded_instruction |
454 | je allow_embedded_instruction |
474 | cmp bx,times_directive-assembler |
455 | cmp bx,times_directive-assembler |
475 | je parse_times_directive |
456 | je parse_times_directive |
476 | cmp bx,end_directive-assembler |
457 | cmp bx,end_directive-assembler |
477 | je allow_embedded_instruction |
458 | je allow_embedded_instruction |
478 | cmp bx,label_directive-assembler |
459 | cmp bx,label_directive-assembler |
479 | je parse_label_directive |
460 | je parse_label_directive |
480 | cmp bx,segment_directive-assembler |
461 | cmp bx,segment_directive-assembler |
481 | je parse_label_directive |
462 | je parse_label_directive |
482 | cmp bx,load_directive-assembler |
463 | cmp bx,load_directive-assembler |
483 | je parse_load_directive |
464 | je parse_load_directive |
484 | cmp bx,extrn_directive-assembler |
465 | cmp bx,extrn_directive-assembler |
485 | je parse_extrn_directive |
466 | je parse_extrn_directive |
486 | cmp bx,public_directive-assembler |
467 | cmp bx,public_directive-assembler |
487 | je parse_public_directive |
468 | je parse_public_directive |
488 | parse_argument: |
469 | parse_argument: |
489 | lea eax,[edi+100h] |
470 | lea eax,[edi+100h] |
490 | cmp eax,[labels_list] |
471 | cmp eax,[labels_list] |
491 | jae out_of_memory |
472 | jae out_of_memory |
492 | lods byte [esi] |
473 | lods byte [esi] |
493 | cmp al,':' |
474 | cmp al,':' |
494 | je instruction_separator |
475 | je instruction_separator |
495 | cmp al,',' |
476 | cmp al,',' |
496 | je separator |
477 | je separator |
497 | cmp al,'=' |
478 | cmp al,'=' |
498 | je separator |
479 | je separator |
499 | cmp al,'|' |
480 | cmp al,'|' |
500 | je separator |
481 | je separator |
501 | cmp al,'&' |
482 | cmp al,'&' |
502 | je separator |
483 | je separator |
503 | cmp al,'~' |
484 | cmp al,'~' |
504 | je separator |
485 | je separator |
505 | cmp al,'>' |
486 | cmp al,'>' |
506 | je greater |
487 | je greater |
507 | cmp al,'<' |
488 | cmp al,'<' |
508 | je less |
489 | je less |
509 | cmp al,')' |
490 | cmp al,')' |
510 | je close_parenthesis |
491 | je close_parenthesis |
511 | or al,al |
492 | or al,al |
512 | jz contents_parsed |
493 | jz contents_parsed |
513 | cmp al,'[' |
494 | cmp al,'[' |
514 | je address_argument |
495 | je address_argument |
515 | cmp al,']' |
496 | cmp al,']' |
516 | je separator |
497 | je separator |
517 | cmp al,'{' |
498 | cmp al,'{' |
518 | je unallowed_character |
499 | je unallowed_character |
519 | cmp al,'}' |
500 | cmp al,'}' |
520 | je unallowed_character |
501 | je unallowed_character |
521 | cmp al,'#' |
502 | cmp al,'#' |
522 | je unallowed_character |
503 | je unallowed_character |
523 | cmp al,'`' |
504 | cmp al,'`' |
524 | je unallowed_character |
505 | je unallowed_character |
525 | dec esi |
506 | dec esi |
526 | cmp al,1Ah |
507 | cmp al,1Ah |
527 | jne expression_argument |
508 | jne expression_argument |
528 | push edi |
509 | push edi |
529 | mov edi,directive_operators |
510 | mov edi,directive_operators |
530 | call get_operator |
511 | call get_operator |
531 | or al,al |
512 | or al,al |
532 | jnz operator_argument |
513 | jnz operator_argument |
533 | inc esi |
514 | inc esi |
534 | movzx ecx,byte [esi] |
515 | movzx ecx,byte [esi] |
535 | inc esi |
516 | inc esi |
536 | call get_symbol |
517 | call get_symbol |
537 | jnc symbol_argument |
518 | jnc symbol_argument |
538 | cmp ecx,1 |
519 | cmp ecx,1 |
539 | jne check_argument |
520 | jne check_argument |
540 | cmp byte [esi],'?' |
521 | cmp byte [esi],'?' |
541 | jne check_argument |
522 | jne check_argument |
542 | pop edi |
523 | pop edi |
543 | movs byte [edi],[esi] |
524 | movs byte [edi],[esi] |
544 | jmp argument_parsed |
525 | jmp argument_parsed |
545 | symbol_argument: |
526 | symbol_argument: |
546 | pop edi |
527 | pop edi |
547 | stos word [edi] |
528 | stos word [edi] |
548 | jmp argument_parsed |
529 | jmp argument_parsed |
549 | operator_argument: |
530 | operator_argument: |
550 | pop edi |
531 | pop edi |
551 | cmp al,85h |
532 | cmp al,85h |
552 | je ptr_argument |
533 | je ptr_argument |
553 | stos byte [edi] |
534 | stos byte [edi] |
554 | cmp al,80h |
535 | cmp al,80h |
555 | je forced_expression |
536 | je forced_expression |
556 | cmp al,81h |
537 | cmp al,81h |
557 | je forced_parenthesis |
538 | je forced_parenthesis |
558 | cmp al,82h |
539 | cmp al,82h |
559 | je parse_from_operator |
540 | je parse_from_operator |
560 | cmp al,89h |
541 | cmp al,89h |
561 | je parse_label_operator |
542 | je parse_label_operator |
562 | jmp argument_parsed |
543 | jmp argument_parsed |
563 | allow_embedded_instruction: |
544 | allow_embedded_instruction: |
564 | cmp byte [esi],1Ah |
545 | cmp byte [esi],1Ah |
565 | jne parse_argument |
546 | jne parse_argument |
566 | push edi |
547 | push edi |
567 | inc esi |
548 | inc esi |
568 | movzx ecx,byte [esi] |
549 | movzx ecx,byte [esi] |
569 | inc esi |
550 | inc esi |
570 | call get_instruction |
551 | call get_instruction |
571 | jnc embedded_instruction |
552 | jnc embedded_instruction |
572 | call get_data_directive |
553 | call get_data_directive |
573 | jnc embedded_instruction |
554 | jnc embedded_instruction |
574 | pop edi |
555 | pop edi |
575 | sub esi,2 |
556 | sub esi,2 |
576 | jmp parse_argument |
557 | jmp parse_argument |
577 | embedded_instruction: |
558 | embedded_instruction: |
578 | pop edi |
559 | pop edi |
579 | mov dl,al |
560 | mov dl,al |
580 | mov al,1 |
561 | mov al,1 |
581 | stos byte [edi] |
562 | stos byte [edi] |
582 | mov ax,bx |
563 | mov ax,bx |
583 | stos word [edi] |
564 | stos word [edi] |
584 | mov al,dl |
565 | mov al,dl |
585 | stos byte [edi] |
566 | stos byte [edi] |
586 | jmp parse_instruction_arguments |
567 | jmp parse_instruction_arguments |
587 | parse_times_directive: |
568 | parse_times_directive: |
588 | mov al,'(' |
569 | mov al,'(' |
589 | stos byte [edi] |
570 | stos byte [edi] |
590 | call convert_expression |
571 | call convert_expression |
591 | mov al,')' |
572 | mov al,')' |
592 | stos byte [edi] |
573 | stos byte [edi] |
593 | cmp byte [esi],':' |
574 | cmp byte [esi],':' |
594 | jne allow_embedded_instruction |
575 | jne allow_embedded_instruction |
595 | movs byte [edi],[esi] |
576 | movs byte [edi],[esi] |
596 | jmp allow_embedded_instruction |
577 | jmp allow_embedded_instruction |
597 | parse_label_directive: |
578 | parse_label_directive: |
598 | cmp byte [esi],1Ah |
579 | cmp byte [esi],1Ah |
599 | jne argument_parsed |
580 | jne argument_parsed |
600 | push esi |
581 | push esi |
601 | inc esi |
582 | inc esi |
602 | movzx ecx,byte [esi] |
583 | movzx ecx,byte [esi] |
603 | inc esi |
584 | inc esi |
604 | call identify_label |
585 | call identify_label |
605 | pop ebx |
586 | pop ebx |
606 | cmp eax,0Fh |
587 | cmp eax,0Fh |
607 | je non_label_identified |
588 | je non_label_identified |
608 | mov byte [edi],2 |
589 | mov byte [edi],2 |
609 | inc edi |
590 | inc edi |
610 | stos dword [edi] |
591 | stos dword [edi] |
611 | xor al,al |
592 | xor al,al |
612 | stos byte [edi] |
593 | stos byte [edi] |
613 | jmp argument_parsed |
594 | jmp argument_parsed |
614 | non_label_identified: |
595 | non_label_identified: |
615 | mov esi,ebx |
596 | mov esi,ebx |
616 | jmp argument_parsed |
597 | jmp argument_parsed |
617 | parse_load_directive: |
598 | parse_load_directive: |
618 | cmp byte [esi],1Ah |
599 | cmp byte [esi],1Ah |
619 | jne argument_parsed |
600 | jne argument_parsed |
620 | push esi |
601 | push esi |
621 | inc esi |
602 | inc esi |
622 | movzx ecx,byte [esi] |
603 | movzx ecx,byte [esi] |
623 | inc esi |
604 | inc esi |
624 | call get_label_id |
605 | call get_label_id |
625 | pop ebx |
606 | pop ebx |
626 | cmp eax,0Fh |
607 | cmp eax,0Fh |
627 | je non_label_identified |
608 | je non_label_identified |
628 | mov byte [edi],2 |
609 | mov byte [edi],2 |
629 | inc edi |
610 | inc edi |
630 | stos dword [edi] |
611 | stos dword [edi] |
631 | xor al,al |
612 | xor al,al |
632 | stos byte [edi] |
613 | stos byte [edi] |
633 | jmp argument_parsed |
614 | jmp argument_parsed |
634 | parse_public_directive: |
615 | parse_public_directive: |
635 | cmp byte [esi],1Ah |
616 | cmp byte [esi],1Ah |
636 | jne parse_argument |
617 | jne parse_argument |
637 | inc esi |
618 | inc esi |
638 | push esi |
619 | push esi |
639 | movzx ecx,byte [esi] |
620 | movzx ecx,byte [esi] |
640 | inc esi |
621 | inc esi |
641 | push esi ecx |
622 | push esi ecx |
642 | push edi |
623 | push edi |
643 | call get_symbol |
624 | call get_symbol |
644 | pop edi |
625 | pop edi |
645 | jc parse_public_label |
626 | jc parse_public_label |
646 | cmp al,1Dh |
627 | cmp al,1Dh |
647 | jne parse_public_label |
628 | jne parse_public_label |
648 | add esp,12 |
629 | add esp,12 |
649 | stos word [edi] |
630 | stos word [edi] |
650 | jmp parse_public_directive |
631 | jmp parse_public_directive |
651 | parse_public_label: |
632 | parse_public_label: |
652 | pop ecx esi |
633 | pop ecx esi |
653 | mov al,2 |
634 | mov al,2 |
654 | stos byte [edi] |
635 | stos byte [edi] |
655 | call get_label_id |
636 | call get_label_id |
656 | stos dword [edi] |
637 | stos dword [edi] |
657 | mov ax,8600h |
638 | mov ax,8600h |
658 | stos word [edi] |
639 | stos word [edi] |
659 | pop ebx |
640 | pop ebx |
660 | push ebx esi edi |
641 | push ebx esi edi |
661 | mov edi,directive_operators |
642 | mov edi,directive_operators |
662 | call get_operator |
643 | call get_operator |
663 | pop edi edx ebx |
644 | pop edi edx ebx |
664 | cmp al,86h |
645 | cmp al,86h |
665 | je argument_parsed |
646 | je argument_parsed |
666 | mov esi,edx |
647 | mov esi,edx |
667 | xchg esi,ebx |
648 | xchg esi,ebx |
668 | movzx ecx,byte [esi] |
649 | movzx ecx,byte [esi] |
669 | inc esi |
650 | inc esi |
670 | mov ax,'(' |
651 | mov ax,'(' |
671 | stos word [edi] |
652 | stos word [edi] |
672 | mov eax,ecx |
653 | mov eax,ecx |
673 | stos dword [edi] |
654 | stos dword [edi] |
674 | rep movs byte [edi],[esi] |
655 | rep movs byte [edi],[esi] |
675 | xor al,al |
656 | xor al,al |
676 | stos byte [edi] |
657 | stos byte [edi] |
677 | xchg esi,ebx |
658 | xchg esi,ebx |
678 | jmp argument_parsed |
659 | jmp argument_parsed |
679 | parse_extrn_directive: |
660 | parse_extrn_directive: |
680 | cmp byte [esi],22h |
661 | cmp byte [esi],22h |
681 | je parse_quoted_extrn |
662 | je parse_quoted_extrn |
682 | cmp byte [esi],1Ah |
663 | cmp byte [esi],1Ah |
683 | jne parse_argument |
664 | jne parse_argument |
684 | push esi |
665 | push esi |
685 | movzx ecx,byte [esi+1] |
666 | movzx ecx,byte [esi+1] |
686 | add esi,2 |
667 | add esi,2 |
687 | mov ax,'(' |
668 | mov ax,'(' |
688 | stos word [edi] |
669 | stos word [edi] |
689 | mov eax,ecx |
670 | mov eax,ecx |
690 | stos dword [edi] |
671 | stos dword [edi] |
691 | rep movs byte [edi],[esi] |
672 | rep movs byte [edi],[esi] |
692 | mov ax,8600h |
673 | mov ax,8600h |
693 | stos word [edi] |
674 | stos word [edi] |
694 | pop esi |
675 | pop esi |
695 | parse_label_operator: |
676 | parse_label_operator: |
696 | cmp byte [esi],1Ah |
677 | cmp byte [esi],1Ah |
697 | jne argument_parsed |
678 | jne argument_parsed |
698 | inc esi |
679 | inc esi |
699 | movzx ecx,byte [esi] |
680 | movzx ecx,byte [esi] |
700 | inc esi |
681 | inc esi |
701 | mov al,2 |
682 | mov al,2 |
702 | stos byte [edi] |
683 | stos byte [edi] |
703 | call get_label_id |
684 | call get_label_id |
704 | stos dword [edi] |
685 | stos dword [edi] |
705 | xor al,al |
686 | xor al,al |
706 | stos byte [edi] |
687 | stos byte [edi] |
707 | jmp argument_parsed |
688 | jmp argument_parsed |
708 | parse_from_operator: |
689 | parse_from_operator: |
709 | cmp byte [esi],22h |
690 | cmp byte [esi],22h |
710 | jne forced_expression |
691 | jne forced_expression |
711 | jmp argument_parsed |
692 | jmp argument_parsed |
712 | parse_quoted_extrn: |
693 | parse_quoted_extrn: |
713 | inc esi |
694 | inc esi |
714 | mov ax,'(' |
695 | mov ax,'(' |
715 | stos word [edi] |
696 | stos word [edi] |
716 | lods dword [esi] |
697 | lods dword [esi] |
717 | mov ecx,eax |
698 | mov ecx,eax |
718 | stos dword [edi] |
699 | stos dword [edi] |
719 | rep movs byte [edi],[esi] |
700 | rep movs byte [edi],[esi] |
720 | xor al,al |
701 | xor al,al |
721 | stos byte [edi] |
702 | stos byte [edi] |
722 | push esi edi |
703 | push esi edi |
723 | mov edi,directive_operators |
704 | mov edi,directive_operators |
724 | call get_operator |
705 | call get_operator |
725 | mov edx,esi |
706 | mov edx,esi |
726 | pop edi esi |
707 | pop edi esi |
727 | cmp al,86h |
708 | cmp al,86h |
728 | jne argument_parsed |
709 | jne argument_parsed |
729 | stos byte [edi] |
710 | stos byte [edi] |
730 | mov esi,edx |
711 | mov esi,edx |
731 | jmp parse_label_operator |
712 | jmp parse_label_operator |
732 | ptr_argument: |
713 | ptr_argument: |
733 | call parse_address |
714 | call parse_address |
734 | jmp address_parsed |
715 | jmp address_parsed |
735 | check_argument: |
716 | check_argument: |
736 | push esi ecx |
717 | push esi ecx |
737 | sub esi,2 |
718 | sub esi,2 |
738 | mov edi,single_operand_operators |
719 | mov edi,single_operand_operators |
739 | call get_operator |
720 | call get_operator |
740 | pop ecx esi |
721 | pop ecx esi |
741 | or al,al |
722 | or al,al |
742 | jnz not_instruction |
723 | jnz not_instruction |
743 | call get_instruction |
724 | call get_instruction |
744 | jnc embedded_instruction |
725 | jnc embedded_instruction |
745 | call get_data_directive |
726 | call get_data_directive |
746 | jnc embedded_instruction |
727 | jnc embedded_instruction |
747 | not_instruction: |
728 | not_instruction: |
748 | pop edi |
729 | pop edi |
749 | sub esi,2 |
730 | sub esi,2 |
750 | expression_argument: |
731 | expression_argument: |
751 | cmp byte [esi],22h |
732 | cmp byte [esi],22h |
752 | jne not_string |
733 | jne not_string |
753 | mov eax,[esi+1] |
734 | mov eax,[esi+1] |
754 | lea ebx,[esi+5+eax] |
735 | lea ebx,[esi+5+eax] |
755 | push ebx ecx esi edi |
736 | push ebx ecx esi edi |
756 | mov al,'(' |
737 | mov al,'(' |
757 | stos byte [edi] |
738 | stos byte [edi] |
758 | call convert_expression |
739 | call convert_expression |
759 | mov al,')' |
740 | mov al,')' |
760 | stos byte [edi] |
741 | stos byte [edi] |
761 | pop eax edx ecx ebx |
742 | pop eax edx ecx ebx |
762 | cmp esi,ebx |
743 | cmp esi,ebx |
763 | jne expression_parsed |
744 | jne expression_parsed |
764 | mov edi,eax |
745 | mov edi,eax |
765 | mov esi,edx |
746 | mov esi,edx |
766 | string_argument: |
747 | string_argument: |
767 | inc esi |
748 | inc esi |
768 | mov ax,'(' |
749 | mov ax,'(' |
769 | stos word [edi] |
750 | stos word [edi] |
770 | lods dword [esi] |
751 | lods dword [esi] |
771 | mov ecx,eax |
752 | mov ecx,eax |
772 | stos dword [edi] |
753 | stos dword [edi] |
773 | shr ecx,1 |
754 | shr ecx,1 |
774 | jnc string_movsb_ok |
755 | jnc string_movsb_ok |
775 | movs byte [edi],[esi] |
756 | movs byte [edi],[esi] |
776 | string_movsb_ok: |
757 | string_movsb_ok: |
777 | shr ecx,1 |
758 | shr ecx,1 |
778 | jnc string_movsw_ok |
759 | jnc string_movsw_ok |
779 | movs word [edi],[esi] |
760 | movs word [edi],[esi] |
780 | string_movsw_ok: |
761 | string_movsw_ok: |
781 | rep movs dword [edi],[esi] |
762 | rep movs dword [edi],[esi] |
782 | xor al,al |
763 | xor al,al |
783 | stos byte [edi] |
764 | stos byte [edi] |
784 | jmp expression_parsed |
765 | jmp expression_parsed |
785 | not_string: |
766 | not_string: |
786 | cmp byte [esi],'(' |
767 | cmp byte [esi],'(' |
787 | jne expression |
768 | jne expression |
788 | mov eax,esp |
769 | mov eax,esp |
789 | sub eax,100h |
770 | sub eax,100h |
790 | jc stack_overflow |
771 | jc stack_overflow |
791 | cmp eax,[stack_limit] |
772 | cmp eax,[stack_limit] |
792 | jb stack_overflow |
773 | jb stack_overflow |
793 | push esi edi |
774 | push esi edi |
794 | inc esi |
775 | inc esi |
795 | mov al,'{' |
776 | mov al,'{' |
796 | stos byte [edi] |
777 | stos byte [edi] |
797 | inc [parenthesis_stack] |
778 | inc [parenthesis_stack] |
798 | jmp parse_argument |
779 | jmp parse_argument |
799 | expression: |
780 | expression: |
800 | mov al,'(' |
781 | mov al,'(' |
801 | stos byte [edi] |
782 | stos byte [edi] |
802 | call convert_expression |
783 | call convert_expression |
803 | mov al,')' |
784 | mov al,')' |
804 | stos byte [edi] |
785 | stos byte [edi] |
805 | jmp expression_parsed |
786 | jmp expression_parsed |
806 | forced_expression: |
787 | forced_expression: |
807 | mov al,'(' |
788 | mov al,'(' |
808 | stos byte [edi] |
789 | stos byte [edi] |
809 | call convert_expression |
790 | call convert_expression |
810 | mov al,')' |
791 | mov al,')' |
811 | stos byte [edi] |
792 | stos byte [edi] |
812 | jmp argument_parsed |
793 | jmp argument_parsed |
813 | address_argument: |
794 | address_argument: |
814 | call parse_address |
795 | call parse_address |
815 | lods byte [esi] |
796 | lods byte [esi] |
816 | cmp al,']' |
797 | cmp al,']' |
817 | je address_parsed |
798 | je address_parsed |
818 | dec esi |
799 | dec esi |
819 | mov al,')' |
800 | mov al,')' |
820 | stos byte [edi] |
801 | stos byte [edi] |
821 | jmp argument_parsed |
802 | jmp argument_parsed |
822 | address_parsed: |
803 | address_parsed: |
823 | mov al,']' |
804 | mov al,']' |
824 | stos byte [edi] |
805 | stos byte [edi] |
825 | jmp argument_parsed |
806 | jmp argument_parsed |
826 | parse_address: |
807 | parse_address: |
827 | mov al,'[' |
808 | mov al,'[' |
828 | stos byte [edi] |
809 | stos byte [edi] |
829 | cmp word [esi],021Ah |
810 | cmp word [esi],021Ah |
830 | jne convert_address |
811 | jne convert_address |
831 | push esi |
812 | push esi |
832 | add esi,4 |
813 | add esi,4 |
833 | lea ebx,[esi+1] |
814 | lea ebx,[esi+1] |
834 | cmp byte [esi],':' |
815 | cmp byte [esi],':' |
835 | pop esi |
816 | pop esi |
836 | jne convert_address |
817 | jne convert_address |
837 | add esi,2 |
818 | add esi,2 |
838 | mov ecx,2 |
819 | mov ecx,2 |
839 | push ebx edi |
820 | push ebx edi |
840 | call get_symbol |
821 | call get_symbol |
841 | pop edi esi |
822 | pop edi esi |
842 | jc unknown_segment_prefix |
823 | jc unknown_segment_prefix |
843 | cmp al,10h |
824 | cmp al,10h |
844 | jne unknown_segment_prefix |
825 | jne unknown_segment_prefix |
845 | mov al,ah |
826 | mov al,ah |
846 | and ah,11110000b |
827 | and ah,11110000b |
847 | cmp ah,60h |
828 | cmp ah,60h |
848 | jne unknown_segment_prefix |
829 | jne unknown_segment_prefix |
849 | stos byte [edi] |
830 | stos byte [edi] |
850 | jmp convert_address |
831 | jmp convert_address |
851 | unknown_segment_prefix: |
832 | unknown_segment_prefix: |
852 | sub esi,5 |
833 | sub esi,5 |
853 | convert_address: |
834 | convert_address: |
854 | push edi |
835 | push edi |
855 | mov edi,address_sizes |
836 | mov edi,address_sizes |
856 | call get_operator |
837 | call get_operator |
857 | pop edi |
838 | pop edi |
858 | or al,al |
839 | or al,al |
859 | jz convert_expression |
840 | jz convert_expression |
860 | add al,70h |
841 | add al,70h |
861 | stos byte [edi] |
842 | stos byte [edi] |
862 | jmp convert_expression |
843 | jmp convert_expression |
863 | forced_parenthesis: |
844 | forced_parenthesis: |
864 | cmp byte [esi],'(' |
845 | cmp byte [esi],'(' |
865 | jne argument_parsed |
846 | jne argument_parsed |
866 | inc esi |
847 | inc esi |
867 | mov al,'{' |
848 | mov al,'{' |
868 | jmp separator |
849 | jmp separator |
869 | unallowed_character: |
850 | unallowed_character: |
870 | mov al,0FFh |
851 | mov al,0FFh |
871 | jmp separator |
852 | jmp separator |
872 | close_parenthesis: |
853 | close_parenthesis: |
873 | mov al,'}' |
854 | mov al,'}' |
874 | separator: |
855 | separator: |
875 | stos byte [edi] |
856 | stos byte [edi] |
876 | jmp argument_parsed |
857 | jmp argument_parsed |
877 | instruction_separator: |
858 | instruction_separator: |
878 | stos byte [edi] |
859 | stos byte [edi] |
879 | jmp allow_embedded_instruction |
860 | jmp allow_embedded_instruction |
880 | greater: |
861 | greater: |
881 | cmp byte [esi],'=' |
862 | cmp byte [esi],'=' |
882 | jne separator |
863 | jne separator |
883 | inc esi |
864 | inc esi |
884 | mov al,0F2h |
865 | mov al,0F2h |
885 | jmp separator |
866 | jmp separator |
886 | less: |
867 | less: |
887 | cmp byte [edi-1],0F6h |
868 | cmp byte [edi-1],0F6h |
888 | je separator |
869 | je separator |
889 | cmp byte [esi],'>' |
870 | cmp byte [esi],'>' |
890 | je not_equal |
871 | je not_equal |
891 | cmp byte [esi],'=' |
872 | cmp byte [esi],'=' |
892 | jne separator |
873 | jne separator |
893 | inc esi |
874 | inc esi |
894 | mov al,0F3h |
875 | mov al,0F3h |
895 | jmp separator |
876 | jmp separator |
896 | not_equal: |
877 | not_equal: |
897 | inc esi |
878 | inc esi |
898 | mov al,0F1h |
879 | mov al,0F1h |
899 | jmp separator |
880 | jmp separator |
900 | argument_parsed: |
881 | argument_parsed: |
901 | cmp [parenthesis_stack],0 |
882 | cmp [parenthesis_stack],0 |
902 | je parse_argument |
883 | je parse_argument |
903 | dec [parenthesis_stack] |
884 | dec [parenthesis_stack] |
904 | add esp,8 |
885 | add esp,8 |
905 | jmp argument_parsed |
886 | jmp argument_parsed |
906 | expression_parsed: |
887 | expression_parsed: |
907 | cmp [parenthesis_stack],0 |
888 | cmp [parenthesis_stack],0 |
908 | je parse_argument |
889 | je parse_argument |
909 | cmp byte [esi],')' |
890 | cmp byte [esi],')' |
910 | jne argument_parsed |
891 | jne argument_parsed |
911 | dec [parenthesis_stack] |
892 | dec [parenthesis_stack] |
912 | pop edi esi |
893 | pop edi esi |
913 | jmp expression |
894 | jmp expression |
914 | contents_parsed: |
895 | contents_parsed: |
915 | cmp [parenthesis_stack],0 |
896 | cmp [parenthesis_stack],0 |
916 | ; jne invalid_expression |
897 | je contents_ok |
917 | je contents_ok |
- | |
918 | dec [parenthesis_stack] |
898 | dec [parenthesis_stack] |
919 | add esp,8 |
899 | add esp,8 |
920 | jmp contents_parsed |
900 | jmp contents_parsed |
921 | contents_ok: |
901 | contents_ok: |
922 | ret |
902 | ret |
923 | 903 | ||
924 | identify_label: |
904 | identify_label: |
925 | cmp byte [esi],'.' |
905 | cmp byte [esi],'.' |
926 | je local_label_name |
906 | je local_label_name |
927 | call get_label_id |
907 | call get_label_id |
928 | cmp eax,10h |
908 | cmp eax,10h |
929 | jb label_identified |
909 | jb label_identified |
930 | or ebx,ebx |
910 | or ebx,ebx |
931 | jz anonymous_label_name |
911 | jz anonymous_label_name |
932 | dec ebx |
912 | dec ebx |
933 | mov [current_locals_prefix],ebx |
913 | mov [current_locals_prefix],ebx |
934 | label_identified: |
914 | label_identified: |
935 | ret |
915 | ret |
936 | anonymous_label_name: |
916 | anonymous_label_name: |
937 | cmp byte [esi-1],'@' |
917 | cmp byte [esi-1],'@' |
938 | je anonymous_label_name_ok |
918 | je anonymous_label_name_ok |
939 | mov eax,0Fh |
919 | mov eax,0Fh |
940 | anonymous_label_name_ok: |
920 | anonymous_label_name_ok: |
941 | ret |
921 | ret |
942 | local_label_name: |
922 | local_label_name: |
943 | call get_label_id |
923 | call get_label_id |
944 | ret |
924 | ret |
945 | 925 | ||
946 | get_operator: |
926 | get_operator: |
947 | cmp byte [esi],1Ah |
927 | cmp byte [esi],1Ah |
948 | jne get_simple_operator |
928 | jne get_simple_operator |
949 | mov edx,esi |
929 | mov edx,esi |
950 | push ebp |
930 | push ebp |
951 | inc esi |
931 | inc esi |
952 | lods byte [esi] |
932 | lods byte [esi] |
953 | movzx ebp,al |
933 | movzx ebp,al |
954 | push edi |
934 | push edi |
955 | mov ecx,ebp |
935 | mov ecx,ebp |
956 | call lower_case |
936 | call lower_case |
957 | pop edi |
937 | pop edi |
958 | check_operator: |
938 | check_operator: |
959 | mov esi,converted |
939 | mov esi,converted |
960 | movzx ecx,byte [edi] |
940 | movzx ecx,byte [edi] |
961 | jecxz no_operator |
941 | jecxz no_operator |
962 | inc edi |
942 | inc edi |
963 | mov ebx,edi |
943 | mov ebx,edi |
964 | add ebx,ecx |
944 | add ebx,ecx |
965 | cmp ecx,ebp |
945 | cmp ecx,ebp |
966 | jne next_operator |
946 | jne next_operator |
967 | repe cmps byte [esi],[edi] |
947 | repe cmps byte [esi],[edi] |
968 | je operator_found |
948 | je operator_found |
969 | next_operator: |
949 | next_operator: |
970 | mov edi,ebx |
950 | mov edi,ebx |
971 | inc edi |
951 | inc edi |
972 | jmp check_operator |
952 | jmp check_operator |
973 | no_operator: |
953 | no_operator: |
974 | mov esi,edx |
954 | mov esi,edx |
975 | mov ecx,ebp |
955 | mov ecx,ebp |
976 | pop ebp |
956 | pop ebp |
977 | no_simple_operator: |
957 | no_simple_operator: |
978 | xor al,al |
958 | xor al,al |
979 | ret |
959 | ret |
980 | operator_found: |
960 | operator_found: |
981 | lea esi,[edx+2+ebp] |
961 | lea esi,[edx+2+ebp] |
982 | mov ecx,ebp |
962 | mov ecx,ebp |
983 | pop ebp |
963 | pop ebp |
984 | mov al,[edi] |
964 | mov al,[edi] |
985 | ret |
965 | ret |
986 | get_simple_operator: |
966 | get_simple_operator: |
987 | mov al,[esi] |
967 | mov al,[esi] |
988 | cmp al,22h |
968 | cmp al,22h |
989 | je no_simple_operator |
969 | je no_simple_operator |
990 | simple_operator: |
970 | simple_operator: |
991 | cmp byte [edi],1 |
971 | cmp byte [edi],1 |
992 | jb no_simple_operator |
972 | jb no_simple_operator |
993 | ja simple_next_operator |
973 | ja simple_next_operator |
994 | cmp al,[edi+1] |
974 | cmp al,[edi+1] |
995 | je simple_operator_found |
975 | je simple_operator_found |
996 | simple_next_operator: |
976 | simple_next_operator: |
997 | movzx ecx,byte [edi] |
977 | movzx ecx,byte [edi] |
998 | lea edi,[edi+1+ecx+1] |
978 | lea edi,[edi+1+ecx+1] |
999 | jmp simple_operator |
979 | jmp simple_operator |
1000 | simple_operator_found: |
980 | simple_operator_found: |
1001 | inc esi |
981 | inc esi |
1002 | mov al,[edi+2] |
982 | mov al,[edi+2] |
1003 | ret |
983 | ret |
1004 | 984 | ||
1005 | get_symbol: |
985 | get_symbol: |
1006 | push esi |
986 | push esi |
1007 | mov ebp,ecx |
987 | mov ebp,ecx |
1008 | call lower_case |
988 | call lower_case |
1009 | mov ecx,ebp |
989 | mov ecx,ebp |
1010 | cmp cl,11 |
990 | cmp cl,11 |
1011 | ja no_symbol |
991 | ja no_symbol |
1012 | sub cl,2 |
992 | sub cl,2 |
1013 | jc no_symbol |
993 | jc no_symbol |
1014 | movzx ebx,word [symbols+ecx*4] |
994 | movzx ebx,word [symbols+ecx*4] |
1015 | add ebx,symbols |
995 | add ebx,symbols |
1016 | movzx edx,word [symbols+ecx*4+2] |
996 | movzx edx,word [symbols+ecx*4+2] |
1017 | scan_symbols: |
997 | scan_symbols: |
1018 | or edx,edx |
998 | or edx,edx |
1019 | jz no_symbol |
999 | jz no_symbol |
1020 | mov eax,edx |
1000 | mov eax,edx |
1021 | shr eax,1 |
1001 | shr eax,1 |
1022 | lea edi,[ebp+2] |
1002 | lea edi,[ebp+2] |
1023 | imul eax,edi |
1003 | imul eax,edi |
1024 | lea edi,[ebx+eax] |
1004 | lea edi,[ebx+eax] |
1025 | mov esi,converted |
1005 | mov esi,converted |
1026 | mov ecx,ebp |
1006 | mov ecx,ebp |
1027 | repe cmps byte [esi],[edi] |
1007 | repe cmps byte [esi],[edi] |
1028 | ja symbols_up |
1008 | ja symbols_up |
1029 | jb symbols_down |
1009 | jb symbols_down |
1030 | pop esi |
1010 | pop esi |
1031 | add esi,ebp |
1011 | add esi,ebp |
1032 | mov ax,[edi] |
1012 | mov ax,[edi] |
1033 | clc |
1013 | clc |
1034 | ret |
1014 | ret |
1035 | no_symbol: |
1015 | no_symbol: |
1036 | pop esi |
1016 | pop esi |
1037 | mov ecx,ebp |
1017 | mov ecx,ebp |
1038 | stc |
1018 | stc |
1039 | ret |
1019 | ret |
1040 | symbols_down: |
1020 | symbols_down: |
1041 | shr edx,1 |
1021 | shr edx,1 |
1042 | jmp scan_symbols |
1022 | jmp scan_symbols |
1043 | symbols_up: |
1023 | symbols_up: |
1044 | lea ebx,[edi+ecx+2] |
1024 | lea ebx,[edi+ecx+2] |
1045 | shr edx,1 |
1025 | shr edx,1 |
1046 | adc edx,-1 |
1026 | adc edx,-1 |
1047 | jmp scan_symbols |
1027 | jmp scan_symbols |
1048 | 1028 | ||
1049 | get_data_directive: |
1029 | get_data_directive: |
1050 | push esi |
1030 | push esi |
1051 | mov ebp,ecx |
1031 | mov ebp,ecx |
1052 | call lower_case |
1032 | call lower_case |
1053 | mov ecx,ebp |
1033 | mov ecx,ebp |
1054 | cmp cl,4 |
1034 | cmp cl,4 |
1055 | ja no_instruction |
1035 | ja no_instruction |
1056 | sub cl,2 |
1036 | sub cl,2 |
1057 | jc no_instruction |
1037 | jc no_instruction |
1058 | movzx ebx,word [data_directives+ecx*4] |
1038 | movzx ebx,word [data_directives+ecx*4] |
1059 | add ebx,data_directives |
1039 | add ebx,data_directives |
1060 | movzx edx,word [data_directives+ecx*4+2] |
1040 | movzx edx,word [data_directives+ecx*4+2] |
1061 | jmp scan_instructions |
1041 | jmp scan_instructions |
1062 | 1042 | ||
1063 | get_instruction: |
1043 | get_instruction: |
1064 | push esi |
1044 | push esi |
1065 | mov ebp,ecx |
1045 | mov ebp,ecx |
1066 | call lower_case |
1046 | call lower_case |
1067 | mov ecx,ebp |
1047 | mov ecx,ebp |
1068 | cmp cl,11 |
1048 | cmp cl,11 |
1069 | ja no_instruction |
1049 | ja no_instruction |
1070 | sub cl,2 |
1050 | sub cl,2 |
1071 | jc no_instruction |
1051 | jc no_instruction |
1072 | movzx ebx,word [instructions+ecx*4] |
1052 | movzx ebx,word [instructions+ecx*4] |
1073 | add ebx,instructions |
1053 | add ebx,instructions |
1074 | movzx edx,word [instructions+ecx*4+2] |
1054 | movzx edx,word [instructions+ecx*4+2] |
1075 | scan_instructions: |
1055 | scan_instructions: |
1076 | or edx,edx |
1056 | or edx,edx |
1077 | jz no_instruction |
1057 | jz no_instruction |
1078 | mov eax,edx |
1058 | mov eax,edx |
1079 | shr eax,1 |
1059 | shr eax,1 |
1080 | lea edi,[ebp+3] |
1060 | lea edi,[ebp+3] |
1081 | imul eax,edi |
1061 | imul eax,edi |
1082 | lea edi,[ebx+eax] |
1062 | lea edi,[ebx+eax] |
1083 | mov esi,converted |
1063 | mov esi,converted |
1084 | mov ecx,ebp |
1064 | mov ecx,ebp |
1085 | repe cmps byte [esi],[edi] |
1065 | repe cmps byte [esi],[edi] |
1086 | ja instructions_up |
1066 | ja instructions_up |
1087 | jb instructions_down |
1067 | jb instructions_down |
1088 | pop esi |
1068 | pop esi |
1089 | add esi,ebp |
1069 | add esi,ebp |
1090 | mov al,[edi] |
1070 | mov al,[edi] |
1091 | mov bx,[edi+1] |
1071 | mov bx,[edi+1] |
1092 | clc |
1072 | clc |
1093 | ret |
1073 | ret |
1094 | no_instruction: |
1074 | no_instruction: |
1095 | pop esi |
1075 | pop esi |
1096 | mov ecx,ebp |
1076 | mov ecx,ebp |
1097 | stc |
1077 | stc |
1098 | ret |
1078 | ret |
1099 | instructions_down: |
1079 | instructions_down: |
1100 | shr edx,1 |
1080 | shr edx,1 |
1101 | jmp scan_instructions |
1081 | jmp scan_instructions |
1102 | instructions_up: |
1082 | instructions_up: |
1103 | lea ebx,[edi+ecx+3] |
1083 | lea ebx,[edi+ecx+3] |
1104 | shr edx,1 |
1084 | shr edx,1 |
1105 | adc edx,-1 |
1085 | adc edx,-1 |
1106 | jmp scan_instructions |
1086 | jmp scan_instructions |
1107 | 1087 | ||
1108 | get_label_id: |
1088 | get_label_id: |
1109 | cmp ecx,100h |
1089 | cmp ecx,100h |
1110 | jae name_too_long |
1090 | jae name_too_long |
1111 | cmp byte [esi],'@' |
1091 | cmp byte [esi],'@' |
1112 | je anonymous_label |
1092 | je anonymous_label |
1113 | cmp byte [esi],'.' |
1093 | cmp byte [esi],'.' |
1114 | jne standard_label |
1094 | jne standard_label |
1115 | cmp byte [esi+1],'.' |
1095 | cmp byte [esi+1],'.' |
1116 | je standard_label |
1096 | je standard_label |
1117 | cmp [current_locals_prefix],0 |
1097 | cmp [current_locals_prefix],0 |
1118 | je standard_label |
1098 | je standard_label |
1119 | push edi |
1099 | push edi |
1120 | mov edi,[additional_memory_end] |
1100 | mov edi,[additional_memory_end] |
1121 | sub edi,2 |
1101 | sub edi,2 |
1122 | sub edi,ecx |
1102 | sub edi,ecx |
1123 | push ecx esi |
1103 | push ecx esi |
1124 | mov esi,[current_locals_prefix] |
1104 | mov esi,[current_locals_prefix] |
1125 | lods byte [esi] |
1105 | lods byte [esi] |
1126 | movzx ecx,al |
1106 | movzx ecx,al |
1127 | sub edi,ecx |
1107 | sub edi,ecx |
1128 | cmp edi,[free_additional_memory] |
1108 | cmp edi,[free_additional_memory] |
1129 | jb out_of_memory |
1109 | jb out_of_memory |
1130 | mov word [edi],0 |
1110 | mov word [edi],0 |
1131 | add edi,2 |
1111 | add edi,2 |
1132 | mov ebx,edi |
1112 | mov ebx,edi |
1133 | rep movs byte [edi],[esi] |
1113 | rep movs byte [edi],[esi] |
1134 | pop esi ecx |
1114 | pop esi ecx |
1135 | add al,cl |
1115 | add al,cl |
1136 | jc name_too_long |
1116 | jc name_too_long |
1137 | rep movs byte [edi],[esi] |
1117 | rep movs byte [edi],[esi] |
1138 | pop edi |
1118 | pop edi |
1139 | push ebx esi |
1119 | push ebx esi |
1140 | movzx ecx,al |
1120 | movzx ecx,al |
1141 | mov byte [ebx-1],al |
1121 | mov byte [ebx-1],al |
1142 | mov esi,ebx |
1122 | mov esi,ebx |
1143 | call get_label_id |
1123 | call get_label_id |
1144 | pop esi ebx |
1124 | pop esi ebx |
1145 | cmp ebx,[eax+24] |
1125 | cmp ebx,[eax+24] |
1146 | jne composed_label_id_ok |
1126 | jne composed_label_id_ok |
1147 | lea edx,[ebx-2] |
1127 | lea edx,[ebx-2] |
1148 | mov [additional_memory_end],edx |
1128 | mov [additional_memory_end],edx |
1149 | composed_label_id_ok: |
1129 | composed_label_id_ok: |
1150 | ret |
1130 | ret |
1151 | anonymous_label: |
1131 | anonymous_label: |
1152 | cmp ecx,2 |
1132 | cmp ecx,2 |
1153 | jne standard_label |
1133 | jne standard_label |
1154 | mov al,[esi+1] |
1134 | mov al,[esi+1] |
1155 | mov ebx,characters |
1135 | mov ebx,characters |
1156 | xlat byte [ebx] |
1136 | xlat byte [ebx] |
1157 | cmp al,'@' |
1137 | cmp al,'@' |
1158 | je new_anonymous |
1138 | je new_anonymous |
1159 | cmp al,'b' |
1139 | cmp al,'b' |
1160 | je anonymous_back |
1140 | je anonymous_back |
1161 | cmp al,'r' |
1141 | cmp al,'r' |
1162 | je anonymous_back |
1142 | je anonymous_back |
1163 | cmp al,'f' |
1143 | cmp al,'f' |
1164 | jne standard_label |
1144 | jne standard_label |
1165 | add esi,2 |
1145 | add esi,2 |
1166 | mov eax,[anonymous_forward] |
1146 | mov eax,[anonymous_forward] |
1167 | or eax,eax |
1147 | or eax,eax |
1168 | jnz anonymous_ok |
1148 | jnz anonymous_ok |
1169 | mov eax,[current_line] |
1149 | mov eax,[current_line] |
1170 | mov [error_line],eax |
1150 | mov [error_line],eax |
1171 | call allocate_label |
1151 | call allocate_label |
1172 | mov [anonymous_forward],eax |
1152 | mov [anonymous_forward],eax |
1173 | anonymous_ok: |
1153 | anonymous_ok: |
1174 | xor ebx,ebx |
1154 | xor ebx,ebx |
1175 | ret |
1155 | ret |
1176 | anonymous_back: |
1156 | anonymous_back: |
1177 | mov eax,[anonymous_reverse] |
1157 | mov eax,[anonymous_reverse] |
1178 | or eax,eax |
1158 | or eax,eax |
1179 | jz new_anonymous |
1159 | jz new_anonymous |
1180 | add esi,2 |
1160 | add esi,2 |
1181 | jmp anonymous_ok |
1161 | jmp anonymous_ok |
1182 | new_anonymous: |
1162 | new_anonymous: |
1183 | add esi,2 |
1163 | add esi,2 |
1184 | mov eax,[anonymous_forward] |
1164 | mov eax,[anonymous_forward] |
1185 | or eax,eax |
1165 | or eax,eax |
1186 | jnz new_anonymous_ok |
1166 | jnz new_anonymous_ok |
1187 | call allocate_label |
1167 | call allocate_label |
1188 | new_anonymous_ok: |
1168 | new_anonymous_ok: |
1189 | mov [anonymous_reverse],eax |
1169 | mov [anonymous_reverse],eax |
1190 | mov [anonymous_forward],0 |
1170 | mov [anonymous_forward],0 |
1191 | jmp anonymous_ok |
1171 | jmp anonymous_ok |
1192 | standard_label: |
1172 | standard_label: |
1193 | cmp byte [esi],'%' |
1173 | cmp byte [esi],'%' |
1194 | je get_predefined_id |
1174 | je get_predefined_id |
1195 | cmp byte [esi],'$' |
1175 | cmp byte [esi],'$' |
1196 | jne find_label |
1176 | jne find_label |
1197 | cmp ecx,2 |
1177 | cmp ecx,2 |
1198 | ja find_label |
1178 | ja find_label |
1199 | inc esi |
1179 | inc esi |
1200 | jb get_current_offset_id |
1180 | jb get_current_offset_id |
1201 | inc esi |
1181 | inc esi |
1202 | cmp byte [esi-1],'$' |
1182 | cmp byte [esi-1],'$' |
1203 | je get_org_origin_id |
1183 | je get_org_origin_id |
1204 | sub esi,ecx |
1184 | sub esi,ecx |
1205 | jmp find_label |
1185 | jmp find_label |
1206 | get_current_offset_id: |
1186 | get_current_offset_id: |
1207 | xor eax,eax |
1187 | xor eax,eax |
1208 | ret |
1188 | ret |
1209 | get_counter_id: |
1189 | get_counter_id: |
1210 | mov eax,1 |
1190 | mov eax,1 |
1211 | ret |
1191 | ret |
1212 | get_timestamp_id: |
1192 | get_timestamp_id: |
1213 | mov eax,2 |
1193 | mov eax,2 |
1214 | ret |
1194 | ret |
1215 | get_org_origin_id: |
1195 | get_org_origin_id: |
1216 | mov eax,3 |
1196 | mov eax,3 |
1217 | ret |
1197 | ret |
1218 | get_predefined_id: |
1198 | get_predefined_id: |
1219 | cmp ecx,2 |
1199 | cmp ecx,2 |
1220 | ja find_label |
1200 | ja find_label |
1221 | inc esi |
1201 | inc esi |
1222 | cmp cl,1 |
1202 | cmp cl,1 |
1223 | je get_counter_id |
1203 | je get_counter_id |
1224 | lods byte [esi] |
1204 | lods byte [esi] |
1225 | mov ebx,characters |
1205 | mov ebx,characters |
1226 | xlat [ebx] |
1206 | xlat [ebx] |
1227 | cmp al,'t' |
1207 | cmp al,'t' |
1228 | je get_timestamp_id |
1208 | je get_timestamp_id |
1229 | sub esi,2 |
1209 | sub esi,2 |
1230 | find_label: |
1210 | find_label: |
1231 | xor ebx,ebx |
1211 | xor ebx,ebx |
1232 | mov eax,2166136261 |
1212 | mov eax,2166136261 |
1233 | mov ebp,16777619 |
1213 | mov ebp,16777619 |
1234 | hash_label: |
1214 | hash_label: |
1235 | xor al,[esi+ebx] |
1215 | xor al,[esi+ebx] |
1236 | mul ebp |
1216 | mul ebp |
1237 | inc bl |
1217 | inc bl |
1238 | cmp bl,cl |
1218 | cmp bl,cl |
1239 | jb hash_label |
1219 | jb hash_label |
1240 | mov ebp,eax |
1220 | mov ebp,eax |
1241 | shl eax,8 |
1221 | shl eax,8 |
1242 | and ebp,0FFh shl 24 |
1222 | and ebp,0FFh shl 24 |
1243 | xor ebp,eax |
1223 | xor ebp,eax |
1244 | or ebp,ebx |
1224 | or ebp,ebx |
1245 | mov [label_hash],ebp |
1225 | mov [label_hash],ebp |
1246 | push edi esi |
1226 | push edi esi |
1247 | push ecx |
1227 | push ecx |
1248 | mov ecx,32 |
1228 | mov ecx,32 |
1249 | mov ebx,hash_tree |
1229 | mov ebx,hash_tree |
1250 | follow_tree: |
1230 | follow_tree: |
1251 | mov edx,[ebx] |
1231 | mov edx,[ebx] |
1252 | or edx,edx |
1232 | or edx,edx |
1253 | jz extend_tree |
1233 | jz extend_tree |
1254 | xor eax,eax |
1234 | xor eax,eax |
1255 | shl ebp,1 |
1235 | shl ebp,1 |
1256 | adc eax,0 |
1236 | adc eax,0 |
1257 | lea ebx,[edx+eax*4] |
1237 | lea ebx,[edx+eax*4] |
1258 | dec ecx |
1238 | dec ecx |
1259 | jnz follow_tree |
1239 | jnz follow_tree |
1260 | mov [label_leaf],ebx |
1240 | mov [label_leaf],ebx |
1261 | pop edx |
1241 | pop edx |
1262 | mov eax,[ebx] |
1242 | mov eax,[ebx] |
1263 | or eax,eax |
1243 | or eax,eax |
1264 | jz add_label |
1244 | jz add_label |
1265 | mov ebx,esi |
1245 | mov ebx,esi |
1266 | mov ebp,[label_hash] |
1246 | mov ebp,[label_hash] |
1267 | compare_labels: |
1247 | compare_labels: |
1268 | mov esi,ebx |
1248 | mov esi,ebx |
1269 | mov ecx,edx |
1249 | mov ecx,edx |
1270 | mov edi,[eax+4] |
1250 | mov edi,[eax+4] |
1271 | mov edi,[edi+24] |
1251 | mov edi,[edi+24] |
1272 | repe cmps byte [esi],[edi] |
1252 | repe cmps byte [esi],[edi] |
1273 | je label_found |
1253 | je label_found |
1274 | mov eax,[eax] |
1254 | mov eax,[eax] |
1275 | or eax,eax |
1255 | or eax,eax |
1276 | jnz compare_labels |
1256 | jnz compare_labels |
1277 | jmp add_label |
1257 | jmp add_label |
1278 | label_found: |
1258 | label_found: |
1279 | add esp,4 |
1259 | add esp,4 |
1280 | pop edi |
1260 | pop edi |
1281 | mov eax,[eax+4] |
1261 | mov eax,[eax+4] |
1282 | ret |
1262 | ret |
1283 | extend_tree: |
1263 | extend_tree: |
1284 | mov edx,[free_additional_memory] |
1264 | mov edx,[free_additional_memory] |
1285 | lea eax,[edx+8] |
1265 | lea eax,[edx+8] |
1286 | cmp eax,[additional_memory_end] |
1266 | cmp eax,[additional_memory_end] |
1287 | ja out_of_memory |
1267 | ja out_of_memory |
1288 | mov [free_additional_memory],eax |
1268 | mov [free_additional_memory],eax |
1289 | xor eax,eax |
1269 | xor eax,eax |
1290 | mov [edx],eax |
1270 | mov [edx],eax |
1291 | mov [edx+4],eax |
1271 | mov [edx+4],eax |
1292 | shl ebp,1 |
1272 | shl ebp,1 |
1293 | adc eax,0 |
1273 | adc eax,0 |
1294 | mov [ebx],edx |
1274 | mov [ebx],edx |
1295 | lea ebx,[edx+eax*4] |
1275 | lea ebx,[edx+eax*4] |
1296 | dec ecx |
1276 | dec ecx |
1297 | jnz extend_tree |
1277 | jnz extend_tree |
1298 | mov [label_leaf],ebx |
1278 | mov [label_leaf],ebx |
1299 | pop edx |
1279 | pop edx |
1300 | add_label: |
1280 | add_label: |
1301 | mov ecx,edx |
1281 | mov ecx,edx |
1302 | pop esi |
1282 | pop esi |
1303 | cmp byte [esi-2],0 |
1283 | cmp byte [esi-2],0 |
1304 | je label_name_ok |
1284 | je label_name_ok |
1305 | mov al,[esi] |
1285 | mov al,[esi] |
1306 | cmp al,30h |
1286 | cmp al,30h |
1307 | jb name_first_char_ok |
1287 | jb name_first_char_ok |
1308 | cmp al,39h |
1288 | cmp al,39h |
1309 | jbe invalid_name |
1289 | jbe invalid_name |
1310 | name_first_char_ok: |
1290 | name_first_char_ok: |
1311 | cmp al,'$' |
1291 | cmp al,'$' |
1312 | jne check_for_reserved_word |
1292 | jne check_for_reserved_word |
1313 | cmp ecx,1 |
1293 | cmp ecx,1 |
1314 | jne invalid_name |
1294 | jne invalid_name |
1315 | reserved_word: |
1295 | reserved_word: |
1316 | mov eax,0Fh |
1296 | mov eax,0Fh |
1317 | pop edi |
1297 | pop edi |
1318 | ret |
1298 | ret |
1319 | check_for_reserved_word: |
1299 | check_for_reserved_word: |
1320 | call get_instruction |
1300 | call get_instruction |
1321 | jnc reserved_word |
1301 | jnc reserved_word |
1322 | call get_data_directive |
1302 | call get_data_directive |
1323 | jnc reserved_word |
1303 | jnc reserved_word |
1324 | call get_symbol |
1304 | call get_symbol |
1325 | jnc reserved_word |
1305 | jnc reserved_word |
1326 | sub esi,2 |
1306 | sub esi,2 |
1327 | mov edi,operators |
1307 | mov edi,operators |
1328 | call get_operator |
1308 | call get_operator |
1329 | or al,al |
1309 | or al,al |
1330 | jnz reserved_word |
1310 | jnz reserved_word |
1331 | mov edi,single_operand_operators |
1311 | mov edi,single_operand_operators |
1332 | call get_operator |
1312 | call get_operator |
1333 | or al,al |
1313 | or al,al |
1334 | jnz reserved_word |
1314 | jnz reserved_word |
1335 | mov edi,directive_operators |
1315 | mov edi,directive_operators |
1336 | call get_operator |
1316 | call get_operator |
1337 | or al,al |
1317 | or al,al |
1338 | jnz reserved_word |
1318 | jnz reserved_word |
1339 | inc esi |
1319 | inc esi |
1340 | movzx ecx,byte [esi] |
1320 | movzx ecx,byte [esi] |
1341 | inc esi |
1321 | inc esi |
1342 | label_name_ok: |
1322 | label_name_ok: |
1343 | mov edx,[free_additional_memory] |
1323 | mov edx,[free_additional_memory] |
1344 | lea eax,[edx+8] |
1324 | lea eax,[edx+8] |
1345 | cmp eax,[additional_memory_end] |
1325 | cmp eax,[additional_memory_end] |
1346 | ja out_of_memory |
1326 | ja out_of_memory |
1347 | mov [free_additional_memory],eax |
1327 | mov [free_additional_memory],eax |
1348 | mov ebx,esi |
1328 | mov ebx,esi |
1349 | add esi,ecx |
1329 | add esi,ecx |
1350 | mov eax,[label_leaf] |
1330 | mov eax,[label_leaf] |
1351 | mov edi,[eax] |
1331 | mov edi,[eax] |
1352 | mov [edx],edi |
1332 | mov [edx],edi |
1353 | mov [eax],edx |
1333 | mov [eax],edx |
1354 | call allocate_label |
1334 | call allocate_label |
1355 | mov [edx+4],eax |
1335 | mov [edx+4],eax |
1356 | mov [eax+24],ebx |
1336 | mov [eax+24],ebx |
1357 | pop edi |
1337 | pop edi |
1358 | ret |
1338 | ret |
1359 | allocate_label: |
1339 | allocate_label: |
1360 | mov eax,[labels_list] |
1340 | mov eax,[labels_list] |
1361 | mov ecx,LABEL_STRUCTURE_SIZE shr 2 |
1341 | mov ecx,LABEL_STRUCTURE_SIZE shr 2 |
1362 | initialize_label: |
1342 | initialize_label: |
1363 | sub eax,4 |
1343 | sub eax,4 |
1364 | mov dword [eax],0 |
1344 | mov dword [eax],0 |
1365 | loop initialize_label |
1345 | loop initialize_label |
1366 | mov [labels_list],eax |
1346 | mov [labels_list],eax |
1367 | ret |
1347 | ret |
1368 | 1348 | ||
1369 | LABEL_STRUCTURE_SIZE = 32' |
1349 | LABEL_STRUCTURE_SIZE = 32' |
1370 | > |
1350 | > |