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