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