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