Rev 7836 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7836 | leency | 1 | |
2 | ; Copyright (c) 1999-2021, Tomasz Grysztar. |
||
9459 | leency | 3 | ; All rights reserved. |
7836 | leency | 4 | |
5 | |||
6 | xor eax,eax |
||
7 | mov [stub_size],eax |
||
8 | mov [current_pass],ax |
||
9 | mov [resolver_flags],eax |
||
10 | mov [number_of_sections],eax |
||
11 | mov [actual_fixups_size],eax |
||
12 | assembler_loop: |
||
13 | mov eax,[labels_list] |
||
14 | mov [tagged_blocks],eax |
||
15 | mov eax,[additional_memory] |
||
16 | mov [free_additional_memory],eax |
||
17 | mov eax,[additional_memory_end] |
||
18 | mov [structures_buffer],eax |
||
19 | mov esi,[source_start] |
||
20 | mov edi,[code_start] |
||
21 | xor eax,eax |
||
22 | mov dword [adjustment],eax |
||
23 | mov dword [adjustment+4],eax |
||
24 | mov [addressing_space],eax |
||
25 | mov [error_line],eax |
||
26 | mov [counter],eax |
||
27 | mov [format_flags],eax |
||
28 | mov [number_of_relocations],eax |
||
29 | mov [undefined_data_end],eax |
||
30 | mov [file_extension],eax |
||
31 | mov [next_pass_needed],al |
||
32 | mov [output_format],al |
||
33 | mov [adjustment_sign],al |
||
34 | mov [evex_mode],al |
||
35 | mov [code_type],16 |
||
36 | call init_addressing_space |
||
37 | pass_loop: |
||
38 | call assemble_line |
||
39 | jnc pass_loop |
||
40 | mov eax,[additional_memory_end] |
||
41 | cmp eax,[structures_buffer] |
||
42 | je pass_done |
||
43 | sub eax,18h |
||
44 | mov eax,[eax+4] |
||
45 | mov [current_line],eax |
||
46 | jmp missing_end_directive |
||
47 | pass_done: |
||
48 | call close_pass |
||
49 | mov eax,[labels_list] |
||
50 | check_symbols: |
||
51 | cmp eax,[memory_end] |
||
52 | jae symbols_checked |
||
53 | test byte [eax+8],8 |
||
54 | jz symbol_defined_ok |
||
55 | mov cx,[current_pass] |
||
56 | cmp cx,[eax+18] |
||
57 | jne symbol_defined_ok |
||
58 | test byte [eax+8],1 |
||
59 | jz symbol_defined_ok |
||
60 | sub cx,[eax+16] |
||
61 | cmp cx,1 |
||
62 | jne symbol_defined_ok |
||
63 | and byte [eax+8],not 1 |
||
64 | or [next_pass_needed],-1 |
||
65 | symbol_defined_ok: |
||
66 | test byte [eax+8],10h |
||
67 | jz use_prediction_ok |
||
68 | mov cx,[current_pass] |
||
69 | and byte [eax+8],not 10h |
||
70 | test byte [eax+8],20h |
||
71 | jnz check_use_prediction |
||
72 | cmp cx,[eax+18] |
||
73 | jne use_prediction_ok |
||
74 | test byte [eax+8],8 |
||
75 | jz use_prediction_ok |
||
76 | jmp use_misprediction |
||
77 | check_use_prediction: |
||
78 | test byte [eax+8],8 |
||
79 | jz use_misprediction |
||
80 | cmp cx,[eax+18] |
||
81 | je use_prediction_ok |
||
82 | use_misprediction: |
||
83 | or [next_pass_needed],-1 |
||
84 | use_prediction_ok: |
||
85 | test byte [eax+8],40h |
||
86 | jz check_next_symbol |
||
87 | and byte [eax+8],not 40h |
||
88 | test byte [eax+8],4 |
||
89 | jnz define_misprediction |
||
90 | mov cx,[current_pass] |
||
91 | test byte [eax+8],80h |
||
92 | jnz check_define_prediction |
||
93 | cmp cx,[eax+16] |
||
94 | jne check_next_symbol |
||
95 | test byte [eax+8],1 |
||
96 | jz check_next_symbol |
||
97 | jmp define_misprediction |
||
98 | check_define_prediction: |
||
99 | test byte [eax+8],1 |
||
100 | jz define_misprediction |
||
101 | cmp cx,[eax+16] |
||
102 | je check_next_symbol |
||
103 | define_misprediction: |
||
104 | or [next_pass_needed],-1 |
||
105 | check_next_symbol: |
||
106 | add eax,LABEL_STRUCTURE_SIZE |
||
107 | jmp check_symbols |
||
108 | symbols_checked: |
||
109 | cmp [next_pass_needed],0 |
||
110 | jne next_pass |
||
111 | mov eax,[error_line] |
||
112 | or eax,eax |
||
113 | jz assemble_ok |
||
114 | mov [current_line],eax |
||
115 | cmp [error],undefined_symbol |
||
116 | jne error_confirmed |
||
117 | mov eax,[error_info] |
||
118 | or eax,eax |
||
119 | jz error_confirmed |
||
120 | test byte [eax+8],1 |
||
121 | jnz next_pass |
||
122 | error_confirmed: |
||
123 | call error_handler |
||
124 | error_handler: |
||
125 | mov eax,[error] |
||
126 | sub eax,error_handler |
||
127 | add [esp],eax |
||
128 | ret |
||
129 | next_pass: |
||
130 | inc [current_pass] |
||
131 | mov ax,[current_pass] |
||
132 | cmp ax,[passes_limit] |
||
133 | je code_cannot_be_generated |
||
134 | jmp assembler_loop |
||
135 | assemble_ok: |
||
136 | ret |
||
137 | |||
138 | |||
139 | mov ebx,[addressing_space] |
||
140 | test ebx,ebx |
||
141 | jz init_addressing_space |
||
142 | test byte [ebx+0Ah],1 |
||
143 | jnz illegal_instruction |
||
144 | mov eax,edi |
||
145 | sub eax,[ebx+18h] |
||
146 | mov [ebx+1Ch],eax |
||
147 | init_addressing_space: |
||
148 | mov ebx,[tagged_blocks] |
||
149 | mov dword [ebx-4],10h |
||
150 | mov dword [ebx-8],24h |
||
151 | sub ebx,8+24h |
||
152 | cmp ebx,edi |
||
153 | jbe out_of_memory |
||
154 | mov [tagged_blocks],ebx |
||
155 | mov [addressing_space],ebx |
||
156 | xor eax,eax |
||
157 | mov [ebx],edi |
||
158 | mov [ebx+4],eax |
||
159 | mov [ebx+8],eax |
||
160 | mov [ebx+10h],eax |
||
161 | mov [ebx+14h],eax |
||
162 | mov [ebx+18h],edi |
||
163 | mov [ebx+1Ch],eax |
||
164 | mov [ebx+20h],eax |
||
165 | ret |
||
166 | |||
167 | |||
168 | mov eax,[tagged_blocks] |
||
169 | sub eax,100h |
||
170 | cmp edi,eax |
||
171 | ja out_of_memory |
||
172 | lods byte [esi] |
||
173 | cmp al,1 |
||
174 | je assemble_instruction |
||
175 | jb source_end |
||
176 | cmp al,3 |
||
177 | jb define_label |
||
178 | je define_constant |
||
179 | cmp al,4 |
||
180 | je label_addressing_space |
||
181 | cmp al,0Fh |
||
182 | je new_line |
||
183 | cmp al,13h |
||
184 | je code_type_setting |
||
185 | cmp al,10h |
||
186 | jne illegal_instruction |
||
187 | lods byte [esi] |
||
188 | jmp segment_prefix |
||
189 | code_type_setting: |
||
190 | lods byte [esi] |
||
191 | mov [code_type],al |
||
192 | jmp instruction_assembled |
||
193 | new_line: |
||
194 | lods dword [esi] |
||
195 | mov [current_line],eax |
||
196 | and [prefix_flags],0 |
||
197 | cmp [symbols_file],0 |
||
198 | je continue_line |
||
199 | cmp [next_pass_needed],0 |
||
200 | jne continue_line |
||
201 | mov ebx,[tagged_blocks] |
||
202 | mov dword [ebx-4],1 |
||
203 | mov dword [ebx-8],14h |
||
204 | sub ebx,8+14h |
||
205 | cmp ebx,edi |
||
206 | jbe out_of_memory |
||
207 | mov [tagged_blocks],ebx |
||
208 | mov [ebx],eax |
||
209 | mov [ebx+4],edi |
||
210 | mov eax,[addressing_space] |
||
211 | mov [ebx+8],eax |
||
212 | mov al,[code_type] |
||
213 | mov [ebx+10h],al |
||
214 | continue_line: |
||
215 | cmp byte [esi],0Fh |
||
216 | je line_assembled |
||
217 | jmp assemble_line |
||
218 | define_label: |
||
219 | lods dword [esi] |
||
220 | cmp eax,0Fh |
||
221 | jb invalid_use_of_symbol |
||
222 | je reserved_word_used_as_symbol |
||
223 | mov ebx,eax |
||
224 | lods byte [esi] |
||
225 | mov [label_size],al |
||
226 | call make_label |
||
227 | jmp continue_line |
||
228 | make_label: |
||
229 | mov eax,edi |
||
230 | xor edx,edx |
||
231 | xor cl,cl |
||
232 | mov ebp,[addressing_space] |
||
233 | sub eax,[ds:ebp] |
||
234 | sbb edx,[ds:ebp+4] |
||
235 | sbb cl,[ds:ebp+8] |
||
236 | jp label_value_ok |
||
237 | call recoverable_overflow |
||
238 | label_value_ok: |
||
239 | mov [address_sign],cl |
||
240 | test byte [ds:ebp+0Ah],1 |
||
241 | jnz make_virtual_label |
||
242 | or byte [ebx+9],1 |
||
243 | xchg eax,[ebx] |
||
244 | xchg edx,[ebx+4] |
||
245 | mov ch,[ebx+9] |
||
246 | shr ch,1 |
||
247 | and ch,1 |
||
248 | neg ch |
||
249 | sub eax,[ebx] |
||
250 | sbb edx,[ebx+4] |
||
251 | sbb ch,cl |
||
252 | mov dword [adjustment],eax |
||
253 | mov dword [adjustment+4],edx |
||
254 | mov [adjustment_sign],ch |
||
255 | or al,ch |
||
256 | or eax,edx |
||
257 | setnz ah |
||
258 | jmp finish_label |
||
259 | make_virtual_label: |
||
260 | and byte [ebx+9],not 1 |
||
261 | cmp eax,[ebx] |
||
262 | mov [ebx],eax |
||
263 | setne ah |
||
264 | cmp edx,[ebx+4] |
||
265 | mov [ebx+4],edx |
||
266 | setne al |
||
267 | or ah,al |
||
268 | finish_label: |
||
269 | mov ebp,[addressing_space] |
||
270 | mov ch,[ds:ebp+9] |
||
271 | mov cl,[label_size] |
||
272 | mov edx,[ds:ebp+14h] |
||
273 | mov ebp,[ds:ebp+10h] |
||
274 | finish_label_symbol: |
||
275 | mov al,[address_sign] |
||
276 | xor al,[ebx+9] |
||
277 | and al,10b |
||
278 | or ah,al |
||
279 | xor [ebx+9],al |
||
280 | cmp cl,[ebx+10] |
||
281 | mov [ebx+10],cl |
||
282 | setne al |
||
283 | or ah,al |
||
284 | cmp ch,[ebx+11] |
||
285 | mov [ebx+11],ch |
||
286 | setne al |
||
287 | or ah,al |
||
288 | cmp ebp,[ebx+12] |
||
289 | mov [ebx+12],ebp |
||
290 | setne al |
||
291 | or ah,al |
||
292 | or ch,ch |
||
293 | jz label_symbol_ok |
||
294 | cmp edx,[ebx+20] |
||
295 | mov [ebx+20],edx |
||
296 | setne al |
||
297 | or ah,al |
||
298 | label_symbol_ok: |
||
299 | mov cx,[current_pass] |
||
300 | xchg [ebx+16],cx |
||
301 | mov edx,[current_line] |
||
302 | mov [ebx+28],edx |
||
303 | and byte [ebx+8],not 2 |
||
304 | test byte [ebx+8],1 |
||
305 | jz new_label |
||
306 | cmp cx,[ebx+16] |
||
307 | je symbol_already_defined |
||
308 | btr dword [ebx+8],10 |
||
309 | jc requalified_label |
||
310 | inc cx |
||
311 | sub cx,[ebx+16] |
||
312 | setnz al |
||
313 | or ah,al |
||
314 | jz label_made |
||
315 | test byte [ebx+8],8 |
||
316 | jz label_made |
||
317 | mov cx,[current_pass] |
||
318 | cmp cx,[ebx+18] |
||
319 | jne label_made |
||
320 | requalified_label: |
||
321 | or [next_pass_needed],-1 |
||
322 | label_made: |
||
323 | ret |
||
324 | new_label: |
||
325 | or byte [ebx+8],1 |
||
326 | ret |
||
327 | define_constant: |
||
328 | lods dword [esi] |
||
329 | inc esi |
||
330 | cmp eax,0Fh |
||
331 | jb invalid_use_of_symbol |
||
332 | je reserved_word_used_as_symbol |
||
333 | push eax |
||
334 | or [operand_flags],1 |
||
335 | call get_value |
||
336 | pop ebx |
||
337 | xor cl,cl |
||
338 | mov ch,[value_type] |
||
339 | cmp ch,3 |
||
340 | je invalid_use_of_symbol |
||
341 | make_constant: |
||
342 | and byte [ebx+9],not 1 |
||
343 | cmp eax,[ebx] |
||
344 | mov [ebx],eax |
||
345 | setne ah |
||
346 | cmp edx,[ebx+4] |
||
347 | mov [ebx+4],edx |
||
348 | setne al |
||
349 | or ah,al |
||
350 | mov al,[value_sign] |
||
351 | xor al,[ebx+9] |
||
352 | and al,10b |
||
353 | or ah,al |
||
354 | xor [ebx+9],al |
||
355 | cmp cl,[ebx+10] |
||
356 | mov [ebx+10],cl |
||
357 | setne al |
||
358 | or ah,al |
||
359 | cmp ch,[ebx+11] |
||
360 | mov [ebx+11],ch |
||
361 | setne al |
||
362 | or ah,al |
||
363 | xor edx,edx |
||
364 | cmp edx,[ebx+12] |
||
365 | mov [ebx+12],edx |
||
366 | setne al |
||
367 | or ah,al |
||
368 | or ch,ch |
||
369 | jz constant_symbol_ok |
||
370 | mov edx,[symbol_identifier] |
||
371 | cmp edx,[ebx+20] |
||
372 | mov [ebx+20],edx |
||
373 | setne al |
||
374 | or ah,al |
||
375 | constant_symbol_ok: |
||
376 | mov cx,[current_pass] |
||
377 | xchg [ebx+16],cx |
||
378 | mov edx,[current_line] |
||
379 | mov [ebx+28],edx |
||
380 | test byte [ebx+8],1 |
||
381 | jz new_constant |
||
382 | cmp cx,[ebx+16] |
||
383 | jne redeclare_constant |
||
384 | test byte [ebx+8],2 |
||
385 | jz symbol_already_defined |
||
386 | or byte [ebx+8],4 |
||
387 | and byte [ebx+9],not 4 |
||
388 | jmp instruction_assembled |
||
389 | redeclare_constant: |
||
390 | btr dword [ebx+8],10 |
||
391 | jc requalified_constant |
||
392 | inc cx |
||
393 | sub cx,[ebx+16] |
||
394 | setnz al |
||
395 | or ah,al |
||
396 | jz instruction_assembled |
||
397 | test byte [ebx+8],4 |
||
398 | jnz instruction_assembled |
||
399 | test byte [ebx+8],8 |
||
400 | jz instruction_assembled |
||
401 | mov cx,[current_pass] |
||
402 | cmp cx,[ebx+18] |
||
403 | jne instruction_assembled |
||
404 | requalified_constant: |
||
405 | or [next_pass_needed],-1 |
||
406 | jmp instruction_assembled |
||
407 | new_constant: |
||
408 | or byte [ebx+8],1+2 |
||
409 | jmp instruction_assembled |
||
410 | label_addressing_space: |
||
411 | lods dword [esi] |
||
412 | cmp eax,0Fh |
||
413 | jb invalid_use_of_symbol |
||
414 | je reserved_word_used_as_symbol |
||
415 | mov cx,[current_pass] |
||
416 | test byte [eax+8],1 |
||
417 | jz make_addressing_space_label |
||
418 | cmp cx,[eax+16] |
||
419 | je symbol_already_defined |
||
420 | test byte [eax+9],4 |
||
421 | jnz make_addressing_space_label |
||
422 | or [next_pass_needed],-1 |
||
423 | make_addressing_space_label: |
||
424 | mov dx,[eax+8] |
||
425 | and dx,not (2 or 100h) |
||
426 | or dx,1 or 4 or 400h |
||
427 | mov [eax+8],dx |
||
428 | mov [eax+16],cx |
||
429 | mov edx,[current_line] |
||
430 | mov [eax+28],edx |
||
431 | mov ebx,[addressing_space] |
||
432 | mov [eax],ebx |
||
433 | or byte [ebx+0Ah],2 |
||
434 | jmp continue_line |
||
435 | assemble_instruction: |
||
436 | ; mov [operand_size],0 |
||
437 | ; mov [operand_flags],0 |
||
438 | ; mov [operand_prefix],0 |
||
439 | ; mov [rex_prefix],0 |
||
440 | and dword [operand_size],0 |
||
441 | ; mov [opcode_prefix],0 |
||
442 | ; mov [vex_required],0 |
||
443 | ; mov [vex_register],0 |
||
444 | ; mov [immediate_size],0 |
||
445 | and dword [opcode_prefix],0 |
||
446 | call instruction_handler |
||
447 | instruction_handler: |
||
448 | movzx ebx,word [esi] |
||
449 | mov al,[esi+2] |
||
450 | add esi,3 |
||
451 | add [esp],ebx |
||
452 | ret |
||
453 | instruction_assembled: |
||
454 | test [prefix_flags],not 1 |
||
455 | jnz illegal_instruction |
||
456 | mov al,[esi] |
||
457 | cmp al,0Fh |
||
458 | je line_assembled |
||
459 | or al,al |
||
460 | jnz extra_characters_on_line |
||
461 | line_assembled: |
||
462 | clc |
||
463 | ret |
||
464 | source_end: |
||
465 | dec esi |
||
466 | stc |
||
467 | ret |
||
468 | |||
469 | |||
470 | lods byte [esi] |
||
471 | cmp al,'(' |
||
472 | jne invalid_argument |
||
473 | cmp byte [esi],'.' |
||
474 | je invalid_value |
||
475 | call get_qword_value |
||
476 | mov cl,[value_type] |
||
477 | test cl,1 |
||
478 | jnz invalid_use_of_symbol |
||
479 | push eax |
||
480 | mov ebx,[addressing_space] |
||
481 | mov eax,edi |
||
482 | sub eax,[ebx+18h] |
||
483 | mov [ebx+1Ch],eax |
||
484 | test byte [ebx+0Ah],1 |
||
485 | jnz in_virtual |
||
486 | call init_addressing_space |
||
487 | jmp org_space_ok |
||
488 | in_virtual: |
||
489 | call close_virtual_addressing_space |
||
490 | call init_addressing_space |
||
491 | or byte [ebx+0Ah],1 |
||
492 | org_space_ok: |
||
493 | pop eax |
||
494 | mov [ebx+9],cl |
||
495 | mov cl,[value_sign] |
||
496 | sub [ebx],eax |
||
497 | sbb [ebx+4],edx |
||
498 | sbb byte [ebx+8],cl |
||
499 | jp org_value_ok |
||
500 | call recoverable_overflow |
||
501 | org_value_ok: |
||
502 | mov edx,[symbol_identifier] |
||
503 | mov [ebx+14h],edx |
||
504 | cmp [output_format],1 |
||
505 | ja instruction_assembled |
||
506 | cmp edi,[code_start] |
||
507 | jne instruction_assembled |
||
508 | cmp eax,100h |
||
509 | jne instruction_assembled |
||
510 | bts [format_flags],0 |
||
511 | jmp instruction_assembled |
||
512 | label_directive: |
||
513 | lods byte [esi] |
||
514 | cmp al,2 |
||
515 | jne invalid_argument |
||
516 | lods dword [esi] |
||
517 | cmp eax,0Fh |
||
518 | jb invalid_use_of_symbol |
||
519 | je reserved_word_used_as_symbol |
||
520 | inc esi |
||
521 | mov ebx,eax |
||
522 | mov [label_size],0 |
||
523 | lods byte [esi] |
||
524 | cmp al,':' |
||
525 | je get_label_size |
||
526 | dec esi |
||
527 | cmp al,11h |
||
528 | jne label_size_ok |
||
529 | get_label_size: |
||
530 | lods word [esi] |
||
531 | cmp al,11h |
||
532 | jne invalid_argument |
||
533 | mov [label_size],ah |
||
534 | label_size_ok: |
||
535 | cmp byte [esi],80h |
||
536 | je get_free_label_value |
||
537 | call make_label |
||
538 | jmp instruction_assembled |
||
539 | get_free_label_value: |
||
540 | inc esi |
||
541 | lods byte [esi] |
||
542 | cmp al,'(' |
||
543 | jne invalid_argument |
||
544 | push ebx ecx |
||
545 | or byte [ebx+8],4 |
||
546 | cmp byte [esi],'.' |
||
547 | je invalid_value |
||
548 | call get_address_value |
||
549 | or bh,bh |
||
550 | setnz ch |
||
551 | xchg ch,cl |
||
552 | mov bp,cx |
||
553 | shl ebp,16 |
||
554 | xchg bl,bh |
||
555 | mov bp,bx |
||
556 | pop ecx ebx |
||
557 | and byte [ebx+8],not 4 |
||
558 | mov ch,[value_type] |
||
559 | test ch,1 |
||
560 | jnz invalid_use_of_symbol |
||
561 | make_free_label: |
||
562 | and byte [ebx+9],not 1 |
||
563 | cmp eax,[ebx] |
||
564 | mov [ebx],eax |
||
565 | setne ah |
||
566 | cmp edx,[ebx+4] |
||
567 | mov [ebx+4],edx |
||
568 | setne al |
||
569 | or ah,al |
||
570 | mov edx,[address_symbol] |
||
571 | mov cl,[label_size] |
||
572 | call finish_label_symbol |
||
573 | jmp instruction_assembled |
||
574 | load_directive: |
||
575 | lods byte [esi] |
||
576 | cmp al,2 |
||
577 | jne invalid_argument |
||
578 | lods dword [esi] |
||
579 | cmp eax,0Fh |
||
580 | jb invalid_use_of_symbol |
||
581 | je reserved_word_used_as_symbol |
||
582 | inc esi |
||
583 | push eax |
||
584 | mov al,1 |
||
585 | cmp byte [esi],11h |
||
586 | jne load_size_ok |
||
587 | lods byte [esi] |
||
588 | lods byte [esi] |
||
589 | load_size_ok: |
||
590 | cmp al,8 |
||
591 | ja invalid_value |
||
592 | mov [operand_size],al |
||
593 | and dword [value],0 |
||
594 | and dword [value+4],0 |
||
595 | lods byte [esi] |
||
596 | cmp al,82h |
||
597 | jne invalid_argument |
||
598 | call get_data_point |
||
599 | jc value_loaded |
||
600 | push esi edi |
||
601 | mov esi,ebx |
||
602 | mov edi,value |
||
603 | rep movs byte [edi],[esi] |
||
604 | pop edi esi |
||
605 | value_loaded: |
||
606 | mov [value_sign],0 |
||
607 | mov eax,dword [value] |
||
608 | mov edx,dword [value+4] |
||
609 | pop ebx |
||
610 | xor cx,cx |
||
611 | jmp make_constant |
||
612 | get_data_point: |
||
613 | lods byte [esi] |
||
614 | cmp al,':' |
||
615 | je get_data_offset |
||
616 | cmp al,'(' |
||
617 | jne invalid_argument |
||
618 | mov ebx,[addressing_space] |
||
619 | mov ecx,edi |
||
620 | sub ecx,[ebx+18h] |
||
621 | mov [ebx+1Ch],ecx |
||
622 | cmp byte [esi],11h |
||
623 | jne get_data_address |
||
624 | cmp word [esi+1+4],'):' |
||
625 | jne get_data_address |
||
626 | inc esi |
||
627 | lods dword [esi] |
||
628 | add esi,2 |
||
629 | cmp byte [esi],'(' |
||
630 | jne invalid_argument |
||
631 | inc esi |
||
632 | cmp eax,0Fh |
||
633 | jbe reserved_word_used_as_symbol |
||
634 | mov edx,undefined_symbol |
||
635 | test byte [eax+8],1 |
||
636 | jz addressing_space_unavailable |
||
637 | mov edx,symbol_out_of_scope |
||
638 | mov cx,[eax+16] |
||
639 | cmp cx,[current_pass] |
||
640 | jne addressing_space_unavailable |
||
641 | test byte [eax+9],4 |
||
642 | jz invalid_use_of_symbol |
||
643 | mov ebx,eax |
||
644 | mov ax,[current_pass] |
||
645 | mov [ebx+18],ax |
||
646 | or byte [ebx+8],8 |
||
647 | call store_label_reference |
||
648 | get_addressing_space: |
||
649 | mov ebx,[ebx] |
||
650 | get_data_address: |
||
651 | push ebx |
||
652 | cmp byte [esi],'.' |
||
653 | je invalid_value |
||
654 | or [operand_flags],1 |
||
655 | call get_address_value |
||
656 | pop ebp |
||
657 | call calculate_relative_offset |
||
658 | cmp [next_pass_needed],0 |
||
659 | jne data_address_type_ok |
||
660 | cmp [value_type],0 |
||
661 | jne invalid_use_of_symbol |
||
662 | data_address_type_ok: |
||
663 | mov ebx,edi |
||
664 | xor ecx,ecx |
||
665 | add ebx,eax |
||
666 | adc edx,ecx |
||
667 | mov eax,ebx |
||
668 | sub eax,[ds:ebp+18h] |
||
669 | sbb edx,ecx |
||
670 | jnz bad_data_address |
||
671 | mov cl,[operand_size] |
||
672 | add eax,ecx |
||
673 | cmp eax,[ds:ebp+1Ch] |
||
674 | ja bad_data_address |
||
675 | clc |
||
676 | ret |
||
677 | addressing_space_unavailable: |
||
678 | cmp [error_line],0 |
||
679 | jne get_data_address |
||
680 | push [current_line] |
||
681 | pop [error_line] |
||
682 | mov [error],edx |
||
683 | mov [error_info],eax |
||
684 | jmp get_data_address |
||
685 | bad_data_address: |
||
686 | call recoverable_overflow |
||
687 | stc |
||
688 | ret |
||
689 | get_data_offset: |
||
690 | cmp [output_format],2 |
||
691 | jae invalid_operand |
||
692 | lods byte [esi] |
||
693 | cmp al,'(' |
||
694 | jne invalid_argument |
||
695 | cmp byte [esi],'.' |
||
696 | je invalid_value |
||
697 | call get_dword_value |
||
698 | cmp [value_type],0 |
||
699 | je data_offset_ok |
||
700 | call recoverable_invalid_address |
||
701 | data_offset_ok: |
||
702 | add eax,[code_start] |
||
703 | jc bad_data_address |
||
704 | mov ebx,eax |
||
705 | movzx ecx,[operand_size] |
||
706 | add eax,ecx |
||
707 | jc bad_data_address |
||
708 | mov edx,[addressing_space] |
||
709 | test byte [edx+0Ah],1 |
||
710 | jnz data_offset_from_virtual |
||
711 | cmp eax,edi |
||
712 | ja bad_data_address |
||
713 | clc |
||
714 | ret |
||
715 | data_offset_from_virtual: |
||
716 | cmp eax,[undefined_data_end] |
||
717 | ja bad_data_address |
||
718 | clc |
||
719 | ret |
||
720 | |||
721 | |||
722 | cmp byte [esi],11h |
||
723 | je sized_store |
||
724 | lods byte [esi] |
||
725 | cmp al,'(' |
||
726 | jne invalid_argument |
||
727 | call get_byte_value |
||
728 | xor edx,edx |
||
729 | movzx eax,al |
||
730 | mov [operand_size],1 |
||
731 | jmp store_value_ok |
||
732 | sized_store: |
||
733 | or [operand_flags],1 |
||
734 | call get_value |
||
735 | store_value_ok: |
||
736 | cmp [value_type],0 |
||
737 | jne invalid_use_of_symbol |
||
738 | mov dword [value],eax |
||
739 | mov dword [value+4],edx |
||
740 | lods byte [esi] |
||
741 | cmp al,80h |
||
742 | jne invalid_argument |
||
743 | call get_data_point |
||
744 | jc instruction_assembled |
||
745 | push esi edi |
||
746 | mov esi,value |
||
747 | mov edi,ebx |
||
748 | rep movs byte [edi],[esi] |
||
749 | mov eax,edi |
||
750 | pop edi esi |
||
751 | cmp ebx,[undefined_data_end] |
||
752 | jae instruction_assembled |
||
753 | cmp eax,[undefined_data_start] |
||
754 | jbe instruction_assembled |
||
755 | mov [undefined_data_start],eax |
||
756 | jmp instruction_assembled |
||
757 | |||
758 | |||
759 | lods byte [esi] |
||
760 | cmp al,'(' |
||
761 | jne invalid_argument |
||
762 | cmp byte [esi],0 |
||
763 | jne display_byte |
||
764 | inc esi |
||
765 | lods dword [esi] |
||
766 | mov ecx,eax |
||
767 | push edi |
||
768 | mov edi,[tagged_blocks] |
||
769 | sub edi,8 |
||
770 | sub edi,eax |
||
771 | cmp edi,[esp] |
||
772 | jbe out_of_memory |
||
773 | mov [tagged_blocks],edi |
||
774 | rep movs byte [edi],[esi] |
||
775 | stos dword [edi] |
||
776 | xor eax,eax |
||
777 | stos dword [edi] |
||
778 | pop edi |
||
779 | inc esi |
||
780 | jmp display_next |
||
781 | display_byte: |
||
782 | call get_byte_value |
||
783 | push edi |
||
784 | mov edi,[tagged_blocks] |
||
785 | sub edi,8+1 |
||
786 | mov [tagged_blocks],edi |
||
787 | stos byte [edi] |
||
788 | mov eax,1 |
||
789 | stos dword [edi] |
||
790 | dec eax |
||
791 | stos dword [edi] |
||
792 | pop edi |
||
793 | display_next: |
||
794 | cmp edi,[tagged_blocks] |
||
795 | ja out_of_memory |
||
796 | lods byte [esi] |
||
797 | cmp al,',' |
||
798 | je display_directive |
||
799 | dec esi |
||
800 | jmp instruction_assembled |
||
801 | show_display_buffer: |
||
802 | mov eax,[tagged_blocks] |
||
803 | or eax,eax |
||
804 | jz display_done |
||
805 | mov esi,[labels_list] |
||
806 | cmp esi,eax |
||
807 | je display_done |
||
808 | display_messages: |
||
809 | sub esi,8 |
||
810 | mov eax,[esi+4] |
||
811 | mov ecx,[esi] |
||
812 | sub esi,ecx |
||
813 | cmp eax,10h |
||
814 | je write_addressing_space |
||
815 | test eax,eax |
||
816 | jnz skip_block |
||
817 | push esi |
||
818 | call display_block |
||
819 | pop esi |
||
820 | skip_block: |
||
821 | cmp esi,[tagged_blocks] |
||
822 | jne display_messages |
||
823 | display_done: |
||
824 | ret |
||
825 | write_addressing_space: |
||
826 | mov ecx,[esi+20h] |
||
827 | jecxz skip_block |
||
828 | push esi |
||
829 | mov edi,[free_additional_memory] |
||
830 | mov esi,[output_file] |
||
831 | test esi,esi |
||
832 | jz addressing_space_written |
||
833 | xor ebx,ebx |
||
834 | copy_output_path: |
||
835 | lodsb |
||
836 | cmp edi,[structures_buffer] |
||
837 | jae out_of_memory |
||
838 | stosb |
||
839 | test al,al |
||
840 | jz output_path_copied |
||
841 | cmp al,'/' |
||
842 | je new_path_segment |
||
843 | cmp al,'\' |
||
844 | je new_path_segment |
||
845 | cmp al,'.' |
||
846 | jne copy_output_path |
||
847 | mov ebx,edi |
||
848 | jmp copy_output_path |
||
849 | new_path_segment: |
||
850 | xor ebx,ebx |
||
851 | jmp copy_output_path |
||
852 | output_path_copied: |
||
853 | test ebx,ebx |
||
854 | jnz append_extension |
||
855 | mov byte [edi-1],'.' |
||
856 | mov ebx,edi |
||
857 | append_extension: |
||
858 | mov edi,ebx |
||
859 | add ebx,ecx |
||
860 | inc ebx |
||
861 | cmp ebx,[structures_buffer] |
||
862 | jae out_of_memory |
||
863 | mov esi,[esp] |
||
864 | mov esi,[esi+18h] |
||
865 | sub esi,ecx |
||
866 | rep movs byte [edi],[esi] |
||
867 | xor al,al |
||
868 | stos byte [edi] |
||
869 | mov edx,[free_additional_memory] |
||
870 | call create |
||
871 | jc write_failed |
||
872 | mov esi,[esp] |
||
873 | mov edx,[esi+18h] |
||
874 | mov ecx,[esi+1Ch] |
||
875 | call write |
||
876 | jc write_failed |
||
877 | call close |
||
878 | addressing_space_written: |
||
879 | pop esi |
||
880 | jmp skip_block |
||
881 | |||
882 | |||
883 | lods byte [esi] |
||
884 | cmp al,'(' |
||
885 | jne invalid_argument |
||
886 | cmp byte [esi],'.' |
||
887 | je invalid_value |
||
888 | call get_count_value |
||
889 | cmp eax,0 |
||
890 | je zero_times |
||
891 | cmp byte [esi],':' |
||
892 | jne times_argument_ok |
||
893 | inc esi |
||
894 | times_argument_ok: |
||
895 | push [counter] |
||
896 | push [counter_limit] |
||
897 | mov [counter_limit],eax |
||
898 | mov [counter],1 |
||
899 | times_loop: |
||
900 | mov eax,esp |
||
901 | sub eax,[stack_limit] |
||
902 | cmp eax,100h |
||
903 | jb stack_overflow |
||
904 | push esi |
||
905 | or [prefix_flags],1 |
||
906 | call continue_line |
||
907 | mov eax,[counter_limit] |
||
908 | cmp [counter],eax |
||
909 | je times_done |
||
910 | inc [counter] |
||
911 | pop esi |
||
912 | jmp times_loop |
||
913 | times_done: |
||
914 | pop eax |
||
915 | pop [counter_limit] |
||
916 | pop [counter] |
||
917 | jmp instruction_assembled |
||
918 | zero_times: |
||
919 | call skip_symbol |
||
920 | jnc zero_times |
||
921 | jmp instruction_assembled |
||
922 | |||
923 | |||
924 | lods byte [esi] |
||
925 | cmp al,'(' |
||
926 | je continue_virtual_area |
||
927 | cmp al,80h |
||
928 | jne virtual_at_current |
||
929 | lods byte [esi] |
||
930 | cmp al,'(' |
||
931 | jne invalid_argument |
||
932 | cmp byte [esi],'.' |
||
933 | je invalid_value |
||
934 | call get_address_value |
||
935 | mov ebp,[address_symbol] |
||
936 | or bh,bh |
||
937 | setnz ch |
||
938 | jmp set_virtual |
||
939 | virtual_at_current: |
||
940 | dec esi |
||
941 | virtual_fallback: |
||
942 | mov ebp,[addressing_space] |
||
943 | mov al,[ds:ebp+9] |
||
944 | mov [value_type],al |
||
945 | mov eax,edi |
||
946 | xor edx,edx |
||
947 | xor cl,cl |
||
948 | sub eax,[ds:ebp] |
||
949 | sbb edx,[ds:ebp+4] |
||
950 | sbb cl,[ds:ebp+8] |
||
951 | mov [address_sign],cl |
||
952 | mov bx,[ds:ebp+10h] |
||
953 | mov cx,[ds:ebp+10h+2] |
||
954 | xchg bh,bl |
||
955 | xchg ch,cl |
||
956 | mov ebp,[ds:ebp+14h] |
||
957 | set_virtual: |
||
958 | xchg bl,bh |
||
959 | xchg cl,ch |
||
960 | shl ecx,16 |
||
961 | mov cx,bx |
||
962 | push ecx eax |
||
963 | mov ebx,[addressing_space] |
||
964 | test byte [ebx+0Ah],1 |
||
965 | jnz non_virtual_end_ok |
||
966 | mov eax,edi |
||
967 | xchg eax,[undefined_data_end] |
||
968 | cmp eax,edi |
||
969 | je non_virtual_end_ok |
||
970 | mov [undefined_data_start],edi |
||
971 | non_virtual_end_ok: |
||
972 | call allocate_virtual_structure_data |
||
973 | call init_addressing_space |
||
974 | or byte [ebx+0Ah],1 |
||
975 | cmp byte [esi],86h |
||
976 | jne addressing_space_extension_ok |
||
977 | cmp word [esi+1],'(' |
||
978 | jne invalid_argument |
||
979 | mov ecx,[esi+3] |
||
980 | add esi,3+4 |
||
981 | add [ebx+18h],ecx |
||
982 | mov [ebx+20h],ecx |
||
983 | or byte [ebx+0Ah],2 |
||
984 | push ebx |
||
985 | mov ebx,characters |
||
986 | get_extension: |
||
987 | lods byte [esi] |
||
988 | stos byte [edi] |
||
989 | xlat byte [ebx] |
||
990 | test al,al |
||
991 | jz invalid_argument |
||
992 | loop get_extension |
||
993 | inc esi |
||
994 | pop ebx |
||
995 | addressing_space_extension_ok: |
||
996 | pop eax |
||
997 | mov cl,[address_sign] |
||
998 | not eax |
||
999 | not edx |
||
1000 | not cl |
||
1001 | add eax,1 |
||
1002 | adc edx,0 |
||
1003 | adc cl,0 |
||
1004 | add eax,edi |
||
1005 | adc edx,0 |
||
1006 | adc cl,0 |
||
1007 | mov [ebx],eax |
||
1008 | mov [ebx+4],edx |
||
1009 | mov [ebx+8],cl |
||
1010 | pop dword [ebx+10h] |
||
1011 | mov [ebx+14h],ebp |
||
1012 | mov al,[value_type] |
||
1013 | test al,1 |
||
1014 | jnz invalid_use_of_symbol |
||
1015 | mov [ebx+9],al |
||
1016 | jmp instruction_assembled |
||
1017 | allocate_structure_data: |
||
1018 | mov ebx,[structures_buffer] |
||
1019 | sub ebx,18h |
||
1020 | cmp ebx,[free_additional_memory] |
||
1021 | jb out_of_memory |
||
1022 | mov [structures_buffer],ebx |
||
1023 | ret |
||
1024 | find_structure_data: |
||
1025 | mov ebx,[structures_buffer] |
||
1026 | scan_structures: |
||
1027 | cmp ebx,[additional_memory_end] |
||
1028 | je no_such_structure |
||
1029 | cmp ax,[ebx] |
||
1030 | je structure_data_found |
||
1031 | add ebx,18h |
||
1032 | jmp scan_structures |
||
1033 | structure_data_found: |
||
1034 | ret |
||
1035 | no_such_structure: |
||
1036 | stc |
||
1037 | ret |
||
1038 | allocate_virtual_structure_data: |
||
1039 | call allocate_structure_data |
||
1040 | mov word [ebx],virtual_directive-instruction_handler |
||
1041 | mov ecx,[addressing_space] |
||
1042 | mov [ebx+12],ecx |
||
1043 | mov [ebx+8],edi |
||
1044 | mov ecx,[current_line] |
||
1045 | mov [ebx+4],ecx |
||
1046 | mov ebx,[addressing_space] |
||
1047 | mov eax,edi |
||
1048 | sub eax,[ebx+18h] |
||
1049 | mov [ebx+1Ch],eax |
||
1050 | ret |
||
1051 | continue_virtual_area: |
||
1052 | cmp byte [esi],11h |
||
1053 | jne invalid_argument |
||
1054 | cmp byte [esi+1+4],')' |
||
1055 | jne invalid_argument |
||
1056 | inc esi |
||
1057 | lods dword [esi] |
||
1058 | inc esi |
||
1059 | cmp eax,0Fh |
||
1060 | jbe reserved_word_used_as_symbol |
||
1061 | mov edx,undefined_symbol |
||
1062 | test byte [eax+8],1 |
||
1063 | jz virtual_area_unavailable |
||
1064 | mov edx,symbol_out_of_scope |
||
1065 | mov cx,[eax+16] |
||
1066 | cmp cx,[current_pass] |
||
1067 | jne virtual_area_unavailable |
||
1068 | mov edx,invalid_use_of_symbol |
||
1069 | test byte [eax+9],4 |
||
1070 | jz virtual_area_unavailable |
||
1071 | mov ebx,eax |
||
1072 | mov ax,[current_pass] |
||
1073 | mov [ebx+18],ax |
||
1074 | or byte [ebx+8],8 |
||
1075 | call store_label_reference |
||
1076 | mov ebx,[ebx] |
||
1077 | test byte [ebx+0Ah],4 |
||
1078 | jz virtual_area_unavailable |
||
1079 | and byte [ebx+0Ah],not 4 |
||
1080 | mov edx,ebx |
||
1081 | call allocate_virtual_structure_data |
||
1082 | mov [addressing_space],edx |
||
1083 | push esi |
||
1084 | mov esi,[edx+18h] |
||
1085 | mov ecx,[edx+1Ch] |
||
1086 | mov eax,[edx+20h] |
||
1087 | sub esi,eax |
||
1088 | add ecx,eax |
||
1089 | lea eax,[edi+ecx] |
||
1090 | cmp eax,[tagged_blocks] |
||
1091 | jae out_of_memory |
||
1092 | mov eax,esi |
||
1093 | sub eax,edi |
||
1094 | sub [edx+18h],eax |
||
1095 | sub [edx],eax |
||
1096 | sbb dword [edx+4],0 |
||
1097 | sbb byte [edx+8],0 |
||
1098 | mov al,cl |
||
1099 | shr ecx,2 |
||
1100 | rep movs dword [edi],[esi] |
||
1101 | mov cl,al |
||
1102 | and cl,11b |
||
1103 | rep movs byte [edi],[esi] |
||
1104 | pop esi |
||
1105 | jmp instruction_assembled |
||
1106 | virtual_area_unavailable: |
||
1107 | cmp [error_line],0 |
||
1108 | jne virtual_fallback |
||
1109 | push [current_line] |
||
1110 | pop [error_line] |
||
1111 | mov [error],edx |
||
1112 | mov [error_info],eax |
||
1113 | jmp virtual_fallback |
||
1114 | end_virtual: |
||
1115 | call find_structure_data |
||
1116 | jc unexpected_instruction |
||
1117 | push ebx |
||
1118 | call close_virtual_addressing_space |
||
1119 | pop ebx |
||
1120 | mov eax,[ebx+12] |
||
1121 | mov [addressing_space],eax |
||
1122 | mov edi,[ebx+8] |
||
1123 | remove_structure_data: |
||
1124 | push esi edi |
||
1125 | mov ecx,ebx |
||
1126 | sub ecx,[structures_buffer] |
||
1127 | shr ecx,2 |
||
1128 | lea esi,[ebx-4] |
||
1129 | lea edi,[esi+18h] |
||
1130 | std |
||
1131 | rep movs dword [edi],[esi] |
||
1132 | cld |
||
1133 | add [structures_buffer],18h |
||
1134 | pop edi esi |
||
1135 | ret |
||
1136 | close_virtual_addressing_space: |
||
1137 | mov ebx,[addressing_space] |
||
1138 | mov eax,edi |
||
1139 | sub eax,[ebx+18h] |
||
1140 | mov [ebx+1Ch],eax |
||
1141 | add eax,[ebx+20h] |
||
1142 | test byte [ebx+0Ah],2 |
||
1143 | jz addressing_space_closed |
||
1144 | or byte [ebx+0Ah],4 |
||
1145 | push esi edi ecx edx |
||
1146 | mov ecx,eax |
||
1147 | mov eax,[tagged_blocks] |
||
1148 | mov dword [eax-4],11h |
||
1149 | mov dword [eax-8],ecx |
||
1150 | sub eax,8 |
||
1151 | sub eax,ecx |
||
1152 | mov [tagged_blocks],eax |
||
1153 | lea edi,[eax+ecx-1] |
||
1154 | add eax,[ebx+20h] |
||
1155 | xchg eax,[ebx+18h] |
||
1156 | sub eax,[ebx+20h] |
||
1157 | lea esi,[eax+ecx-1] |
||
1158 | mov eax,edi |
||
1159 | sub eax,esi |
||
1160 | std |
||
1161 | shr ecx,1 |
||
1162 | jnc virtual_byte_ok |
||
1163 | movs byte [edi],[esi] |
||
1164 | virtual_byte_ok: |
||
1165 | dec esi |
||
1166 | dec edi |
||
1167 | shr ecx,1 |
||
1168 | jnc virtual_word_ok |
||
1169 | movs word [edi],[esi] |
||
1170 | virtual_word_ok: |
||
1171 | sub esi,2 |
||
1172 | sub edi,2 |
||
1173 | rep movs dword [edi],[esi] |
||
1174 | cld |
||
1175 | xor edx,edx |
||
1176 | add [ebx],eax |
||
1177 | adc dword [ebx+4],edx |
||
1178 | adc byte [ebx+8],dl |
||
1179 | pop edx ecx edi esi |
||
1180 | addressing_space_closed: |
||
1181 | ret |
||
1182 | repeat_directive: |
||
1183 | test [prefix_flags],1 |
||
1184 | jnz unexpected_instruction |
||
1185 | lods byte [esi] |
||
1186 | cmp al,'(' |
||
1187 | jne invalid_argument |
||
1188 | cmp byte [esi],'.' |
||
1189 | je invalid_value |
||
1190 | call get_count_value |
||
1191 | cmp eax,0 |
||
1192 | je zero_repeat |
||
1193 | call allocate_structure_data |
||
1194 | mov word [ebx],repeat_directive-instruction_handler |
||
1195 | xchg eax,[counter_limit] |
||
1196 | mov [ebx+10h],eax |
||
1197 | mov eax,1 |
||
1198 | xchg eax,[counter] |
||
1199 | mov [ebx+14h],eax |
||
1200 | mov [ebx+8],esi |
||
1201 | mov eax,[current_line] |
||
1202 | mov [ebx+4],eax |
||
1203 | jmp instruction_assembled |
||
1204 | end_repeat: |
||
1205 | test [prefix_flags],1 |
||
1206 | jnz unexpected_instruction |
||
1207 | call find_structure_data |
||
1208 | jc unexpected_instruction |
||
1209 | mov eax,[counter_limit] |
||
1210 | inc [counter] |
||
1211 | cmp [counter],eax |
||
1212 | jbe continue_repeating |
||
1213 | stop_repeat: |
||
1214 | mov eax,[ebx+10h] |
||
1215 | mov [counter_limit],eax |
||
1216 | mov eax,[ebx+14h] |
||
1217 | mov [counter],eax |
||
1218 | call remove_structure_data |
||
1219 | jmp instruction_assembled |
||
1220 | continue_repeating: |
||
1221 | mov esi,[ebx+8] |
||
1222 | jmp instruction_assembled |
||
1223 | zero_repeat: |
||
1224 | mov al,[esi] |
||
1225 | or al,al |
||
1226 | jz missing_end_directive |
||
1227 | cmp al,0Fh |
||
1228 | jne extra_characters_on_line |
||
1229 | call find_end_repeat |
||
1230 | jmp instruction_assembled |
||
1231 | find_end_repeat: |
||
1232 | call find_structure_end |
||
1233 | cmp ax,repeat_directive-instruction_handler |
||
1234 | jne unexpected_instruction |
||
1235 | ret |
||
1236 | while_directive: |
||
1237 | test [prefix_flags],1 |
||
1238 | jnz unexpected_instruction |
||
1239 | call allocate_structure_data |
||
1240 | mov word [ebx],while_directive-instruction_handler |
||
1241 | mov eax,1 |
||
1242 | xchg eax,[counter] |
||
1243 | mov [ebx+10h],eax |
||
1244 | mov [ebx+8],esi |
||
1245 | mov eax,[current_line] |
||
1246 | mov [ebx+4],eax |
||
1247 | do_while: |
||
1248 | push ebx |
||
1249 | call calculate_logical_expression |
||
1250 | or al,al |
||
1251 | jnz while_true |
||
1252 | mov al,[esi] |
||
1253 | or al,al |
||
1254 | jz missing_end_directive |
||
1255 | cmp al,0Fh |
||
1256 | jne extra_characters_on_line |
||
1257 | stop_while: |
||
1258 | call find_end_while |
||
1259 | pop ebx |
||
1260 | mov eax,[ebx+10h] |
||
1261 | mov [counter],eax |
||
1262 | call remove_structure_data |
||
1263 | jmp instruction_assembled |
||
1264 | while_true: |
||
1265 | pop ebx |
||
1266 | jmp instruction_assembled |
||
1267 | end_while: |
||
1268 | test [prefix_flags],1 |
||
1269 | jnz unexpected_instruction |
||
1270 | call find_structure_data |
||
1271 | jc unexpected_instruction |
||
1272 | mov eax,[ebx+4] |
||
1273 | mov [current_line],eax |
||
1274 | inc [counter] |
||
1275 | jz too_many_repeats |
||
1276 | mov esi,[ebx+8] |
||
1277 | jmp do_while |
||
1278 | find_end_while: |
||
1279 | call find_structure_end |
||
1280 | cmp ax,while_directive-instruction_handler |
||
1281 | jne unexpected_instruction |
||
1282 | ret |
||
1283 | if_directive: |
||
1284 | test [prefix_flags],1 |
||
1285 | jnz unexpected_instruction |
||
1286 | call calculate_logical_expression |
||
1287 | mov dl,al |
||
1288 | mov al,[esi] |
||
1289 | or al,al |
||
1290 | jz missing_end_directive |
||
1291 | cmp al,0Fh |
||
1292 | jne extra_characters_on_line |
||
1293 | or dl,dl |
||
1294 | jnz if_true |
||
1295 | call find_else |
||
1296 | jc instruction_assembled |
||
1297 | mov al,[esi] |
||
1298 | cmp al,1 |
||
1299 | jne else_true |
||
1300 | cmp word [esi+1],if_directive-instruction_handler |
||
1301 | jne else_true |
||
1302 | add esi,4 |
||
1303 | jmp if_directive |
||
1304 | if_true: |
||
1305 | xor al,al |
||
1306 | make_if_structure: |
||
1307 | call allocate_structure_data |
||
1308 | mov word [ebx],if_directive-instruction_handler |
||
1309 | mov byte [ebx+2],al |
||
1310 | mov eax,[current_line] |
||
1311 | mov [ebx+4],eax |
||
1312 | jmp instruction_assembled |
||
1313 | else_true: |
||
1314 | or al,al |
||
1315 | jz missing_end_directive |
||
1316 | cmp al,0Fh |
||
1317 | jne extra_characters_on_line |
||
1318 | or al,-1 |
||
1319 | jmp make_if_structure |
||
1320 | else_directive: |
||
1321 | test [prefix_flags],1 |
||
1322 | jnz unexpected_instruction |
||
1323 | mov ax,if_directive-instruction_handler |
||
1324 | call find_structure_data |
||
1325 | jc unexpected_instruction |
||
1326 | cmp byte [ebx+2],0 |
||
1327 | jne unexpected_instruction |
||
1328 | found_else: |
||
1329 | mov al,[esi] |
||
1330 | cmp al,1 |
||
1331 | jne skip_else |
||
1332 | cmp word [esi+1],if_directive-instruction_handler |
||
1333 | jne skip_else |
||
1334 | add esi,4 |
||
1335 | call find_else |
||
1336 | jnc found_else |
||
1337 | call remove_structure_data |
||
1338 | jmp instruction_assembled |
||
1339 | skip_else: |
||
1340 | or al,al |
||
1341 | jz missing_end_directive |
||
1342 | cmp al,0Fh |
||
1343 | jne extra_characters_on_line |
||
1344 | call find_end_if |
||
1345 | call remove_structure_data |
||
1346 | jmp instruction_assembled |
||
1347 | end_if: |
||
1348 | test [prefix_flags],1 |
||
1349 | jnz unexpected_instruction |
||
1350 | call find_structure_data |
||
1351 | jc unexpected_instruction |
||
1352 | call remove_structure_data |
||
1353 | jmp instruction_assembled |
||
1354 | find_else: |
||
1355 | call find_structure_end |
||
1356 | cmp ax,else_directive-instruction_handler |
||
1357 | je else_found |
||
1358 | cmp ax,if_directive-instruction_handler |
||
1359 | jne unexpected_instruction |
||
1360 | stc |
||
1361 | ret |
||
1362 | else_found: |
||
1363 | clc |
||
1364 | ret |
||
1365 | find_end_if: |
||
1366 | call find_structure_end |
||
1367 | cmp ax,if_directive-instruction_handler |
||
1368 | jne unexpected_instruction |
||
1369 | ret |
||
1370 | find_structure_end: |
||
1371 | push [error_line] |
||
1372 | mov eax,[current_line] |
||
1373 | mov [error_line],eax |
||
1374 | find_end_directive: |
||
1375 | call skip_symbol |
||
1376 | jnc find_end_directive |
||
1377 | lods byte [esi] |
||
1378 | cmp al,0Fh |
||
1379 | jne no_end_directive |
||
1380 | lods dword [esi] |
||
1381 | mov [current_line],eax |
||
1382 | skip_labels: |
||
1383 | cmp byte [esi],2 |
||
1384 | jne labels_ok |
||
1385 | add esi,6 |
||
1386 | jmp skip_labels |
||
1387 | labels_ok: |
||
1388 | cmp byte [esi],1 |
||
1389 | jne find_end_directive |
||
1390 | mov ax,[esi+1] |
||
1391 | cmp ax,prefix_instruction-instruction_handler |
||
1392 | je find_end_directive |
||
1393 | add esi,4 |
||
1394 | cmp ax,repeat_directive-instruction_handler |
||
1395 | je skip_repeat |
||
1396 | cmp ax,while_directive-instruction_handler |
||
1397 | je skip_while |
||
1398 | cmp ax,if_directive-instruction_handler |
||
1399 | je skip_if |
||
1400 | cmp ax,else_directive-instruction_handler |
||
1401 | je structure_end |
||
1402 | cmp ax,end_directive-instruction_handler |
||
1403 | jne find_end_directive |
||
1404 | cmp byte [esi],1 |
||
1405 | jne find_end_directive |
||
1406 | mov ax,[esi+1] |
||
1407 | add esi,4 |
||
1408 | cmp ax,repeat_directive-instruction_handler |
||
1409 | je structure_end |
||
1410 | cmp ax,while_directive-instruction_handler |
||
1411 | je structure_end |
||
1412 | cmp ax,if_directive-instruction_handler |
||
1413 | jne find_end_directive |
||
1414 | structure_end: |
||
1415 | pop [error_line] |
||
1416 | ret |
||
1417 | no_end_directive: |
||
1418 | mov eax,[error_line] |
||
1419 | mov [current_line],eax |
||
1420 | jmp missing_end_directive |
||
1421 | skip_repeat: |
||
1422 | call find_end_repeat |
||
1423 | jmp find_end_directive |
||
1424 | skip_while: |
||
1425 | call find_end_while |
||
1426 | jmp find_end_directive |
||
1427 | skip_if: |
||
1428 | call skip_if_block |
||
1429 | jmp find_end_directive |
||
1430 | skip_if_block: |
||
1431 | call find_else |
||
1432 | jc if_block_skipped |
||
1433 | cmp byte [esi],1 |
||
1434 | jne skip_after_else |
||
1435 | cmp word [esi+1],if_directive-instruction_handler |
||
1436 | jne skip_after_else |
||
1437 | add esi,4 |
||
1438 | jmp skip_if_block |
||
1439 | skip_after_else: |
||
1440 | call find_end_if |
||
1441 | if_block_skipped: |
||
1442 | ret |
||
1443 | end_directive: |
||
1444 | lods byte [esi] |
||
1445 | cmp al,1 |
||
1446 | jne invalid_argument |
||
1447 | lods word [esi] |
||
1448 | inc esi |
||
1449 | cmp ax,virtual_directive-instruction_handler |
||
1450 | je end_virtual |
||
1451 | cmp ax,repeat_directive-instruction_handler |
||
1452 | je end_repeat |
||
1453 | cmp ax,while_directive-instruction_handler |
||
1454 | je end_while |
||
1455 | cmp ax,if_directive-instruction_handler |
||
1456 | je end_if |
||
1457 | cmp ax,data_directive-instruction_handler |
||
1458 | je end_data |
||
1459 | jmp invalid_argument |
||
1460 | break_directive: |
||
1461 | mov ebx,[structures_buffer] |
||
1462 | mov al,[esi] |
||
1463 | or al,al |
||
1464 | jz find_breakable_structure |
||
1465 | cmp al,0Fh |
||
1466 | jne extra_characters_on_line |
||
1467 | find_breakable_structure: |
||
1468 | cmp ebx,[additional_memory_end] |
||
1469 | je unexpected_instruction |
||
1470 | mov ax,[ebx] |
||
1471 | cmp ax,repeat_directive-instruction_handler |
||
1472 | je break_repeat |
||
1473 | cmp ax,while_directive-instruction_handler |
||
1474 | je break_while |
||
1475 | cmp ax,if_directive-instruction_handler |
||
1476 | je break_if |
||
1477 | add ebx,18h |
||
1478 | jmp find_breakable_structure |
||
1479 | break_if: |
||
1480 | push [current_line] |
||
1481 | mov eax,[ebx+4] |
||
1482 | mov [current_line],eax |
||
1483 | call remove_structure_data |
||
1484 | call skip_if_block |
||
1485 | pop [current_line] |
||
1486 | mov ebx,[structures_buffer] |
||
1487 | jmp find_breakable_structure |
||
1488 | break_repeat: |
||
1489 | push ebx |
||
1490 | call find_end_repeat |
||
1491 | pop ebx |
||
1492 | jmp stop_repeat |
||
1493 | break_while: |
||
1494 | push ebx |
||
1495 | jmp stop_while |
||
1496 | |||
1497 | |||
1498 | cmp edi,[tagged_blocks] |
||
1499 | jae out_of_memory |
||
1500 | cmp byte [esi],'(' |
||
1501 | jne simple_data_value |
||
1502 | mov ebx,esi |
||
1503 | inc esi |
||
1504 | call skip_expression |
||
1505 | xchg esi,ebx |
||
1506 | cmp byte [ebx],81h |
||
1507 | jne simple_data_value |
||
1508 | inc esi |
||
1509 | call get_count_value |
||
1510 | inc esi |
||
1511 | or eax,eax |
||
1512 | jz duplicate_zero_times |
||
1513 | cmp byte [esi],91h |
||
1514 | jne duplicate_single_data_value |
||
1515 | inc esi |
||
1516 | duplicate_data: |
||
1517 | push eax esi |
||
1518 | duplicated_values: |
||
1519 | cmp edi,[tagged_blocks] |
||
1520 | jae out_of_memory |
||
1521 | clc |
||
1522 | call near dword [esp+8] |
||
1523 | lods byte [esi] |
||
1524 | cmp al,',' |
||
1525 | je duplicated_values |
||
1526 | cmp al,92h |
||
1527 | jne invalid_argument |
||
1528 | pop ebx eax |
||
1529 | dec eax |
||
1530 | jz data_defined |
||
1531 | mov esi,ebx |
||
1532 | jmp duplicate_data |
||
1533 | duplicate_single_data_value: |
||
1534 | cmp edi,[tagged_blocks] |
||
1535 | jae out_of_memory |
||
1536 | push eax esi |
||
1537 | clc |
||
1538 | call near dword [esp+8] |
||
1539 | pop ebx eax |
||
1540 | dec eax |
||
1541 | jz data_defined |
||
1542 | mov esi,ebx |
||
1543 | jmp duplicate_single_data_value |
||
1544 | duplicate_zero_times: |
||
1545 | cmp byte [esi],91h |
||
1546 | jne skip_single_data_value |
||
1547 | inc esi |
||
1548 | skip_data_value: |
||
1549 | call skip_symbol |
||
1550 | jc invalid_argument |
||
1551 | cmp byte [esi],92h |
||
1552 | jne skip_data_value |
||
1553 | inc esi |
||
1554 | jmp data_defined |
||
1555 | skip_single_data_value: |
||
1556 | call skip_symbol |
||
1557 | jmp data_defined |
||
1558 | simple_data_value: |
||
1559 | cmp edi,[tagged_blocks] |
||
1560 | jae out_of_memory |
||
1561 | clc |
||
1562 | call near dword [esp] |
||
1563 | data_defined: |
||
1564 | lods byte [esi] |
||
1565 | cmp al,',' |
||
1566 | je define_data |
||
1567 | dec esi |
||
1568 | stc |
||
1569 | ret |
||
1570 | data_bytes: |
||
1571 | call define_data |
||
1572 | jc instruction_assembled |
||
1573 | lods byte [esi] |
||
1574 | cmp al,'(' |
||
1575 | je get_byte |
||
1576 | cmp al,'?' |
||
1577 | jne invalid_argument |
||
1578 | mov eax,edi |
||
1579 | mov byte [edi],0 |
||
1580 | inc edi |
||
1581 | jmp undefined_data |
||
1582 | get_byte: |
||
1583 | cmp byte [esi],0 |
||
1584 | je get_string |
||
1585 | call get_byte_value |
||
1586 | stos byte [edi] |
||
1587 | ret |
||
1588 | get_string: |
||
1589 | inc esi |
||
1590 | lods dword [esi] |
||
1591 | mov ecx,eax |
||
1592 | lea eax,[edi+ecx] |
||
1593 | cmp eax,[tagged_blocks] |
||
1594 | ja out_of_memory |
||
1595 | rep movs byte [edi],[esi] |
||
1596 | inc esi |
||
1597 | ret |
||
1598 | undefined_data: |
||
1599 | mov ebp,[addressing_space] |
||
1600 | test byte [ds:ebp+0Ah],1 |
||
1601 | jz mark_undefined_data |
||
1602 | ret |
||
1603 | mark_undefined_data: |
||
1604 | cmp eax,[undefined_data_end] |
||
1605 | je undefined_data_ok |
||
1606 | mov [undefined_data_start],eax |
||
1607 | undefined_data_ok: |
||
1608 | mov [undefined_data_end],edi |
||
1609 | ret |
||
1610 | data_unicode: |
||
1611 | or [base_code],-1 |
||
1612 | jmp define_words |
||
1613 | data_words: |
||
1614 | mov [base_code],0 |
||
1615 | define_words: |
||
1616 | call define_data |
||
1617 | jc instruction_assembled |
||
1618 | lods byte [esi] |
||
1619 | cmp al,'(' |
||
1620 | je get_word |
||
1621 | cmp al,'?' |
||
1622 | jne invalid_argument |
||
1623 | mov eax,edi |
||
1624 | and word [edi],0 |
||
1625 | scas word [edi] |
||
1626 | jmp undefined_data |
||
1627 | ret |
||
1628 | get_word: |
||
1629 | cmp [base_code],0 |
||
1630 | je word_data_value |
||
1631 | cmp byte [esi],0 |
||
1632 | je word_string |
||
1633 | word_data_value: |
||
1634 | call get_word_value |
||
1635 | call mark_relocation |
||
1636 | stos word [edi] |
||
1637 | ret |
||
1638 | word_string: |
||
1639 | inc esi |
||
1640 | lods dword [esi] |
||
1641 | mov ecx,eax |
||
1642 | jecxz word_string_ok |
||
1643 | lea eax,[edi+ecx*2] |
||
1644 | cmp eax,[tagged_blocks] |
||
1645 | ja out_of_memory |
||
1646 | xor ah,ah |
||
1647 | copy_word_string: |
||
1648 | lods byte [esi] |
||
1649 | stos word [edi] |
||
1650 | loop copy_word_string |
||
1651 | word_string_ok: |
||
1652 | inc esi |
||
1653 | ret |
||
1654 | data_dwords: |
||
1655 | call define_data |
||
1656 | jc instruction_assembled |
||
1657 | lods byte [esi] |
||
1658 | cmp al,'(' |
||
1659 | je get_dword |
||
1660 | cmp al,'?' |
||
1661 | jne invalid_argument |
||
1662 | mov eax,edi |
||
1663 | and dword [edi],0 |
||
1664 | scas dword [edi] |
||
1665 | jmp undefined_data |
||
1666 | get_dword: |
||
1667 | push esi |
||
1668 | call get_dword_value |
||
1669 | pop ebx |
||
1670 | cmp byte [esi],':' |
||
1671 | je complex_dword |
||
1672 | call mark_relocation |
||
1673 | stos dword [edi] |
||
1674 | ret |
||
1675 | complex_dword: |
||
1676 | mov esi,ebx |
||
1677 | cmp byte [esi],'.' |
||
1678 | je invalid_value |
||
1679 | call get_word_value |
||
1680 | push eax |
||
1681 | inc esi |
||
1682 | lods byte [esi] |
||
1683 | cmp al,'(' |
||
1684 | jne invalid_operand |
||
1685 | mov al,[value_type] |
||
1686 | push eax |
||
1687 | cmp byte [esi],'.' |
||
1688 | je invalid_value |
||
1689 | call get_word_value |
||
1690 | call mark_relocation |
||
1691 | stos word [edi] |
||
1692 | pop eax |
||
1693 | mov [value_type],al |
||
1694 | pop eax |
||
1695 | call mark_relocation |
||
1696 | stos word [edi] |
||
1697 | ret |
||
1698 | data_pwords: |
||
1699 | call define_data |
||
1700 | jc instruction_assembled |
||
1701 | lods byte [esi] |
||
1702 | cmp al,'(' |
||
1703 | je get_pword |
||
1704 | cmp al,'?' |
||
1705 | jne invalid_argument |
||
1706 | mov eax,edi |
||
1707 | and dword [edi],0 |
||
1708 | scas dword [edi] |
||
1709 | and word [edi],0 |
||
1710 | scas word [edi] |
||
1711 | jmp undefined_data |
||
1712 | get_pword: |
||
1713 | push esi |
||
1714 | call get_pword_value |
||
1715 | pop ebx |
||
1716 | cmp byte [esi],':' |
||
1717 | je complex_pword |
||
1718 | call mark_relocation |
||
1719 | stos dword [edi] |
||
1720 | mov ax,dx |
||
1721 | stos word [edi] |
||
1722 | ret |
||
1723 | complex_pword: |
||
1724 | mov esi,ebx |
||
1725 | cmp byte [esi],'.' |
||
1726 | je invalid_value |
||
1727 | call get_word_value |
||
1728 | push eax |
||
1729 | inc esi |
||
1730 | lods byte [esi] |
||
1731 | cmp al,'(' |
||
1732 | jne invalid_operand |
||
1733 | mov al,[value_type] |
||
1734 | push eax |
||
1735 | cmp byte [esi],'.' |
||
1736 | je invalid_value |
||
1737 | call get_dword_value |
||
1738 | call mark_relocation |
||
1739 | stos dword [edi] |
||
1740 | pop eax |
||
1741 | mov [value_type],al |
||
1742 | pop eax |
||
1743 | call mark_relocation |
||
1744 | stos word [edi] |
||
1745 | ret |
||
1746 | data_qwords: |
||
1747 | call define_data |
||
1748 | jc instruction_assembled |
||
1749 | lods byte [esi] |
||
1750 | cmp al,'(' |
||
1751 | je get_qword |
||
1752 | cmp al,'?' |
||
1753 | jne invalid_argument |
||
1754 | mov eax,edi |
||
1755 | and dword [edi],0 |
||
1756 | scas dword [edi] |
||
1757 | and dword [edi],0 |
||
1758 | scas dword [edi] |
||
1759 | jmp undefined_data |
||
1760 | get_qword: |
||
1761 | call get_qword_value |
||
1762 | call mark_relocation |
||
1763 | stos dword [edi] |
||
1764 | mov eax,edx |
||
1765 | stos dword [edi] |
||
1766 | ret |
||
1767 | data_twords: |
||
1768 | call define_data |
||
1769 | jc instruction_assembled |
||
1770 | lods byte [esi] |
||
1771 | cmp al,'(' |
||
1772 | je get_tword |
||
1773 | cmp al,'?' |
||
1774 | jne invalid_argument |
||
1775 | mov eax,edi |
||
1776 | and dword [edi],0 |
||
1777 | scas dword [edi] |
||
1778 | and dword [edi],0 |
||
1779 | scas dword [edi] |
||
1780 | and word [edi],0 |
||
1781 | scas word [edi] |
||
1782 | jmp undefined_data |
||
1783 | get_tword: |
||
1784 | cmp byte [esi],'.' |
||
1785 | jne complex_tword |
||
1786 | inc esi |
||
1787 | cmp word [esi+8],8000h |
||
1788 | je fp_zero_tword |
||
1789 | mov eax,[esi] |
||
1790 | stos dword [edi] |
||
1791 | mov eax,[esi+4] |
||
1792 | stos dword [edi] |
||
1793 | mov ax,[esi+8] |
||
1794 | add ax,3FFFh |
||
1795 | jo value_out_of_range |
||
1796 | cmp ax,7FFFh |
||
1797 | jge value_out_of_range |
||
1798 | cmp ax,0 |
||
1799 | jg tword_exp_ok |
||
1800 | mov cx,ax |
||
1801 | neg cx |
||
1802 | inc cx |
||
1803 | cmp cx,64 |
||
1804 | jae value_out_of_range |
||
1805 | cmp cx,32 |
||
1806 | ja large_shift |
||
1807 | mov eax,[esi] |
||
1808 | mov edx,[esi+4] |
||
1809 | mov ebx,edx |
||
1810 | shr edx,cl |
||
1811 | shrd eax,ebx,cl |
||
1812 | jmp tword_mantissa_shift_done |
||
1813 | large_shift: |
||
1814 | sub cx,32 |
||
1815 | xor edx,edx |
||
1816 | mov eax,[esi+4] |
||
1817 | shr eax,cl |
||
1818 | tword_mantissa_shift_done: |
||
1819 | jnc store_shifted_mantissa |
||
1820 | add eax,1 |
||
1821 | adc edx,0 |
||
1822 | store_shifted_mantissa: |
||
1823 | mov [edi-8],eax |
||
1824 | mov [edi-4],edx |
||
1825 | xor ax,ax |
||
1826 | test edx,1 shl 31 |
||
1827 | jz tword_exp_ok |
||
1828 | inc ax |
||
1829 | tword_exp_ok: |
||
1830 | mov bl,[esi+11] |
||
1831 | shl bx,15 |
||
1832 | or ax,bx |
||
1833 | stos word [edi] |
||
1834 | add esi,13 |
||
1835 | ret |
||
1836 | fp_zero_tword: |
||
1837 | xor eax,eax |
||
1838 | stos dword [edi] |
||
1839 | stos dword [edi] |
||
1840 | mov al,[esi+11] |
||
1841 | shl ax,15 |
||
1842 | stos word [edi] |
||
1843 | add esi,13 |
||
1844 | ret |
||
1845 | complex_tword: |
||
1846 | call get_word_value |
||
1847 | push eax |
||
1848 | cmp byte [esi],':' |
||
1849 | jne invalid_operand |
||
1850 | inc esi |
||
1851 | lods byte [esi] |
||
1852 | cmp al,'(' |
||
1853 | jne invalid_operand |
||
1854 | mov al,[value_type] |
||
1855 | push eax |
||
1856 | cmp byte [esi],'.' |
||
1857 | je invalid_value |
||
1858 | call get_qword_value |
||
1859 | call mark_relocation |
||
1860 | stos dword [edi] |
||
1861 | mov eax,edx |
||
1862 | stos dword [edi] |
||
1863 | pop eax |
||
1864 | mov [value_type],al |
||
1865 | pop eax |
||
1866 | call mark_relocation |
||
1867 | stos word [edi] |
||
1868 | ret |
||
1869 | data_file: |
||
1870 | lods word [esi] |
||
1871 | cmp ax,'(' |
||
1872 | jne invalid_argument |
||
1873 | add esi,4 |
||
1874 | call open_binary_file |
||
1875 | mov eax,[esi-4] |
||
1876 | lea esi,[esi+eax+1] |
||
1877 | mov al,2 |
||
1878 | xor edx,edx |
||
1879 | call lseek |
||
1880 | push eax |
||
1881 | xor edx,edx |
||
1882 | cmp byte [esi],':' |
||
1883 | jne position_ok |
||
1884 | inc esi |
||
1885 | cmp byte [esi],'(' |
||
1886 | jne invalid_argument |
||
1887 | inc esi |
||
1888 | cmp byte [esi],'.' |
||
1889 | je invalid_value |
||
1890 | push ebx |
||
1891 | call get_count_value |
||
1892 | pop ebx |
||
1893 | mov edx,eax |
||
1894 | sub [esp],edx |
||
1895 | jc value_out_of_range |
||
1896 | position_ok: |
||
1897 | cmp byte [esi],',' |
||
1898 | jne size_ok |
||
1899 | inc esi |
||
1900 | cmp byte [esi],'(' |
||
1901 | jne invalid_argument |
||
1902 | inc esi |
||
1903 | cmp byte [esi],'.' |
||
1904 | je invalid_value |
||
1905 | push ebx edx |
||
1906 | call get_count_value |
||
1907 | pop edx ebx |
||
1908 | cmp eax,[esp] |
||
1909 | ja value_out_of_range |
||
1910 | mov [esp],eax |
||
1911 | size_ok: |
||
1912 | xor al,al |
||
1913 | call lseek |
||
1914 | pop ecx |
||
1915 | mov edx,edi |
||
1916 | add edi,ecx |
||
1917 | jc out_of_memory |
||
1918 | cmp edi,[tagged_blocks] |
||
1919 | ja out_of_memory |
||
1920 | call read |
||
1921 | jc error_reading_file |
||
1922 | call close |
||
1923 | lods byte [esi] |
||
1924 | cmp al,',' |
||
1925 | je data_file |
||
1926 | dec esi |
||
1927 | jmp instruction_assembled |
||
1928 | open_binary_file: |
||
1929 | push esi |
||
1930 | push edi |
||
1931 | mov eax,[current_line] |
||
1932 | find_current_source_path: |
||
1933 | mov esi,[eax] |
||
1934 | test byte [eax+7],80h |
||
1935 | jz get_current_path |
||
1936 | mov eax,[eax+8] |
||
1937 | jmp find_current_source_path |
||
1938 | get_current_path: |
||
1939 | lodsb |
||
1940 | stosb |
||
1941 | or al,al |
||
1942 | jnz get_current_path |
||
1943 | cut_current_path: |
||
1944 | cmp edi,[esp] |
||
1945 | je current_path_ok |
||
1946 | cmp byte [edi-1],'\' |
||
1947 | je current_path_ok |
||
1948 | cmp byte [edi-1],'/' |
||
1949 | je current_path_ok |
||
1950 | dec edi |
||
1951 | jmp cut_current_path |
||
1952 | current_path_ok: |
||
1953 | mov esi,[esp+4] |
||
1954 | call expand_path |
||
1955 | pop edx |
||
1956 | mov esi,edx |
||
1957 | call open |
||
1958 | jnc file_opened |
||
1959 | mov edx,[include_paths] |
||
1960 | search_in_include_paths: |
||
1961 | push edx esi |
||
1962 | mov edi,esi |
||
1963 | mov esi,[esp+4] |
||
1964 | call get_include_directory |
||
1965 | mov [esp+4],esi |
||
1966 | mov esi,[esp+8] |
||
1967 | call expand_path |
||
1968 | pop edx |
||
1969 | mov esi,edx |
||
1970 | call open |
||
1971 | pop edx |
||
1972 | jnc file_opened |
||
1973 | cmp byte [edx],0 |
||
1974 | jne search_in_include_paths |
||
1975 | mov edi,esi |
||
1976 | mov esi,[esp] |
||
1977 | push edi |
||
1978 | call expand_path |
||
1979 | pop edx |
||
1980 | mov esi,edx |
||
1981 | call open |
||
1982 | jc file_not_found |
||
1983 | file_opened: |
||
1984 | mov edi,esi |
||
1985 | pop esi |
||
1986 | ret |
||
1987 | reserve_bytes: |
||
1988 | lods byte [esi] |
||
1989 | cmp al,'(' |
||
1990 | jne invalid_argument |
||
1991 | cmp byte [esi],'.' |
||
1992 | je invalid_value |
||
1993 | call get_count_value |
||
1994 | mov ecx,eax |
||
1995 | mov edx,ecx |
||
1996 | add edx,edi |
||
1997 | jc out_of_memory |
||
1998 | cmp edx,[tagged_blocks] |
||
1999 | ja out_of_memory |
||
2000 | push edi |
||
2001 | cmp [next_pass_needed],0 |
||
2002 | je zero_bytes |
||
2003 | add edi,ecx |
||
2004 | jmp reserved_data |
||
2005 | zero_bytes: |
||
2006 | xor eax,eax |
||
2007 | shr ecx,1 |
||
2008 | jnc bytes_stosb_ok |
||
2009 | stos byte [edi] |
||
2010 | bytes_stosb_ok: |
||
2011 | shr ecx,1 |
||
2012 | jnc bytes_stosw_ok |
||
2013 | stos word [edi] |
||
2014 | bytes_stosw_ok: |
||
2015 | rep stos dword [edi] |
||
2016 | reserved_data: |
||
2017 | pop eax |
||
2018 | call undefined_data |
||
2019 | jmp instruction_assembled |
||
2020 | reserve_words: |
||
2021 | lods byte [esi] |
||
2022 | cmp al,'(' |
||
2023 | jne invalid_argument |
||
2024 | cmp byte [esi],'.' |
||
2025 | je invalid_value |
||
2026 | call get_count_value |
||
2027 | mov ecx,eax |
||
2028 | mov edx,ecx |
||
2029 | shl edx,1 |
||
2030 | jc out_of_memory |
||
2031 | add edx,edi |
||
2032 | jc out_of_memory |
||
2033 | cmp edx,[tagged_blocks] |
||
2034 | ja out_of_memory |
||
2035 | push edi |
||
2036 | cmp [next_pass_needed],0 |
||
2037 | je zero_words |
||
2038 | lea edi,[edi+ecx*2] |
||
2039 | jmp reserved_data |
||
2040 | zero_words: |
||
2041 | xor eax,eax |
||
2042 | shr ecx,1 |
||
2043 | jnc words_stosw_ok |
||
2044 | stos word [edi] |
||
2045 | words_stosw_ok: |
||
2046 | rep stos dword [edi] |
||
2047 | jmp reserved_data |
||
2048 | reserve_dwords: |
||
2049 | lods byte [esi] |
||
2050 | cmp al,'(' |
||
2051 | jne invalid_argument |
||
2052 | cmp byte [esi],'.' |
||
2053 | je invalid_value |
||
2054 | call get_count_value |
||
2055 | mov ecx,eax |
||
2056 | mov edx,ecx |
||
2057 | shl edx,1 |
||
2058 | jc out_of_memory |
||
2059 | shl edx,1 |
||
2060 | jc out_of_memory |
||
2061 | add edx,edi |
||
2062 | jc out_of_memory |
||
2063 | cmp edx,[tagged_blocks] |
||
2064 | ja out_of_memory |
||
2065 | push edi |
||
2066 | cmp [next_pass_needed],0 |
||
2067 | je zero_dwords |
||
2068 | lea edi,[edi+ecx*4] |
||
2069 | jmp reserved_data |
||
2070 | zero_dwords: |
||
2071 | xor eax,eax |
||
2072 | rep stos dword [edi] |
||
2073 | jmp reserved_data |
||
2074 | reserve_pwords: |
||
2075 | lods byte [esi] |
||
2076 | cmp al,'(' |
||
2077 | jne invalid_argument |
||
2078 | cmp byte [esi],'.' |
||
2079 | je invalid_value |
||
2080 | call get_count_value |
||
2081 | mov ecx,eax |
||
2082 | shl ecx,1 |
||
2083 | jc out_of_memory |
||
2084 | add ecx,eax |
||
2085 | mov edx,ecx |
||
2086 | shl edx,1 |
||
2087 | jc out_of_memory |
||
2088 | add edx,edi |
||
2089 | jc out_of_memory |
||
2090 | cmp edx,[tagged_blocks] |
||
2091 | ja out_of_memory |
||
2092 | push edi |
||
2093 | cmp [next_pass_needed],0 |
||
2094 | je zero_words |
||
2095 | lea edi,[edi+ecx*2] |
||
2096 | jmp reserved_data |
||
2097 | reserve_qwords: |
||
2098 | lods byte [esi] |
||
2099 | cmp al,'(' |
||
2100 | jne invalid_argument |
||
2101 | cmp byte [esi],'.' |
||
2102 | je invalid_value |
||
2103 | call get_count_value |
||
2104 | mov ecx,eax |
||
2105 | shl ecx,1 |
||
2106 | jc out_of_memory |
||
2107 | mov edx,ecx |
||
2108 | shl edx,1 |
||
2109 | jc out_of_memory |
||
2110 | shl edx,1 |
||
2111 | jc out_of_memory |
||
2112 | add edx,edi |
||
2113 | jc out_of_memory |
||
2114 | cmp edx,[tagged_blocks] |
||
2115 | ja out_of_memory |
||
2116 | push edi |
||
2117 | cmp [next_pass_needed],0 |
||
2118 | je zero_dwords |
||
2119 | lea edi,[edi+ecx*4] |
||
2120 | jmp reserved_data |
||
2121 | reserve_twords: |
||
2122 | lods byte [esi] |
||
2123 | cmp al,'(' |
||
2124 | jne invalid_argument |
||
2125 | cmp byte [esi],'.' |
||
2126 | je invalid_value |
||
2127 | call get_count_value |
||
2128 | mov ecx,eax |
||
2129 | shl ecx,2 |
||
2130 | jc out_of_memory |
||
2131 | add ecx,eax |
||
2132 | mov edx,ecx |
||
2133 | shl edx,1 |
||
2134 | jc out_of_memory |
||
2135 | add edx,edi |
||
2136 | jc out_of_memory |
||
2137 | cmp edx,[tagged_blocks] |
||
2138 | ja out_of_memory |
||
2139 | push edi |
||
2140 | cmp [next_pass_needed],0 |
||
2141 | je zero_words |
||
2142 | lea edi,[edi+ecx*2] |
||
2143 | jmp reserved_data |
||
2144 | align_directive: |
||
2145 | lods byte [esi] |
||
2146 | cmp al,'(' |
||
2147 | jne invalid_argument |
||
2148 | cmp byte [esi],'.' |
||
2149 | je invalid_value |
||
2150 | call get_count_value |
||
2151 | mov edx,eax |
||
2152 | dec edx |
||
2153 | test eax,edx |
||
2154 | jnz invalid_align_value |
||
2155 | or eax,eax |
||
2156 | jz invalid_align_value |
||
2157 | cmp eax,1 |
||
2158 | je instruction_assembled |
||
2159 | mov ecx,edi |
||
2160 | mov ebp,[addressing_space] |
||
2161 | sub ecx,[ds:ebp] |
||
2162 | cmp dword [ds:ebp+10h],0 |
||
2163 | jne section_not_aligned_enough |
||
2164 | cmp byte [ds:ebp+9],0 |
||
2165 | je make_alignment |
||
2166 | cmp [output_format],3 |
||
2167 | je pe_alignment |
||
2168 | cmp [output_format],5 |
||
2169 | jne object_alignment |
||
2170 | test [format_flags],1 |
||
2171 | jnz pe_alignment |
||
2172 | object_alignment: |
||
2173 | mov ebx,[ds:ebp+14h] |
||
2174 | cmp byte [ebx],0 |
||
2175 | jne section_not_aligned_enough |
||
2176 | cmp eax,[ebx+10h] |
||
2177 | jbe make_alignment |
||
2178 | jmp section_not_aligned_enough |
||
2179 | pe_alignment: |
||
2180 | cmp eax,1000h |
||
2181 | ja section_not_aligned_enough |
||
2182 | make_alignment: |
||
2183 | dec eax |
||
2184 | and ecx,eax |
||
2185 | jz instruction_assembled |
||
2186 | neg ecx |
||
2187 | add ecx,eax |
||
2188 | inc ecx |
||
2189 | mov edx,ecx |
||
2190 | add edx,edi |
||
2191 | jc out_of_memory |
||
2192 | cmp edx,[tagged_blocks] |
||
2193 | ja out_of_memory |
||
2194 | push edi |
||
2195 | cmp [next_pass_needed],0 |
||
2196 | je nops |
||
2197 | add edi,ecx |
||
2198 | jmp reserved_data |
||
2199 | invalid_align_value: |
||
2200 | cmp [error_line],0 |
||
2201 | jne instruction_assembled |
||
2202 | mov eax,[current_line] |
||
2203 | mov [error_line],eax |
||
2204 | mov [error],invalid_value |
||
2205 | jmp instruction_assembled |
||
2206 | nops: |
||
2207 | mov eax,90909090h |
||
2208 | shr ecx,1 |
||
2209 | jnc nops_stosb_ok |
||
2210 | stos byte [edi] |
||
2211 | nops_stosb_ok: |
||
2212 | shr ecx,1 |
||
2213 | jnc nops_stosw_ok |
||
2214 | stos word [edi] |
||
2215 | nops_stosw_ok: |
||
2216 | rep stos dword [edi] |
||
2217 | jmp reserved_data |
||
2218 | err_directive: |
||
2219 | mov al,[esi] |
||
2220 | cmp al,0Fh |
||
2221 | je invoked_error |
||
2222 | or al,al |
||
2223 | jz invoked_error |
||
2224 | jmp extra_characters_on_line |
||
2225 | assert_directive: |
||
2226 | call calculate_logical_expression |
||
2227 | or al,al |
||
2228 | jnz instruction_assembled |
||
2229 | cmp [error_line],0 |
||
2230 | jne instruction_assembled |
||
2231 | mov eax,[current_line] |
||
2232 | mov [error_line],eax |
||
2233 | mov [error],assertion_failed |
||
2234 | jmp instruction_assembled |
||
2235 |