Rev 157 | 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-2006, Tomasz Grysztar. |
||
109 | 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 | call get_qword_value |
||
174 | heavyiron | 621 | call calculate_relative_offset |
622 | push esi edi |
||
623 | cmp [next_pass_needed],0 |
||
157 | heavyiron | 624 | jne load_address_type_ok |
174 | heavyiron | 625 | cmp [value_type],0 |
157 | heavyiron | 626 | jne invalid_use_of_symbol |
627 | load_address_type_ok: |
||
174 | heavyiron | 628 | cmp edx,-1 |
629 | jne bad_load_address |
||
630 | neg eax |
||
631 | mov esi,edi |
||
157 | heavyiron | 632 | sub esi,eax |
633 | jc bad_load_address |
||
634 | cmp esi,[org_start] |
||
635 | jb bad_load_address |
||
636 | mov edi,value |
||
637 | movzx ecx,[operand_size] |
||
638 | cmp ecx,eax |
||
639 | ja bad_load_address |
||
640 | rep movs byte [edi],[esi] |
||
641 | jmp value_loaded |
||
642 | bad_load_address: |
||
31 | halyavin | 643 | cmp [error_line],0 |
157 | heavyiron | 644 | jne value_loaded |
645 | mov eax,[current_line] |
||
646 | mov [error_line],eax |
||
647 | mov [error],value_out_of_range |
||
648 | value_loaded: |
||
31 | halyavin | 649 | pop edi esi |
157 | heavyiron | 650 | mov eax,dword [value] |
651 | mov edx,dword [value+4] |
||
652 | pop ebx |
||
653 | xor cx,cx |
||
654 | jmp make_constant |
||
655 | store_directive: |
||
31 | halyavin | 656 | cmp byte [esi],11h |
157 | heavyiron | 657 | je sized_store |
658 | lods byte [esi] |
||
659 | cmp al,'(' |
||
660 | jne invalid_argument |
||
661 | call get_byte_value |
||
662 | xor edx,edx |
||
663 | movzx eax,al |
||
664 | mov [operand_size],1 |
||
665 | jmp store_value_ok |
||
666 | sized_store: |
||
31 | halyavin | 667 | call get_value |
157 | heavyiron | 668 | store_value_ok: |
31 | halyavin | 669 | cmp [value_type],0 |
157 | heavyiron | 670 | jne invalid_use_of_symbol |
671 | mov dword [value],eax |
||
672 | mov dword [value+4],edx |
||
673 | lods word [esi] |
||
674 | cmp ax,80h+'(' shl 8 |
||
675 | jne invalid_argument |
||
676 | cmp byte [esi],'.' |
||
677 | je invalid_value |
||
678 | call get_qword_value |
||
174 | heavyiron | 679 | call calculate_relative_offset |
680 | push esi edi |
||
681 | cmp [next_pass_needed],0 |
||
157 | heavyiron | 682 | jne store_address_type_ok |
174 | heavyiron | 683 | cmp [value_type],0 |
157 | heavyiron | 684 | jne invalid_use_of_symbol |
685 | store_address_type_ok: |
||
174 | heavyiron | 686 | cmp edx,-1 |
687 | jne bad_store_address |
||
688 | neg eax |
||
689 | sub edi,eax |
||
157 | heavyiron | 690 | jc bad_store_address |
691 | cmp edi,[org_start] |
||
692 | jb bad_store_address |
||
693 | mov esi,value |
||
694 | movzx ecx,[operand_size] |
||
695 | cmp ecx,eax |
||
696 | ja bad_store_address |
||
697 | rep movs byte [edi],[esi] |
||
698 | mov eax,edi |
||
699 | pop edi esi |
||
700 | cmp edi,[undefined_data_end] |
||
701 | jne instruction_assembled |
||
702 | cmp eax,[undefined_data_start] |
||
703 | jbe instruction_assembled |
||
704 | mov [undefined_data_start],eax |
||
705 | jmp instruction_assembled |
||
706 | bad_store_address: |
||
31 | halyavin | 707 | pop edi esi |
157 | heavyiron | 708 | cmp [error_line],0 |
709 | jne instruction_assembled |
||
710 | mov eax,[current_line] |
||
711 | mov [error_line],eax |
||
712 | mov [error],value_out_of_range |
||
713 | jmp instruction_assembled |
||
714 | |||
31 | halyavin | 715 | |
716 | lods byte [esi] |
||
157 | heavyiron | 717 | cmp al,'(' |
718 | jne invalid_argument |
||
719 | cmp byte [esi],0 |
||
720 | jne display_byte |
||
721 | inc esi |
||
722 | lods dword [esi] |
||
723 | mov ecx,eax |
||
724 | push edi |
||
725 | mov edi,[display_buffer] |
||
726 | sub edi,4 |
||
727 | sub edi,eax |
||
728 | mov [display_buffer],edi |
||
729 | rep movs byte [edi],[esi] |
||
730 | stos dword [edi] |
||
731 | pop edi |
||
732 | inc esi |
||
733 | jmp display_next |
||
734 | display_byte: |
||
31 | halyavin | 735 | call get_byte_value |
157 | heavyiron | 736 | push edi |
737 | mov edi,[display_buffer] |
||
738 | sub edi,4+1 |
||
739 | mov [display_buffer],edi |
||
740 | stos byte [edi] |
||
741 | mov eax,1 |
||
742 | stos dword [edi] |
||
743 | pop edi |
||
744 | display_next: |
||
31 | halyavin | 745 | cmp edi,[display_buffer] |
157 | heavyiron | 746 | ja out_of_memory |
747 | lods byte [esi] |
||
748 | cmp al,',' |
||
749 | je display_directive |
||
750 | dec esi |
||
751 | jmp instruction_assembled |
||
752 | flush_display_buffer: |
||
31 | halyavin | 753 | mov eax,[display_buffer] |
157 | heavyiron | 754 | or eax,eax |
755 | jz display_done |
||
756 | mov esi,[labels_list] |
||
757 | cmp esi,eax |
||
758 | je display_done |
||
759 | display_messages: |
||
31 | halyavin | 760 | sub esi,4 |
157 | heavyiron | 761 | mov ecx,[esi] |
762 | sub esi,ecx |
||
763 | push esi |
||
764 | call display_block |
||
765 | pop esi |
||
766 | cmp esi,[display_buffer] |
||
767 | jne display_messages |
||
768 | mov eax,[labels_list] |
||
769 | mov [display_buffer],eax |
||
770 | display_done: |
||
31 | halyavin | 771 | ret |
157 | heavyiron | 772 | times_directive: |
31 | halyavin | 773 | lods byte [esi] |
157 | heavyiron | 774 | cmp al,'(' |
775 | jne invalid_argument |
||
776 | cmp byte [esi],'.' |
||
777 | je invalid_value |
||
778 | call get_dword_value |
||
779 | cmp [next_pass_needed],0 |
||
780 | jne times_value_ok |
||
781 | cmp [value_type],0 |
||
782 | jne invalid_use_of_symbol |
||
783 | times_value_ok: |
||
31 | halyavin | 784 | cmp eax,0 |
157 | heavyiron | 785 | je zero_times |
786 | jl negative_times |
||
787 | cmp byte [esi],':' |
||
788 | jne times_argument_ok |
||
789 | inc esi |
||
790 | times_argument_ok: |
||
31 | halyavin | 791 | push [counter] |
157 | heavyiron | 792 | push [counter_limit] |
793 | mov [counter_limit],eax |
||
794 | mov [counter],1 |
||
795 | times_loop: |
||
31 | halyavin | 796 | mov eax,esp |
157 | heavyiron | 797 | sub eax,100h |
798 | jc stack_overflow |
||
799 | cmp eax,[stack_limit] |
||
800 | jb stack_overflow |
||
801 | push esi |
||
802 | or [prefixed_instruction],-1 |
||
803 | call continue_line |
||
804 | mov eax,[counter_limit] |
||
805 | cmp [counter],eax |
||
806 | je times_done |
||
807 | inc [counter] |
||
808 | pop esi |
||
809 | jmp times_loop |
||
810 | times_done: |
||
31 | halyavin | 811 | pop eax |
157 | heavyiron | 812 | pop [counter_limit] |
813 | pop [counter] |
||
814 | jmp instruction_assembled |
||
815 | negative_times: |
||
31 | halyavin | 816 | cmp [error_line],0 |
157 | heavyiron | 817 | jne zero_times |
818 | mov eax,[current_line] |
||
819 | mov [error_line],eax |
||
820 | mov [error],invalid_value |
||
821 | zero_times: |
||
31 | halyavin | 822 | call skip_line |
157 | heavyiron | 823 | jmp instruction_assembled |
824 | |||
31 | halyavin | 825 | |
826 | lods byte [esi] |
||
157 | heavyiron | 827 | cmp al,80h |
828 | jne virtual_at_current |
||
829 | lods byte [esi] |
||
830 | cmp al,'(' |
||
831 | jne invalid_argument |
||
832 | cmp byte [esi],'.' |
||
833 | je invalid_value |
||
834 | call get_address_value |
||
835 | mov ebp,[address_symbol] |
||
836 | xor ch,ch |
||
837 | or bh,bh |
||
838 | jz set_virtual |
||
839 | mov ch,1 |
||
840 | jmp set_virtual |
||
841 | virtual_at_current: |
||
31 | halyavin | 842 | dec esi |
157 | heavyiron | 843 | mov al,[labels_type] |
844 | mov [value_type],al |
||
845 | mov ebp,[org_symbol] |
||
846 | mov eax,edi |
||
847 | xor edx,edx |
||
848 | sub eax,dword [org_origin] |
||
849 | sbb edx,dword [org_origin+4] |
||
850 | mov bx,word [org_registers] |
||
851 | mov cx,word [org_registers+2] |
||
852 | xchg bh,bl |
||
853 | xchg ch,cl |
||
854 | set_virtual: |
||
31 | halyavin | 855 | push [org_registers] |
157 | heavyiron | 856 | mov byte [org_registers],bh |
857 | mov byte [org_registers+1],bl |
||
858 | mov byte [org_registers+2],ch |
||
859 | mov byte [org_registers+3],cl |
||
860 | call allocate_structure_data |
||
861 | mov word [ebx],virtual_directive-assembler |
||
862 | not eax |
||
863 | not edx |
||
864 | add eax,1 |
||
865 | adc edx,0 |
||
866 | add eax,edi |
||
867 | adc edx,0 |
||
868 | xchg dword [org_origin],eax |
||
869 | xchg dword [org_origin+4],edx |
||
870 | mov [ebx+10h],eax |
||
871 | mov [ebx+14h],edx |
||
872 | pop eax |
||
873 | mov [ebx+18h],eax |
||
874 | mov al,[virtual_data] |
||
875 | mov [ebx+2],al |
||
876 | mov al,[labels_type] |
||
877 | mov [ebx+3],al |
||
878 | mov eax,edi |
||
879 | xchg eax,[org_start] |
||
880 | mov [ebx+0Ch],eax |
||
881 | xchg ebp,[org_symbol] |
||
882 | mov [ebx+1Ch],ebp |
||
883 | mov [ebx+8],edi |
||
884 | mov eax,[current_line] |
||
885 | mov [ebx+4],eax |
||
886 | or [virtual_data],-1 |
||
887 | mov al,[value_type] |
||
888 | test al,1 |
||
889 | jnz invalid_use_of_symbol |
||
890 | mov [labels_type],al |
||
891 | jmp instruction_assembled |
||
892 | allocate_structure_data: |
||
31 | halyavin | 893 | mov ebx,[structures_buffer] |
157 | heavyiron | 894 | sub ebx,20h |
895 | cmp ebx,[free_additional_memory] |
||
896 | jb out_of_memory |
||
897 | mov [structures_buffer],ebx |
||
898 | ret |
||
899 | find_structure_data: |
||
31 | halyavin | 900 | mov ebx,[structures_buffer] |
157 | heavyiron | 901 | scan_structures: |
31 | halyavin | 902 | cmp ebx,[additional_memory_end] |
157 | heavyiron | 903 | je no_such_structure |
904 | cmp ax,[ebx] |
||
905 | je structure_data_found |
||
906 | add ebx,20h |
||
907 | jmp scan_structures |
||
908 | structure_data_found: |
||
109 | heavyiron | 909 | ret |
157 | heavyiron | 910 | no_such_structure: |
31 | halyavin | 911 | stc |
157 | heavyiron | 912 | ret |
913 | end_virtual: |
||
31 | halyavin | 914 | call find_structure_data |
157 | heavyiron | 915 | jc unexpected_instruction |
916 | mov al,[ebx+2] |
||
917 | mov [virtual_data],al |
||
918 | mov al,[ebx+3] |
||
919 | mov [labels_type],al |
||
920 | mov eax,[ebx+10h] |
||
921 | mov dword [org_origin],eax |
||
922 | mov eax,[ebx+14h] |
||
923 | mov dword [org_origin+4],eax |
||
924 | mov eax,[ebx+18h] |
||
925 | mov [org_registers],eax |
||
926 | mov eax,[ebx+0Ch] |
||
927 | mov [org_start],eax |
||
928 | mov eax,[ebx+1Ch] |
||
929 | mov [org_symbol],eax |
||
930 | mov edi,[ebx+8] |
||
931 | remove_structure_data: |
||
31 | halyavin | 932 | push esi edi |
157 | heavyiron | 933 | mov esi,[structures_buffer] |
934 | mov ecx,ebx |
||
935 | sub ecx,esi |
||
936 | lea edi,[esi+20h] |
||
937 | mov [structures_buffer],edi |
||
938 | shr ecx,2 |
||
939 | rep movs dword [edi],[esi] |
||
940 | pop edi esi |
||
941 | ret |
||
942 | repeat_directive: |
||
31 | halyavin | 943 | cmp [prefixed_instruction],0 |
157 | heavyiron | 944 | jne unexpected_instruction |
945 | lods byte [esi] |
||
946 | cmp al,'(' |
||
947 | jne invalid_argument |
||
948 | cmp byte [esi],'.' |
||
949 | je invalid_value |
||
950 | call get_dword_value |
||
951 | cmp [next_pass_needed],0 |
||
952 | jne repeat_value_ok |
||
953 | cmp [value_type],0 |
||
954 | jne invalid_use_of_symbol |
||
955 | repeat_value_ok: |
||
31 | halyavin | 956 | cmp eax,0 |
157 | heavyiron | 957 | je zero_repeat |
958 | jl negative_repeat |
||
959 | call allocate_structure_data |
||
960 | mov word [ebx],repeat_directive-assembler |
||
961 | xchg eax,[counter_limit] |
||
962 | mov [ebx+10h],eax |
||
963 | mov eax,1 |
||
964 | xchg eax,[counter] |
||
965 | mov [ebx+14h],eax |
||
966 | mov [ebx+8],esi |
||
967 | mov eax,[current_line] |
||
968 | mov [ebx+4],eax |
||
969 | jmp instruction_assembled |
||
970 | end_repeat: |
||
31 | halyavin | 971 | cmp [prefixed_instruction],0 |
157 | heavyiron | 972 | jne unexpected_instruction |
973 | call find_structure_data |
||
974 | jc unexpected_instruction |
||
975 | mov eax,[counter_limit] |
||
976 | inc [counter] |
||
977 | cmp [counter],eax |
||
978 | jbe continue_repeating |
||
979 | stop_repeat: |
||
31 | halyavin | 980 | mov eax,[ebx+10h] |
157 | heavyiron | 981 | mov [counter_limit],eax |
982 | mov eax,[ebx+14h] |
||
983 | mov [counter],eax |
||
984 | call remove_structure_data |
||
985 | jmp instruction_assembled |
||
986 | continue_repeating: |
||
31 | halyavin | 987 | mov esi,[ebx+8] |
157 | heavyiron | 988 | jmp instruction_assembled |
989 | negative_repeat: |
||
31 | halyavin | 990 | cmp [error_line],0 |
157 | heavyiron | 991 | jne zero_repeat |
992 | mov eax,[current_line] |
||
993 | mov [error_line],eax |
||
994 | mov [error],invalid_value |
||
995 | zero_repeat: |
||
31 | halyavin | 996 | mov al,[esi] |
157 | heavyiron | 997 | or al,al |
998 | jz missing_end_directive |
||
999 | cmp al,0Fh |
||
1000 | jne extra_characters_on_line |
||
1001 | call find_end_repeat |
||
1002 | jmp instruction_assembled |
||
1003 | find_end_repeat: |
||
31 | halyavin | 1004 | call find_structure_end |
157 | heavyiron | 1005 | cmp ax,repeat_directive-assembler |
1006 | jne unexpected_instruction |
||
1007 | ret |
||
1008 | while_directive: |
||
31 | halyavin | 1009 | cmp [prefixed_instruction],0 |
157 | heavyiron | 1010 | jne unexpected_instruction |
1011 | call allocate_structure_data |
||
1012 | mov word [ebx],while_directive-assembler |
||
1013 | mov eax,1 |
||
1014 | xchg eax,[counter] |
||
1015 | mov [ebx+10h],eax |
||
1016 | mov [ebx+8],esi |
||
1017 | mov eax,[current_line] |
||
1018 | mov [ebx+4],eax |
||
1019 | do_while: |
||
31 | halyavin | 1020 | push ebx |
157 | heavyiron | 1021 | call calculate_logical_expression |
1022 | or al,al |
||
1023 | jnz while_true |
||
1024 | mov al,[esi] |
||
1025 | or al,al |
||
1026 | jz missing_end_directive |
||
1027 | cmp al,0Fh |
||
1028 | jne extra_characters_on_line |
||
1029 | stop_while: |
||
31 | halyavin | 1030 | call find_end_while |
157 | heavyiron | 1031 | pop ebx |
1032 | mov eax,[ebx+10h] |
||
1033 | mov [counter],eax |
||
1034 | call remove_structure_data |
||
1035 | jmp instruction_assembled |
||
1036 | while_true: |
||
31 | halyavin | 1037 | pop ebx |
157 | heavyiron | 1038 | jmp instruction_assembled |
1039 | end_while: |
||
31 | halyavin | 1040 | cmp [prefixed_instruction],0 |
157 | heavyiron | 1041 | jne unexpected_instruction |
1042 | call find_structure_data |
||
1043 | jc unexpected_instruction |
||
1044 | mov eax,[ebx+4] |
||
1045 | mov [current_line],eax |
||
1046 | inc [counter] |
||
1047 | jz too_many_repeats |
||
1048 | mov esi,[ebx+8] |
||
1049 | jmp do_while |
||
1050 | find_end_while: |
||
31 | halyavin | 1051 | call find_structure_end |
157 | heavyiron | 1052 | cmp ax,while_directive-assembler |
1053 | jne unexpected_instruction |
||
1054 | ret |
||
1055 | if_directive: |
||
31 | halyavin | 1056 | cmp [prefixed_instruction],0 |
157 | heavyiron | 1057 | jne unexpected_instruction |
1058 | call calculate_logical_expression |
||
1059 | mov dl,al |
||
1060 | mov al,[esi] |
||
1061 | or al,al |
||
1062 | jz missing_end_directive |
||
1063 | cmp al,0Fh |
||
1064 | jne extra_characters_on_line |
||
1065 | or dl,dl |
||
1066 | jnz if_true |
||
1067 | call find_else |
||
1068 | jc instruction_assembled |
||
1069 | mov al,[esi] |
||
1070 | cmp al,1 |
||
1071 | jne else_true |
||
1072 | cmp word [esi+1],if_directive-assembler |
||
1073 | jne else_true |
||
1074 | add esi,4 |
||
1075 | jmp if_directive |
||
1076 | if_true: |
||
31 | halyavin | 1077 | xor al,al |
157 | heavyiron | 1078 | make_if_structure: |
31 | halyavin | 1079 | call allocate_structure_data |
157 | heavyiron | 1080 | mov word [ebx],if_directive-assembler |
1081 | mov byte [ebx+2],al |
||
1082 | mov eax,[current_line] |
||
1083 | mov [ebx+4],eax |
||
1084 | jmp instruction_assembled |
||
1085 | else_true: |
||
31 | halyavin | 1086 | or al,al |
157 | heavyiron | 1087 | jz missing_end_directive |
1088 | cmp al,0Fh |
||
1089 | jne extra_characters_on_line |
||
1090 | or al,-1 |
||
1091 | jmp make_if_structure |
||
1092 | else_directive: |
||
31 | halyavin | 1093 | cmp [prefixed_instruction],0 |
157 | heavyiron | 1094 | jne unexpected_instruction |
1095 | mov ax,if_directive-assembler |
||
1096 | call find_structure_data |
||
1097 | jc unexpected_instruction |
||
1098 | cmp byte [ebx+2],0 |
||
1099 | jne unexpected_instruction |
||
1100 | found_else: |
||
31 | halyavin | 1101 | mov al,[esi] |
157 | heavyiron | 1102 | cmp al,1 |
1103 | jne skip_else |
||
1104 | cmp word [esi+1],if_directive-assembler |
||
1105 | jne skip_else |
||
1106 | add esi,4 |
||
1107 | call find_else |
||
1108 | jnc found_else |
||
1109 | call remove_structure_data |
||
1110 | jmp instruction_assembled |
||
1111 | skip_else: |
||
31 | halyavin | 1112 | or al,al |
157 | heavyiron | 1113 | jz missing_end_directive |
1114 | cmp al,0Fh |
||
1115 | jne extra_characters_on_line |
||
1116 | call find_end_if |
||
1117 | call remove_structure_data |
||
1118 | jmp instruction_assembled |
||
1119 | end_if: |
||
31 | halyavin | 1120 | cmp [prefixed_instruction],0 |
157 | heavyiron | 1121 | jne unexpected_instruction |
1122 | call find_structure_data |
||
1123 | jc unexpected_instruction |
||
1124 | call remove_structure_data |
||
1125 | jmp instruction_assembled |
||
1126 | find_else: |
||
31 | halyavin | 1127 | call find_structure_end |
157 | heavyiron | 1128 | cmp ax,else_directive-assembler |
1129 | je else_found |
||
1130 | cmp ax,if_directive-assembler |
||
1131 | jne unexpected_instruction |
||
1132 | stc |
||
1133 | ret |
||
1134 | else_found: |
||
31 | halyavin | 1135 | clc |
157 | heavyiron | 1136 | ret |
1137 | find_end_if: |
||
31 | halyavin | 1138 | call find_structure_end |
157 | heavyiron | 1139 | cmp ax,if_directive-assembler |
1140 | jne unexpected_instruction |
||
1141 | ret |
||
1142 | find_structure_end: |
||
31 | halyavin | 1143 | push [error_line] |
157 | heavyiron | 1144 | mov eax,[current_line] |
1145 | mov [error_line],eax |
||
1146 | find_end_directive: |
||
31 | halyavin | 1147 | call skip_line |
157 | heavyiron | 1148 | lods byte [esi] |
1149 | cmp al,0Fh |
||
1150 | jne no_end_directive |
||
1151 | lods dword [esi] |
||
1152 | mov [current_line],eax |
||
1153 | skip_labels: |
||
31 | halyavin | 1154 | cmp byte [esi],2 |
157 | heavyiron | 1155 | jne labels_ok |
1156 | add esi,6 |
||
1157 | jmp skip_labels |
||
1158 | labels_ok: |
||
31 | halyavin | 1159 | cmp byte [esi],1 |
157 | heavyiron | 1160 | jne find_end_directive |
1161 | mov ax,[esi+1] |
||
1162 | cmp ax,prefix_instruction-assembler |
||
1163 | je find_end_directive |
||
1164 | add esi,4 |
||
1165 | cmp ax,repeat_directive-assembler |
||
1166 | je skip_repeat |
||
1167 | cmp ax,while_directive-assembler |
||
1168 | je skip_while |
||
1169 | cmp ax,if_directive-assembler |
||
1170 | je skip_if |
||
1171 | cmp ax,else_directive-assembler |
||
1172 | je structure_end |
||
1173 | cmp ax,end_directive-assembler |
||
1174 | jne find_end_directive |
||
1175 | cmp byte [esi],1 |
||
1176 | jne find_end_directive |
||
1177 | mov ax,[esi+1] |
||
1178 | add esi,4 |
||
1179 | cmp ax,repeat_directive-assembler |
||
1180 | je structure_end |
||
1181 | cmp ax,while_directive-assembler |
||
1182 | je structure_end |
||
1183 | cmp ax,if_directive-assembler |
||
1184 | jne find_end_directive |
||
1185 | structure_end: |
||
31 | halyavin | 1186 | pop [error_line] |
157 | heavyiron | 1187 | ret |
1188 | no_end_directive: |
||
31 | halyavin | 1189 | mov eax,[error_line] |
157 | heavyiron | 1190 | mov [current_line],eax |
1191 | jmp missing_end_directive |
||
1192 | skip_repeat: |
||
31 | halyavin | 1193 | call find_end_repeat |
157 | heavyiron | 1194 | jmp find_end_directive |
1195 | skip_while: |
||
31 | halyavin | 1196 | call find_end_while |
157 | heavyiron | 1197 | jmp find_end_directive |
1198 | skip_if: |
||
31 | halyavin | 1199 | call skip_if_block |
157 | heavyiron | 1200 | jmp find_end_directive |
1201 | skip_if_block: |
||
31 | halyavin | 1202 | call find_else |
157 | heavyiron | 1203 | jc if_block_skipped |
1204 | cmp byte [esi],1 |
||
1205 | jne skip_after_else |
||
1206 | cmp word [esi+1],if_directive-assembler |
||
1207 | jne skip_after_else |
||
1208 | add esi,4 |
||
1209 | jmp skip_if_block |
||
1210 | skip_after_else: |
||
31 | halyavin | 1211 | call find_end_if |
157 | heavyiron | 1212 | if_block_skipped: |
31 | halyavin | 1213 | ret |
157 | heavyiron | 1214 | end_directive: |
31 | halyavin | 1215 | lods byte [esi] |
157 | heavyiron | 1216 | cmp al,1 |
1217 | jne invalid_argument |
||
1218 | lods word [esi] |
||
1219 | inc esi |
||
1220 | cmp ax,virtual_directive-assembler |
||
1221 | je end_virtual |
||
1222 | cmp ax,repeat_directive-assembler |
||
1223 | je end_repeat |
||
1224 | cmp ax,while_directive-assembler |
||
1225 | je end_while |
||
1226 | cmp ax,if_directive-assembler |
||
1227 | je end_if |
||
1228 | cmp ax,data_directive-assembler |
||
1229 | je end_data |
||
1230 | jmp invalid_argument |
||
1231 | break_directive: |
||
31 | halyavin | 1232 | mov ebx,[structures_buffer] |
157 | heavyiron | 1233 | mov al,[esi] |
1234 | or al,al |
||
1235 | jz find_breakable_structure |
||
1236 | cmp al,0Fh |
||
1237 | jne extra_characters_on_line |
||
1238 | find_breakable_structure: |
||
31 | halyavin | 1239 | cmp ebx,[additional_memory_end] |
157 | heavyiron | 1240 | je unexpected_instruction |
1241 | mov ax,[ebx] |
||
1242 | cmp ax,repeat_directive-assembler |
||
1243 | je break_repeat |
||
1244 | cmp ax,while_directive-assembler |
||
1245 | je break_while |
||
1246 | cmp ax,if_directive-assembler |
||
1247 | je break_if |
||
1248 | add ebx,20h |
||
1249 | jmp find_breakable_structure |
||
1250 | break_if: |
||
31 | halyavin | 1251 | push [current_line] |
157 | heavyiron | 1252 | mov eax,[ebx+4] |
1253 | mov [current_line],eax |
||
1254 | call remove_structure_data |
||
1255 | call skip_if_block |
||
1256 | pop [current_line] |
||
1257 | mov ebx,[structures_buffer] |
||
1258 | jmp find_breakable_structure |
||
1259 | break_repeat: |
||
31 | halyavin | 1260 | push ebx |
157 | heavyiron | 1261 | call find_end_repeat |
1262 | pop ebx |
||
1263 | jmp stop_repeat |
||
1264 | break_while: |
||
31 | halyavin | 1265 | push ebx |
157 | heavyiron | 1266 | jmp stop_while |
1267 | |||
31 | halyavin | 1268 | |
1269 | call define_data |
||
157 | heavyiron | 1270 | lods byte [esi] |
1271 | cmp al,'(' |
||
1272 | je get_byte |
||
1273 | cmp al,'?' |
||
1274 | jne invalid_argument |
||
1275 | mov eax,edi |
||
1276 | mov byte [edi],0 |
||
1277 | inc edi |
||
1278 | jmp undefined_data |
||
1279 | get_byte: |
||
31 | halyavin | 1280 | cmp byte [esi],0 |
157 | heavyiron | 1281 | je get_string |
1282 | call get_byte_value |
||
1283 | stos byte [edi] |
||
1284 | ret |
||
1285 | get_string: |
||
31 | halyavin | 1286 | inc esi |
157 | heavyiron | 1287 | lods dword [esi] |
1288 | mov ecx,eax |
||
1289 | lea eax,[edi+ecx] |
||
1290 | cmp eax,[display_buffer] |
||
1291 | ja out_of_memory |
||
1292 | rep movs byte [edi],[esi] |
||
1293 | inc esi |
||
1294 | ret |
||
1295 | undefined_data: |
||
31 | halyavin | 1296 | cmp [virtual_data],0 |
157 | heavyiron | 1297 | je mark_undefined_data |
1298 | ret |
||
1299 | mark_undefined_data: |
||
31 | halyavin | 1300 | cmp eax,[undefined_data_end] |
157 | heavyiron | 1301 | je undefined_data_ok |
1302 | mov [undefined_data_start],eax |
||
1303 | undefined_data_ok: |
||
31 | halyavin | 1304 | mov [undefined_data_end],edi |
157 | heavyiron | 1305 | ret |
1306 | define_data: |
||
31 | halyavin | 1307 | cmp edi,[display_buffer] |
157 | heavyiron | 1308 | jae out_of_memory |
1309 | cmp byte [esi],'(' |
||
1310 | jne simple_data_value |
||
1311 | mov ebx,esi |
||
1312 | inc esi |
||
1313 | call skip_expression |
||
1314 | xchg esi,ebx |
||
1315 | cmp byte [ebx],81h |
||
1316 | jne simple_data_value |
||
1317 | inc esi |
||
1318 | call get_dword_value |
||
1319 | cmp [next_pass_needed],0 |
||
1320 | jne dup_value_ok |
||
1321 | cmp [value_type],0 |
||
1322 | jne invalid_use_of_symbol |
||
1323 | dup_value_ok: |
||
31 | halyavin | 1324 | inc esi |
157 | heavyiron | 1325 | cmp eax,0 |
1326 | jg dup_positive |
||
1327 | cmp [error_line],0 |
||
1328 | jne dup_invalid |
||
1329 | mov eax,[current_line] |
||
1330 | mov [error_line],eax |
||
1331 | mov [error],invalid_value |
||
1332 | dup_invalid: |
||
31 | halyavin | 1333 | mov eax,1 |
157 | heavyiron | 1334 | dup_positive: |
31 | halyavin | 1335 | cmp byte [esi],'{' |
157 | heavyiron | 1336 | jne duplicate_single_data_value |
1337 | inc esi |
||
1338 | duplicate_data: |
||
31 | halyavin | 1339 | push eax esi |
157 | heavyiron | 1340 | duplicated_values: |
31 | halyavin | 1341 | cmp edi,[display_buffer] |
157 | heavyiron | 1342 | jae out_of_memory |
1343 | call near dword [esp+8] |
||
1344 | lods byte [esi] |
||
1345 | cmp al,',' |
||
1346 | je duplicated_values |
||
1347 | cmp al,'}' |
||
1348 | jne invalid_argument |
||
1349 | pop ebx eax |
||
1350 | dec eax |
||
1351 | jz data_defined |
||
1352 | mov esi,ebx |
||
1353 | jmp duplicate_data |
||
1354 | duplicate_single_data_value: |
||
31 | halyavin | 1355 | cmp edi,[display_buffer] |
157 | heavyiron | 1356 | jae out_of_memory |
1357 | push eax esi |
||
1358 | call near dword [esp+8] |
||
1359 | pop ebx eax |
||
1360 | dec eax |
||
1361 | jz data_defined |
||
1362 | mov esi,ebx |
||
1363 | jmp duplicate_single_data_value |
||
1364 | simple_data_value: |
||
31 | halyavin | 1365 | cmp edi,[display_buffer] |
157 | heavyiron | 1366 | jae out_of_memory |
1367 | call near dword [esp] |
||
1368 | data_defined: |
||
31 | halyavin | 1369 | lods byte [esi] |
157 | heavyiron | 1370 | cmp al,',' |
1371 | je define_data |
||
1372 | dec esi |
||
1373 | add esp,4 |
||
1374 | jmp instruction_assembled |
||
1375 | data_unicode: |
||
31 | halyavin | 1376 | or [base_code],-1 |
157 | heavyiron | 1377 | jmp define_words |
1378 | data_words: |
||
31 | halyavin | 1379 | mov [base_code],0 |
157 | heavyiron | 1380 | define_words: |
31 | halyavin | 1381 | call define_data |
157 | heavyiron | 1382 | lods byte [esi] |
1383 | cmp al,'(' |
||
1384 | je get_word |
||
1385 | cmp al,'?' |
||
1386 | jne invalid_argument |
||
1387 | mov eax,edi |
||
1388 | mov word [edi],0 |
||
1389 | scas word [edi] |
||
1390 | jmp undefined_data |
||
1391 | ret |
||
1392 | get_word: |
||
31 | halyavin | 1393 | cmp [base_code],0 |
157 | heavyiron | 1394 | je word_data_value |
1395 | cmp byte [esi],0 |
||
1396 | je word_string |
||
1397 | word_data_value: |
||
31 | halyavin | 1398 | call get_word_value |
157 | heavyiron | 1399 | call mark_relocation |
1400 | stos word [edi] |
||
1401 | ret |
||
1402 | word_string: |
||
31 | halyavin | 1403 | inc esi |
157 | heavyiron | 1404 | lods dword [esi] |
1405 | mov ecx,eax |
||
1406 | jecxz word_string_ok |
||
1407 | lea eax,[edi+ecx*2] |
||
1408 | cmp eax,[display_buffer] |
||
1409 | ja out_of_memory |
||
1410 | xor ah,ah |
||
1411 | copy_word_string: |
||
31 | halyavin | 1412 | lods byte [esi] |
157 | heavyiron | 1413 | stos word [edi] |
1414 | loop copy_word_string |
||
1415 | word_string_ok: |
||
31 | halyavin | 1416 | inc esi |
157 | heavyiron | 1417 | ret |
1418 | data_dwords: |
||
31 | halyavin | 1419 | call define_data |
157 | heavyiron | 1420 | lods byte [esi] |
1421 | cmp al,'(' |
||
1422 | je get_dword |
||
1423 | cmp al,'?' |
||
1424 | jne invalid_argument |
||
1425 | mov eax,edi |
||
1426 | mov dword [edi],0 |
||
1427 | scas dword [edi] |
||
1428 | jmp undefined_data |
||
1429 | get_dword: |
||
31 | halyavin | 1430 | push esi |
157 | heavyiron | 1431 | call get_dword_value |
1432 | pop ebx |
||
1433 | cmp byte [esi],':' |
||
1434 | je complex_dword |
||
1435 | call mark_relocation |
||
1436 | stos dword [edi] |
||
1437 | ret |
||
1438 | complex_dword: |
||
31 | halyavin | 1439 | mov esi,ebx |
157 | heavyiron | 1440 | cmp byte [esi],'.' |
1441 | je invalid_value |
||
1442 | call get_word_value |
||
1443 | push eax |
||
1444 | inc esi |
||
1445 | lods byte [esi] |
||
1446 | cmp al,'(' |
||
1447 | jne invalid_operand |
||
1448 | mov al,[value_type] |
||
1449 | push eax |
||
1450 | cmp byte [esi],'.' |
||
1451 | je invalid_value |
||
1452 | call get_word_value |
||
1453 | call mark_relocation |
||
1454 | stos word [edi] |
||
1455 | pop eax |
||
1456 | mov [value_type],al |
||
1457 | pop eax |
||
1458 | call mark_relocation |
||
1459 | stos word [edi] |
||
1460 | ret |
||
1461 | data_pwords: |
||
31 | halyavin | 1462 | call define_data |
157 | heavyiron | 1463 | lods byte [esi] |
1464 | cmp al,'(' |
||
1465 | je get_pword |
||
1466 | cmp al,'?' |
||
1467 | jne invalid_argument |
||
1468 | mov eax,edi |
||
1469 | mov dword [edi],0 |
||
1470 | scas dword [edi] |
||
1471 | mov word [edi],0 |
||
1472 | scas word [edi] |
||
1473 | jmp undefined_data |
||
1474 | get_pword: |
||
31 | halyavin | 1475 | push esi |
157 | heavyiron | 1476 | call get_pword_value |
1477 | pop ebx |
||
1478 | cmp byte [esi],':' |
||
1479 | je complex_pword |
||
1480 | call mark_relocation |
||
1481 | stos dword [edi] |
||
1482 | mov ax,dx |
||
1483 | stos word [edi] |
||
1484 | ret |
||
1485 | complex_pword: |
||
31 | halyavin | 1486 | mov esi,ebx |
157 | heavyiron | 1487 | cmp byte [esi],'.' |
1488 | je invalid_value |
||
1489 | call get_word_value |
||
1490 | push eax |
||
1491 | inc esi |
||
1492 | lods byte [esi] |
||
1493 | cmp al,'(' |
||
1494 | jne invalid_operand |
||
1495 | mov al,[value_type] |
||
1496 | push eax |
||
1497 | cmp byte [esi],'.' |
||
1498 | je invalid_value |
||
1499 | call get_dword_value |
||
1500 | call mark_relocation |
||
1501 | stos dword [edi] |
||
1502 | pop eax |
||
1503 | mov [value_type],al |
||
1504 | pop eax |
||
1505 | call mark_relocation |
||
1506 | stos word [edi] |
||
1507 | ret |
||
1508 | data_qwords: |
||
31 | halyavin | 1509 | call define_data |
157 | heavyiron | 1510 | lods byte [esi] |
1511 | cmp al,'(' |
||
1512 | je get_qword |
||
1513 | cmp al,'?' |
||
1514 | jne invalid_argument |
||
1515 | mov eax,edi |
||
1516 | mov dword [edi],0 |
||
1517 | scas dword [edi] |
||
1518 | mov dword [edi],0 |
||
1519 | scas dword [edi] |
||
1520 | jmp undefined_data |
||
1521 | get_qword: |
||
31 | halyavin | 1522 | call get_qword_value |
157 | heavyiron | 1523 | call mark_relocation |
1524 | stos dword [edi] |
||
1525 | mov eax,edx |
||
1526 | stos dword [edi] |
||
1527 | ret |
||
1528 | data_twords: |
||
31 | halyavin | 1529 | call define_data |
157 | heavyiron | 1530 | lods byte [esi] |
1531 | cmp al,'(' |
||
1532 | je get_tword |
||
1533 | cmp al,'?' |
||
1534 | jne invalid_argument |
||
1535 | mov eax,edi |
||
1536 | mov dword [edi],0 |
||
1537 | scas dword [edi] |
||
1538 | mov dword [edi],0 |
||
1539 | scas dword [edi] |
||
1540 | mov word [edi],0 |
||
1541 | scas word [edi] |
||
1542 | jmp undefined_data |
||
1543 | get_tword: |
||
31 | halyavin | 1544 | cmp byte [esi],'.' |
157 | heavyiron | 1545 | jne complex_tword |
1546 | inc esi |
||
1547 | cmp word [esi+8],8000h |
||
1548 | je fp_zero_tword |
||
1549 | mov eax,[esi] |
||
1550 | stos dword [edi] |
||
1551 | mov eax,[esi+4] |
||
1552 | stos dword [edi] |
||
1553 | mov ax,[esi+8] |
||
1554 | add ax,3FFFh |
||
1555 | cmp ax,8000h |
||
1556 | jae value_out_of_range |
||
1557 | mov bl,[esi+11] |
||
1558 | shl bx,15 |
||
1559 | or ax,bx |
||
1560 | stos word [edi] |
||
1561 | add esi,13 |
||
1562 | ret |
||
1563 | fp_zero_tword: |
||
31 | halyavin | 1564 | xor eax,eax |
157 | heavyiron | 1565 | stos dword [edi] |
1566 | stos dword [edi] |
||
1567 | mov al,[esi+11] |
||
1568 | shl ax,15 |
||
1569 | stos word [edi] |
||
1570 | add esi,13 |
||
1571 | ret |
||
1572 | complex_tword: |
||
31 | halyavin | 1573 | call get_word_value |
157 | heavyiron | 1574 | push eax |
1575 | inc esi |
||
1576 | lods byte [esi] |
||
1577 | cmp al,'(' |
||
1578 | jne invalid_operand |
||
1579 | mov al,[value_type] |
||
1580 | push eax |
||
1581 | cmp byte [esi],'.' |
||
1582 | je invalid_value |
||
1583 | call get_qword_value |
||
1584 | call mark_relocation |
||
1585 | stos dword [edi] |
||
1586 | mov eax,edx |
||
1587 | stos dword [edi] |
||
1588 | pop eax |
||
1589 | mov [value_type],al |
||
1590 | pop eax |
||
1591 | call mark_relocation |
||
1592 | stos word [edi] |
||
1593 | ret |
||
1594 | data_file: |
||
31 | halyavin | 1595 | lods word [esi] |
157 | heavyiron | 1596 | cmp ax,'(' |
1597 | jne invalid_argument |
||
1598 | add esi,4 |
||
1599 | call open_binary_file |
||
1600 | mov eax,[esi-4] |
||
1601 | lea esi,[esi+eax+1] |
||
1602 | mov al,2 |
||
1603 | xor edx,edx |
||
1604 | call lseek |
||
1605 | push eax |
||
1606 | xor edx,edx |
||
1607 | cmp byte [esi],':' |
||
1608 | jne position_ok |
||
1609 | inc esi |
||
1610 | cmp byte [esi],'(' |
||
1611 | jne invalid_argument |
||
1612 | inc esi |
||
1613 | cmp byte [esi],'.' |
||
1614 | je invalid_value |
||
1615 | push ebx |
||
1616 | call get_dword_value |
||
1617 | pop ebx |
||
1618 | mov edx,eax |
||
1619 | sub [esp],edx |
||
1620 | position_ok: |
||
31 | halyavin | 1621 | cmp byte [esi],',' |
157 | heavyiron | 1622 | jne size_ok |
1623 | inc esi |
||
1624 | cmp byte [esi],'(' |
||
1625 | jne invalid_argument |
||
1626 | inc esi |
||
1627 | cmp byte [esi],'.' |
||
1628 | je invalid_value |
||
1629 | push ebx edx |
||
1630 | call get_dword_value |
||
1631 | pop edx ebx |
||
1632 | mov [esp],eax |
||
1633 | size_ok: |
||
31 | halyavin | 1634 | xor al,al |
157 | heavyiron | 1635 | call lseek |
1636 | pop ecx |
||
1637 | mov edx,edi |
||
1638 | add edi,ecx |
||
1639 | jc out_of_memory |
||
1640 | cmp edi,[display_buffer] |
||
1641 | ja out_of_memory |
||
1642 | call read |
||
1643 | jc error_reading_file |
||
1644 | call close |
||
1645 | lods byte [esi] |
||
1646 | cmp al,',' |
||
1647 | je data_file |
||
1648 | dec esi |
||
1649 | jmp instruction_assembled |
||
1650 | open_binary_file: |
||
31 | halyavin | 1651 | push esi |
157 | heavyiron | 1652 | push edi |
1653 | mov esi,[current_line] |
||
1654 | mov esi,[esi] |
||
1655 | get_current_path: |
||
31 | halyavin | 1656 | lodsb |
157 | heavyiron | 1657 | stosb |
1658 | or al,al |
||
1659 | jnz get_current_path |
||
1660 | cut_current_path: |
||
31 | halyavin | 1661 | cmp edi,[esp] |
157 | heavyiron | 1662 | je current_path_ok |
1663 | cmp byte [edi-1],'\' |
||
1664 | je current_path_ok |
||
1665 | cmp byte [edi-1],'/' |
||
1666 | je current_path_ok |
||
1667 | dec edi |
||
1668 | jmp cut_current_path |
||
1669 | current_path_ok: |
||
31 | halyavin | 1670 | mov esi,[esp+4] |
157 | heavyiron | 1671 | call preprocess_path |
1672 | pop edx |
||
1673 | mov esi,edx |
||
1674 | call open |
||
1675 | jnc file_opened |
||
1676 | mov edi,esi |
||
1677 | mov esi,[esp] |
||
1678 | push edi |
||
1679 | call preprocess_path |
||
1680 | pop edx |
||
1681 | mov esi,edx |
||
1682 | call open |
||
1683 | jc file_not_found |
||
1684 | file_opened: |
||
31 | halyavin | 1685 | mov edi,esi |
157 | heavyiron | 1686 | pop esi |
1687 | ret |
||
1688 | reserve_bytes: |
||
31 | halyavin | 1689 | lods byte [esi] |
157 | heavyiron | 1690 | cmp al,'(' |
1691 | jne invalid_argument |
||
1692 | cmp byte [esi],'.' |
||
1693 | je invalid_value |
||
1694 | call get_dword_value |
||
1695 | cmp [next_pass_needed],0 |
||
1696 | jne rb_value_ok |
||
1697 | cmp [value_type],0 |
||
1698 | jne invalid_use_of_symbol |
||
1699 | rb_value_ok: |
||
31 | halyavin | 1700 | cmp eax,0 |
157 | heavyiron | 1701 | jl reserve_negative |
1702 | mov ecx,eax |
||
1703 | mov edx,ecx |
||
1704 | add edx,edi |
||
1705 | jc out_of_memory |
||
1706 | cmp edx,[display_buffer] |
||
1707 | ja out_of_memory |
||
1708 | push edi |
||
1709 | cmp [next_pass_needed],0 |
||
1710 | je zero_bytes |
||
1711 | add edi,ecx |
||
1712 | jmp reserved_data |
||
1713 | zero_bytes: |
||
31 | halyavin | 1714 | xor eax,eax |
157 | heavyiron | 1715 | shr ecx,1 |
1716 | jnc bytes_stosb_ok |
||
1717 | stos byte [edi] |
||
1718 | bytes_stosb_ok: |
||
31 | halyavin | 1719 | shr ecx,1 |
157 | heavyiron | 1720 | jnc bytes_stosw_ok |
1721 | stos word [edi] |
||
1722 | bytes_stosw_ok: |
||
31 | halyavin | 1723 | rep stos dword [edi] |
157 | heavyiron | 1724 | reserved_data: |
31 | halyavin | 1725 | pop eax |
157 | heavyiron | 1726 | call undefined_data |
1727 | jmp instruction_assembled |
||
1728 | reserve_negative: |
||
31 | halyavin | 1729 | cmp [error_line],0 |
157 | heavyiron | 1730 | jne instruction_assembled |
1731 | mov eax,[current_line] |
||
1732 | mov [error_line],eax |
||
1733 | mov [error],invalid_value |
||
1734 | jmp instruction_assembled |
||
1735 | reserve_words: |
||
31 | halyavin | 1736 | lods byte [esi] |
157 | heavyiron | 1737 | cmp al,'(' |
1738 | jne invalid_argument |
||
1739 | cmp byte [esi],'.' |
||
1740 | je invalid_value |
||
1741 | call get_dword_value |
||
1742 | cmp [next_pass_needed],0 |
||
1743 | jne rw_value_ok |
||
1744 | cmp [value_type],0 |
||
1745 | jne invalid_use_of_symbol |
||
1746 | rw_value_ok: |
||
31 | halyavin | 1747 | cmp eax,0 |
157 | heavyiron | 1748 | jl reserve_negative |
1749 | mov ecx,eax |
||
1750 | mov edx,ecx |
||
1751 | shl edx,1 |
||
1752 | jc out_of_memory |
||
1753 | add edx,edi |
||
1754 | jc out_of_memory |
||
1755 | cmp edx,[display_buffer] |
||
1756 | ja out_of_memory |
||
1757 | push edi |
||
1758 | cmp [next_pass_needed],0 |
||
1759 | je zero_words |
||
1760 | lea edi,[edi+ecx*2] |
||
1761 | jmp reserved_data |
||
1762 | zero_words: |
||
31 | halyavin | 1763 | xor eax,eax |
157 | heavyiron | 1764 | shr ecx,1 |
1765 | jnc words_stosw_ok |
||
1766 | stos word [edi] |
||
1767 | words_stosw_ok: |
||
31 | halyavin | 1768 | rep stos dword [edi] |
157 | heavyiron | 1769 | jmp reserved_data |
1770 | reserve_dwords: |
||
31 | halyavin | 1771 | lods byte [esi] |
157 | heavyiron | 1772 | cmp al,'(' |
1773 | jne invalid_argument |
||
1774 | cmp byte [esi],'.' |
||
1775 | je invalid_value |
||
1776 | call get_dword_value |
||
1777 | cmp [next_pass_needed],0 |
||
1778 | jne rd_value_ok |
||
1779 | cmp [value_type],0 |
||
1780 | jne invalid_use_of_symbol |
||
1781 | rd_value_ok: |
||
31 | halyavin | 1782 | cmp eax,0 |
157 | heavyiron | 1783 | jl reserve_negative |
1784 | mov ecx,eax |
||
1785 | mov edx,ecx |
||
1786 | shl edx,1 |
||
1787 | jc out_of_memory |
||
1788 | shl edx,1 |
||
1789 | jc out_of_memory |
||
1790 | add edx,edi |
||
1791 | jc out_of_memory |
||
1792 | cmp edx,[display_buffer] |
||
1793 | ja out_of_memory |
||
1794 | push edi |
||
1795 | cmp [next_pass_needed],0 |
||
1796 | je zero_dwords |
||
1797 | lea edi,[edi+ecx*4] |
||
1798 | jmp reserved_data |
||
1799 | zero_dwords: |
||
31 | halyavin | 1800 | xor eax,eax |
157 | heavyiron | 1801 | rep stos dword [edi] |
1802 | jmp reserved_data |
||
1803 | reserve_pwords: |
||
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 rp_value_ok |
||
1812 | cmp [value_type],0 |
||
1813 | jne invalid_use_of_symbol |
||
1814 | rp_value_ok: |
||
31 | halyavin | 1815 | cmp eax,0 |
157 | heavyiron | 1816 | jl reserve_negative |
1817 | mov ecx,eax |
||
1818 | shl ecx,1 |
||
1819 | jc out_of_memory |
||
1820 | add ecx,eax |
||
1821 | mov edx,ecx |
||
1822 | shl edx,1 |
||
1823 | jc out_of_memory |
||
1824 | add edx,edi |
||
1825 | jc out_of_memory |
||
1826 | cmp edx,[display_buffer] |
||
1827 | ja out_of_memory |
||
1828 | push edi |
||
1829 | cmp [next_pass_needed],0 |
||
1830 | je zero_words |
||
1831 | lea edi,[edi+ecx*2] |
||
1832 | jmp reserved_data |
||
1833 | reserve_qwords: |
||
31 | halyavin | 1834 | lods byte [esi] |
157 | heavyiron | 1835 | cmp al,'(' |
1836 | jne invalid_argument |
||
1837 | cmp byte [esi],'.' |
||
1838 | je invalid_value |
||
1839 | call get_dword_value |
||
1840 | cmp [next_pass_needed],0 |
||
1841 | jne rq_value_ok |
||
1842 | cmp [value_type],0 |
||
1843 | jne invalid_use_of_symbol |
||
1844 | rq_value_ok: |
||
31 | halyavin | 1845 | cmp eax,0 |
157 | heavyiron | 1846 | jl reserve_negative |
1847 | mov ecx,eax |
||
1848 | shl ecx,1 |
||
1849 | jc out_of_memory |
||
1850 | mov edx,ecx |
||
1851 | shl edx,1 |
||
1852 | jc out_of_memory |
||
1853 | shl edx,1 |
||
1854 | jc out_of_memory |
||
1855 | add edx,edi |
||
1856 | jc out_of_memory |
||
1857 | cmp edx,[display_buffer] |
||
1858 | ja out_of_memory |
||
1859 | push edi |
||
1860 | cmp [next_pass_needed],0 |
||
1861 | je zero_dwords |
||
1862 | lea edi,[edi+ecx*4] |
||
1863 | jmp reserved_data |
||
1864 | reserve_twords: |
||
31 | halyavin | 1865 | lods byte [esi] |
157 | heavyiron | 1866 | cmp al,'(' |
1867 | jne invalid_argument |
||
1868 | cmp byte [esi],'.' |
||
1869 | je invalid_value |
||
1870 | call get_dword_value |
||
1871 | cmp [next_pass_needed],0 |
||
1872 | jne rt_value_ok |
||
1873 | cmp [value_type],0 |
||
1874 | jne invalid_use_of_symbol |
||
1875 | rt_value_ok: |
||
31 | halyavin | 1876 | cmp eax,0 |
157 | heavyiron | 1877 | jl reserve_negative |
1878 | mov ecx,eax |
||
1879 | shl ecx,2 |
||
1880 | jc out_of_memory |
||
1881 | add ecx,eax |
||
1882 | mov edx,ecx |
||
1883 | shl edx,1 |
||
1884 | jc out_of_memory |
||
1885 | add edx,edi |
||
1886 | jc out_of_memory |
||
1887 | cmp edx,[display_buffer] |
||
1888 | ja out_of_memory |
||
1889 | push edi |
||
1890 | cmp [next_pass_needed],0 |
||
1891 | je zero_words |
||
1892 | lea edi,[edi+ecx*2] |
||
1893 | jmp reserved_data |
||
1894 | align_directive: |
||
31 | halyavin | 1895 | lods byte [esi] |
157 | heavyiron | 1896 | cmp al,'(' |
1897 | jne invalid_argument |
||
1898 | cmp byte [esi],'.' |
||
1899 | je invalid_value |
||
1900 | call get_dword_value |
||
1901 | cmp [value_type],0 |
||
1902 | jne invalid_use_of_symbol |
||
1903 | mov edx,eax |
||
1904 | dec edx |
||
1905 | test eax,edx |
||
1906 | jnz negative_times |
||
1907 | or eax,eax |
||
1908 | jz negative_times |
||
1909 | cmp eax,1 |
||
1910 | je instruction_assembled |
||
1911 | mov ecx,edi |
||
1912 | sub ecx,dword [org_origin] |
||
1913 | cmp [org_registers],0 |
||
1914 | jne section_not_aligned_enough |
||
1915 | cmp [labels_type],0 |
||
1916 | je make_alignment |
||
1917 | cmp [output_format],3 |
||
1918 | je pe_alignment |
||
1919 | mov ebx,[org_symbol] |
||
1920 | cmp byte [ebx],0 |
||
1921 | jne section_not_aligned_enough |
||
1922 | cmp eax,[ebx+10h] |
||
1923 | jbe make_alignment |
||
1924 | jmp section_not_aligned_enough |
||
1925 | pe_alignment: |
||
31 | halyavin | 1926 | cmp eax,1000h |
157 | heavyiron | 1927 | ja section_not_aligned_enough |
1928 | make_alignment: |
||
31 | halyavin | 1929 | dec eax |
157 | heavyiron | 1930 | and ecx,eax |
1931 | jz instruction_assembled |
||
1932 | neg ecx |
||
1933 | add ecx,eax |
||
1934 | inc ecx |
||
1935 | mov edx,ecx |
||
1936 | add edx,edi |
||
1937 | jc out_of_memory |
||
1938 | cmp edx,[display_buffer] |
||
1939 | ja out_of_memory |
||
1940 | push edi |
||
1941 | cmp [next_pass_needed],0 |
||
1942 | je nops |
||
1943 | add edi,ecx |
||
1944 | jmp reserved_data |
||
1945 | nops: |
||
31 | halyavin | 1946 | mov eax,90909090h |
157 | heavyiron | 1947 | shr ecx,1 |
1948 | jnc nops_stosb_ok |
||
1949 | stos byte [edi] |
||
1950 | nops_stosb_ok: |
||
31 | halyavin | 1951 | shr ecx,1 |
157 | heavyiron | 1952 | jnc nops_stosw_ok |
1953 | stos word [edi] |
||
1954 | nops_stosw_ok: |
||
31 | halyavin | 1955 | rep stos dword [edi] |
157 | heavyiron | 1956 | jmp reserved_data |
1957 |