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