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