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