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