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