Rev 4039 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4039 | Rev 6467 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ; flat assembler core |
1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2013, Tomasz Grysztar. |
2 | ; Copyright (c) 1999-2016, Tomasz Grysztar. |
3 | ; All rights reserved. |
3 | ; All rights reserved. |
Line 4... | Line 4... | ||
4 | 4 | ||
5 | assembler: |
5 | assembler: |
6 | xor eax,eax |
6 | xor eax,eax |
Line 30... | Line 30... | ||
30 | mov [file_extension],eax |
30 | mov [file_extension],eax |
31 | mov [next_pass_needed],al |
31 | mov [next_pass_needed],al |
32 | mov [output_format],al |
32 | mov [output_format],al |
33 | mov [adjustment_sign],al |
33 | mov [adjustment_sign],al |
34 | mov [code_type],16 |
34 | mov [evex_mode],al |
- | 35 | mov [code_type],16 |
|
35 | call init_addressing_space |
36 | call init_addressing_space |
36 | pass_loop: |
37 | pass_loop: |
37 | call assemble_line |
38 | call assemble_line |
38 | jnc pass_loop |
39 | jnc pass_loop |
39 | mov eax,[additional_memory_end] |
40 | mov eax,[additional_memory_end] |
Line 190... | Line 191... | ||
190 | jmp instruction_assembled |
191 | jmp instruction_assembled |
191 | new_line: |
192 | new_line: |
192 | lods dword [esi] |
193 | lods dword [esi] |
193 | mov [current_line],eax |
194 | mov [current_line],eax |
194 | mov [prefixed_instruction],0 |
195 | and [prefix_flags],0 |
195 | cmp [symbols_file],0 |
196 | cmp [symbols_file],0 |
196 | je continue_line |
197 | je continue_line |
197 | cmp [next_pass_needed],0 |
198 | cmp [next_pass_needed],0 |
198 | jne continue_line |
199 | jne continue_line |
199 | mov ebx,[tagged_blocks] |
200 | mov ebx,[tagged_blocks] |
200 | mov dword [ebx-4],1 |
201 | mov dword [ebx-4],1 |
Line 327... | Line 328... | ||
327 | inc esi |
328 | inc esi |
328 | cmp eax,0Fh |
329 | cmp eax,0Fh |
329 | jb invalid_use_of_symbol |
330 | jb invalid_use_of_symbol |
330 | je reserved_word_used_as_symbol |
331 | je reserved_word_used_as_symbol |
331 | mov edx,[eax+8] |
332 | push eax |
332 | push edx |
- | |
333 | cmp [current_pass],0 |
- | |
334 | je get_constant_value |
- | |
335 | test dl,4 |
- | |
336 | jnz get_constant_value |
- | |
337 | mov cx,[current_pass] |
- | |
338 | cmp cx,[eax+16] |
- | |
339 | je get_constant_value |
- | |
340 | or dl,4 |
- | |
341 | mov [eax+8],dl |
- | |
342 | get_constant_value: |
- | |
343 | push eax |
- | |
344 | mov al,byte [esi-1] |
- | |
345 | push eax |
- | |
346 | or [size_override],-1 |
333 | or [operand_flags],1 |
347 | call get_value |
334 | call get_value |
348 | pop ebx |
335 | pop ebx |
349 | mov ch,bl |
336 | xor cl,cl |
350 | pop ebx |
- | |
351 | pop ecx |
- | |
352 | test cl,4 |
- | |
353 | jnz constant_referencing_mode_ok |
- | |
354 | and byte [ebx+8],not 4 |
- | |
355 | constant_referencing_mode_ok: |
- | |
356 | xor cl,cl |
- | |
357 | mov ch,[value_type] |
337 | mov ch,[value_type] |
358 | cmp ch,3 |
338 | cmp ch,3 |
359 | je invalid_use_of_symbol |
339 | je invalid_use_of_symbol |
360 | make_constant: |
340 | make_constant: |
361 | and byte [ebx+9],not 1 |
341 | and byte [ebx+9],not 1 |
Line 452... | Line 432... | ||
452 | or byte [ebx+0Ah],2 |
432 | or byte [ebx+0Ah],2 |
453 | jmp continue_line |
433 | jmp continue_line |
454 | assemble_instruction: |
434 | assemble_instruction: |
455 | ; mov [operand_size],0 |
435 | ; mov [operand_size],0 |
456 | ; mov [size_override],0 |
436 | ; mov [operand_flags],0 |
457 | ; mov [operand_prefix],0 |
437 | ; mov [operand_prefix],0 |
458 | ; mov [opcode_prefix],0 |
438 | ; mov [rex_prefix],0 |
459 | and dword [operand_size],0 |
- | |
460 | ; mov [rex_prefix],0 |
- | |
461 | ; mov [vex_required],0 |
439 | and dword [operand_size],0 |
- | 440 | ; mov [opcode_prefix],0 |
|
- | 441 | ; mov [vex_required],0 |
|
462 | ; mov [vex_register],0 |
442 | ; mov [vex_register],0 |
463 | ; mov [immediate_size],0 |
443 | ; mov [immediate_size],0 |
464 | and dword [rex_prefix],0 |
444 | and dword [opcode_prefix],0 |
465 | call instruction_handler |
445 | call instruction_handler |
466 | instruction_handler: |
446 | instruction_handler: |
467 | movzx ebx,word [esi] |
447 | movzx ebx,word [esi] |
468 | mov al,[esi+2] |
448 | mov al,[esi+2] |
469 | add esi,3 |
449 | add esi,3 |
470 | add [esp],ebx |
450 | add [esp],ebx |
471 | ret |
451 | ret |
472 | instruction_assembled: |
452 | instruction_assembled: |
473 | mov al,[esi] |
453 | test [prefix_flags],not 1 |
- | 454 | jnz illegal_instruction |
|
- | 455 | mov al,[esi] |
|
474 | cmp al,0Fh |
456 | cmp al,0Fh |
475 | je line_assembled |
457 | je line_assembled |
476 | or al,al |
458 | or al,al |
477 | jnz extra_characters_on_line |
459 | jnz extra_characters_on_line |
478 | line_assembled: |
460 | line_assembled: |
Line 669... | Line 651... | ||
669 | get_data_address: |
651 | get_data_address: |
670 | push ebx |
652 | push ebx |
671 | cmp byte [esi],'.' |
653 | cmp byte [esi],'.' |
672 | je invalid_value |
654 | je invalid_value |
673 | or [size_override],-1 |
655 | or [operand_flags],1 |
674 | call get_address_value |
656 | call get_address_value |
675 | pop ebp |
657 | pop ebp |
676 | call calculate_relative_offset |
658 | call calculate_relative_offset |
677 | cmp [next_pass_needed],0 |
659 | cmp [next_pass_needed],0 |
678 | jne data_address_type_ok |
660 | jne data_address_type_ok |
679 | cmp [value_type],0 |
661 | cmp [value_type],0 |
Line 716... | Line 698... | ||
716 | movzx eax,al |
698 | movzx eax,al |
717 | mov [operand_size],1 |
699 | mov [operand_size],1 |
718 | jmp store_value_ok |
700 | jmp store_value_ok |
719 | sized_store: |
701 | sized_store: |
720 | or [size_override],-1 |
702 | or [operand_flags],1 |
721 | call get_value |
703 | call get_value |
722 | store_value_ok: |
704 | store_value_ok: |
723 | cmp [value_type],0 |
705 | cmp [value_type],0 |
724 | jne invalid_use_of_symbol |
706 | jne invalid_use_of_symbol |
725 | mov dword [value],eax |
707 | mov dword [value],eax |
726 | mov dword [value+4],edx |
708 | mov dword [value+4],edx |
Line 831... | Line 813... | ||
831 | jc stack_overflow |
813 | jc stack_overflow |
832 | cmp eax,[stack_limit] |
814 | cmp eax,[stack_limit] |
833 | jb stack_overflow |
815 | jb stack_overflow |
834 | push esi |
816 | push esi |
835 | or [prefixed_instruction],-1 |
817 | or [prefix_flags],1 |
836 | call continue_line |
818 | call continue_line |
837 | mov eax,[counter_limit] |
819 | mov eax,[counter_limit] |
838 | cmp [counter],eax |
820 | cmp [counter],eax |
839 | je times_done |
821 | je times_done |
840 | inc [counter] |
822 | inc [counter] |
841 | pop esi |
823 | pop esi |
Line 1006... | Line 988... | ||
1006 | pop edx ecx edi esi |
988 | pop edx ecx edi esi |
1007 | addressing_space_closed: |
989 | addressing_space_closed: |
1008 | ret |
990 | ret |
1009 | repeat_directive: |
991 | repeat_directive: |
1010 | cmp [prefixed_instruction],0 |
992 | test [prefix_flags],1 |
1011 | jne unexpected_instruction |
993 | jnz unexpected_instruction |
1012 | lods byte [esi] |
994 | lods byte [esi] |
1013 | cmp al,'(' |
995 | cmp al,'(' |
1014 | jne invalid_argument |
996 | jne invalid_argument |
1015 | cmp byte [esi],'.' |
997 | cmp byte [esi],'.' |
1016 | je invalid_value |
998 | je invalid_value |
1017 | call get_count_value |
999 | call get_count_value |
Line 1028... | Line 1010... | ||
1028 | mov eax,[current_line] |
1010 | mov eax,[current_line] |
1029 | mov [ebx+4],eax |
1011 | mov [ebx+4],eax |
1030 | jmp instruction_assembled |
1012 | jmp instruction_assembled |
1031 | end_repeat: |
1013 | end_repeat: |
1032 | cmp [prefixed_instruction],0 |
1014 | test [prefix_flags],1 |
1033 | jne unexpected_instruction |
1015 | jnz unexpected_instruction |
1034 | call find_structure_data |
1016 | call find_structure_data |
1035 | jc unexpected_instruction |
1017 | jc unexpected_instruction |
1036 | mov eax,[counter_limit] |
1018 | mov eax,[counter_limit] |
1037 | inc [counter] |
1019 | inc [counter] |
1038 | cmp [counter],eax |
1020 | cmp [counter],eax |
1039 | jbe continue_repeating |
1021 | jbe continue_repeating |
Line 1060... | Line 1042... | ||
1060 | cmp ax,repeat_directive-instruction_handler |
1042 | cmp ax,repeat_directive-instruction_handler |
1061 | jne unexpected_instruction |
1043 | jne unexpected_instruction |
1062 | ret |
1044 | ret |
1063 | while_directive: |
1045 | while_directive: |
1064 | cmp [prefixed_instruction],0 |
1046 | test [prefix_flags],1 |
1065 | jne unexpected_instruction |
1047 | jnz unexpected_instruction |
1066 | call allocate_structure_data |
1048 | call allocate_structure_data |
1067 | mov word [ebx],while_directive-instruction_handler |
1049 | mov word [ebx],while_directive-instruction_handler |
1068 | mov eax,1 |
1050 | mov eax,1 |
1069 | xchg eax,[counter] |
1051 | xchg eax,[counter] |
1070 | mov [ebx+10h],eax |
1052 | mov [ebx+10h],eax |
1071 | mov [ebx+8],esi |
1053 | mov [ebx+8],esi |
Line 1091... | Line 1073... | ||
1091 | while_true: |
1073 | while_true: |
1092 | pop ebx |
1074 | pop ebx |
1093 | jmp instruction_assembled |
1075 | jmp instruction_assembled |
1094 | end_while: |
1076 | end_while: |
1095 | cmp [prefixed_instruction],0 |
1077 | test [prefix_flags],1 |
1096 | jne unexpected_instruction |
1078 | jnz unexpected_instruction |
1097 | call find_structure_data |
1079 | call find_structure_data |
1098 | jc unexpected_instruction |
1080 | jc unexpected_instruction |
1099 | mov eax,[ebx+4] |
1081 | mov eax,[ebx+4] |
1100 | mov [current_line],eax |
1082 | mov [current_line],eax |
1101 | inc [counter] |
1083 | inc [counter] |
1102 | jz too_many_repeats |
1084 | jz too_many_repeats |
Line 1107... | Line 1089... | ||
1107 | cmp ax,while_directive-instruction_handler |
1089 | cmp ax,while_directive-instruction_handler |
1108 | jne unexpected_instruction |
1090 | jne unexpected_instruction |
1109 | ret |
1091 | ret |
1110 | if_directive: |
1092 | if_directive: |
1111 | cmp [prefixed_instruction],0 |
1093 | test [prefix_flags],1 |
1112 | jne unexpected_instruction |
1094 | jnz unexpected_instruction |
1113 | call calculate_logical_expression |
1095 | call calculate_logical_expression |
1114 | mov dl,al |
1096 | mov dl,al |
1115 | mov al,[esi] |
1097 | mov al,[esi] |
1116 | or al,al |
1098 | or al,al |
1117 | jz missing_end_directive |
1099 | jz missing_end_directive |
1118 | cmp al,0Fh |
1100 | cmp al,0Fh |
Line 1144... | Line 1126... | ||
1144 | jne extra_characters_on_line |
1126 | jne extra_characters_on_line |
1145 | or al,-1 |
1127 | or al,-1 |
1146 | jmp make_if_structure |
1128 | jmp make_if_structure |
1147 | else_directive: |
1129 | else_directive: |
1148 | cmp [prefixed_instruction],0 |
1130 | test [prefix_flags],1 |
1149 | jne unexpected_instruction |
1131 | jnz unexpected_instruction |
1150 | mov ax,if_directive-instruction_handler |
1132 | mov ax,if_directive-instruction_handler |
1151 | call find_structure_data |
1133 | call find_structure_data |
1152 | jc unexpected_instruction |
1134 | jc unexpected_instruction |
1153 | cmp byte [ebx+2],0 |
1135 | cmp byte [ebx+2],0 |
1154 | jne unexpected_instruction |
1136 | jne unexpected_instruction |
1155 | found_else: |
1137 | found_else: |
Line 1171... | Line 1153... | ||
1171 | call find_end_if |
1153 | call find_end_if |
1172 | call remove_structure_data |
1154 | call remove_structure_data |
1173 | jmp instruction_assembled |
1155 | jmp instruction_assembled |
1174 | end_if: |
1156 | end_if: |
1175 | cmp [prefixed_instruction],0 |
1157 | test [prefix_flags],1 |
1176 | jne unexpected_instruction |
1158 | jnz unexpected_instruction |
1177 | call find_structure_data |
1159 | call find_structure_data |
1178 | jc unexpected_instruction |
1160 | jc unexpected_instruction |
1179 | call remove_structure_data |
1161 | call remove_structure_data |
1180 | jmp instruction_assembled |
1162 | jmp instruction_assembled |
1181 | find_else: |
1163 | find_else: |
1182 | call find_structure_end |
1164 | call find_structure_end |
Line 1375... | Line 1357... | ||
1375 | call get_count_value |
1357 | call get_count_value |
1376 | inc esi |
1358 | inc esi |
1377 | or eax,eax |
1359 | or eax,eax |
1378 | jz duplicate_zero_times |
1360 | jz duplicate_zero_times |
1379 | cmp byte [esi],'{' |
1361 | cmp byte [esi],91h |
1380 | jne duplicate_single_data_value |
1362 | jne duplicate_single_data_value |
1381 | inc esi |
1363 | inc esi |
1382 | duplicate_data: |
1364 | duplicate_data: |
1383 | push eax esi |
1365 | push eax esi |
1384 | duplicated_values: |
1366 | duplicated_values: |
1385 | cmp edi,[tagged_blocks] |
1367 | cmp edi,[tagged_blocks] |
Line 1387... | Line 1369... | ||
1387 | call near dword [esp+8] |
1369 | call near dword [esp+8] |
1388 | lods byte [esi] |
1370 | lods byte [esi] |
1389 | cmp al,',' |
1371 | cmp al,',' |
1390 | je duplicated_values |
1372 | je duplicated_values |
1391 | cmp al,'}' |
1373 | cmp al,92h |
1392 | jne invalid_argument |
1374 | jne invalid_argument |
1393 | pop ebx eax |
1375 | pop ebx eax |
1394 | dec eax |
1376 | dec eax |
1395 | jz data_defined |
1377 | jz data_defined |
1396 | mov esi,ebx |
1378 | mov esi,ebx |
1397 | jmp duplicate_data |
1379 | jmp duplicate_data |
Line 1405... | Line 1387... | ||
1405 | jz data_defined |
1387 | jz data_defined |
1406 | mov esi,ebx |
1388 | mov esi,ebx |
1407 | jmp duplicate_single_data_value |
1389 | jmp duplicate_single_data_value |
1408 | duplicate_zero_times: |
1390 | duplicate_zero_times: |
1409 | cmp byte [esi],'{' |
1391 | cmp byte [esi],91h |
1410 | jne skip_single_data_value |
1392 | jne skip_single_data_value |
1411 | inc esi |
1393 | inc esi |
1412 | skip_data_value: |
1394 | skip_data_value: |
1413 | call skip_symbol |
1395 | call skip_symbol |
1414 | jc invalid_argument |
1396 | jc invalid_argument |
1415 | cmp byte [esi],'}' |
1397 | cmp byte [esi],92h |
1416 | jne skip_data_value |
1398 | jne skip_data_value |
1417 | inc esi |
1399 | inc esi |
1418 | jmp data_defined |
1400 | jmp data_defined |
1419 | skip_single_data_value: |
1401 | skip_single_data_value: |
1420 | call skip_symbol |
1402 | call skip_symbol |
1421 | jmp data_defined |
1403 | jmp data_defined |