From 613ec371a5b5c5142ae4213d5209e75bb41e524c Mon Sep 17 00:00:00 2001 From: Tomasz Grysztar Date: Thu, 1 Jul 1999 21:38:14 +0200 Subject: [PATCH] unreleased version 1.00 --- SOURCE/ASSEMBLE.INC | 767 +++++++++++++++++++++++++++++++++++++++++--- SOURCE/ERRORS.INC | 8 + SOURCE/EXPRESSI.INC | 70 +++- SOURCE/FASM.ASM | 237 +++++++++++++- SOURCE/PREPROCE.INC | 68 +++- SOURCE/SYMBOLS.INC | 23 +- SOURCE/TABLES.INC | 23 ++ SYNTAX.ASM | 65 ++++ 8 files changed, 1200 insertions(+), 61 deletions(-) create mode 100644 SYNTAX.ASM diff --git a/SOURCE/ASSEMBLE.INC b/SOURCE/ASSEMBLE.INC index 73cbd5c..e1025df 100644 --- a/SOURCE/ASSEMBLE.INC +++ b/SOURCE/ASSEMBLE.INC @@ -17,6 +17,12 @@ assembler: mov [current_section],0 mov [current_line],0 mov [home_line],0 + mov eax,[relocations_memory] + mov [relocations_end],eax + mov eax,[exports_memory] + mov [exports_end],eax + mov eax,[import_relocations_memory] + mov [import_relocations_end],eax assemble_line: mov eax,[current_line] mov [current_line],esi @@ -38,6 +44,13 @@ assembler: call assemble_instruction jmp assemble_line pass_done: + cmp [virtual_mode],0 + je pass_ok + mov [virtual_mode],0 + mov eax,[stored_org] + mov [org_start],eax + mov edi,[stored_offset] + pass_ok: cmp [next_pass_needed],0 je assemble_done inc [current_pass] @@ -126,6 +139,7 @@ assemble_instruction: xor edx,edx call create_symbol mov byte [ebx+8],0 + mov byte [ebx+10],1 jmp find_instruction empty_label: inc [current_section] @@ -146,6 +160,8 @@ assemble_instruction: je constant_qword or al,al jnz invalid_operand_size + cmp [program_relocatable],0 + je constant_dword constant_qword: call get_qword_value pop ecx ebx @@ -154,10 +170,13 @@ assemble_instruction: jmp line_assembled constant_dword: call get_dword_value + mov [temp_byte],ch xor edx,edx pop ecx ebx call create_symbol mov byte [ebx+8],0 + mov ch,[temp_byte] + mov byte [ebx+10],ch jmp line_assembled constant_word: call get_word_value @@ -207,6 +226,7 @@ assemble_instruction: call create_symbol pop ebp eax mov byte [ebx+8],al + mov byte [ebx+10],1 jmp ebp line_assembled: lodsb @@ -226,13 +246,46 @@ assemble_instruction: org_directive: cmp [program_format],0 - jnz illegal_instruction + jnz instruction_not_allowed + set_org: call get_dword_value mov ecx,edi sub ecx,eax mov [org_start],ecx jmp line_assembled +virtual_directive: + push edi + mov edi,special_operators + call get_operator + pop edi + cmp al,1 + jne invalid_argument + cmp [virtual_mode],0 + jne set_org + mov [virtual_mode],-1 + mov eax,[org_start] + mov [stored_org],eax + mov [stored_offset],edi + jmp set_org + virtual_end: + cmp [virtual_mode],1 + je instruction_not_allowed + mov [virtual_mode],0 + mov eax,[stored_org] + mov [org_start],eax + mov edi,[stored_offset] + jmp line_assembled +end_directive: + push edi + mov edi,end_operators + call get_operator + pop edi + cmp al,1 + je virtual_end + jmp invalid_argument code_directive: + cmp [program_format],0 + jnz instruction_not_allowed push edi mov edi,code_types call get_operator @@ -249,12 +302,131 @@ code_directive: jmp line_assembled entry_directive: cmp [program_format],0 - jz illegal_instruction + jz instruction_not_allowed call get_dword_value mov [entry_point],eax mov al,[code_type] mov [entry_code_type],al jmp line_assembled +export_directive: + cmp [program_relocatable],0 + je instruction_not_allowed + find_export_start: + lodsb + cmp al,20h + je find_export_start + dec esi + push edi esi + find_export_end: + lodsb + mov edi,special_characters+1 + movzx ecx,[special_characters] + repne scasb + jne find_export_end + dec esi + mov ecx,esi + mov esi,[esp] + sub ecx,esi + push ecx + call get_symbol + pop edx ebx + push esi + mov esi,ebx + or cl,cl + jz invalid_value + cmp cl,3 + je export_symbol_defined + mov [next_pass_needed],1 + jmp export_symbol_ok + export_symbol_defined: + cmp ch,1 + jne invalid_value + export_symbol_ok: + mov edi,[exports_end] + mov ecx,edx + lea edx,[edi+ecx+1+4] + cmp edx,[exports_memory_end] + jae out_of_memory + rep movsb + mov byte [edi],0 + inc edi + stosd + mov [exports_end],edi + pop esi edi + jmp line_assembled +import_directive: + cmp [program_format],0 + je instruction_not_allowed + cmp [current_pass],0 + ja skip_line + push edi + find_import_start: + lodsb + cmp al,20h + je find_import_start + dec esi + push esi + find_import_end: + lodsb + mov edi,special_characters+1 + movzx ecx,[special_characters] + repne scasb + jne find_import_end + dec esi + mov ecx,esi + sub ecx,[esp] + push ecx + mov edi,size_operators + call get_operator + mov [operand_size],al + mov edi,special_operators + call get_operator + cmp al,2 + jne invalid_argument + find_DLL_name: + lodsb + cmp al,20h + je find_DLL_name + cmp al,27h + jne invalid_argument + mov edi,[imports_end] + get_DLL_name: + lodsb + stosb + or al,al + jz missing_end_quote + cmp al,27h + jne get_DLL_name + lodsb + cmp al,27h + je get_DLL_name + dec esi + mov byte [edi-1],0 + pop ecx ebx + push esi + mov edx,ecx + mov esi,ebx + rep movsb + xor al,al + stosb + mov [imports_end],edi + mov ecx,edx + mov esi,ebx + mov eax,[import_number] + xor edx,edx + call create_symbol + mov al,[operand_size] + mov byte [ebx+8],al + mov byte [ebx+10],2 + inc [import_number] + pop esi edi + jmp line_assembled + skip_line: + lodsb + or al,al + jnz skip_line + dec esi + jmp line_assembled label_directive: lodsb cmp al,20h @@ -296,9 +468,18 @@ label_directive: call create_symbol mov al,byte [value] mov byte [ebx+8],al + cmp [program_relocatable],0 + je line_assembled + cmp al,[value_type] + mov byte [ebx+10],al + or al,al + jnz line_assembled + mov byte [ebx+10],1 jmp line_assembled times_directive: call get_dword_value + or ch,ch + jnz invalid_use_of_symbol cmp eax,0 jz find_end_of_line jl invalid_value @@ -326,9 +507,18 @@ data_bytes: je data_bytes cmp al,27h je data_string + cmp al,'?' + jne get_byte + mov eax,edi + mov byte [edi],0 + inc edi + call undefined_data + jmp byte_ok + get_byte: dec esi call get_byte_value stosb + byte_ok: cmp edi,[symbols_list] jae out_of_memory find_next_data_byte: @@ -359,9 +549,29 @@ data_bytes: je store_string_byte dec esi ret + undefined_data: + cmp eax,[undefined_data_end] + je mark_undefined_data + mov [undefined_data_start],eax + mark_undefined_data: + mov [undefined_data_end],edi + ret data_words: + lodsb + cmp al,20h + je data_words + cmp al,'?' + jne get_word + mov eax,edi + mov word [edi],0 + add edi,2 + call undefined_data + jmp word_ok + get_word: + dec esi call get_word_value stosw + word_ok: cmp edi,[symbols_list] jae out_of_memory find_next_data_word: @@ -373,8 +583,31 @@ data_words: dec esi jmp line_assembled data_dwords: + lodsb + cmp al,20h + je data_dwords + cmp al,'?' + jne get_dword + mov eax,edi + mov dword [edi],0 + add edi,4 + call undefined_data + jmp dword_ok + get_dword: + dec esi call get_dword_value + or ch,ch + jz store_data_dword + cmp ch,2 + je data_imported_value + call mark_relocation + jmp store_data_dword + data_imported_value: + call mark_import_relocation + call mark_relocation + store_data_dword: stosd + dword_ok: cmp edi,[symbols_list] jae out_of_memory find_next_data_dword: @@ -386,10 +619,24 @@ data_dwords: dec esi jmp line_assembled data_pwords: + lodsb + cmp al,20h + je data_pwords + cmp al,'?' + jne get_pword + mov eax,edi + mov dword [edi],0 + mov word [edi+4],0 + add edi,6 + call undefined_data + jmp pword_ok + get_pword: + dec esi call get_pword_value stosd mov eax,edx stosw + pword_ok: cmp edi,[symbols_list] jae out_of_memory find_next_data_pword: @@ -401,10 +648,24 @@ data_pwords: dec esi jmp line_assembled data_qwords: + lodsb + cmp al,20h + je data_qwords + cmp al,'?' + jne get_qword + mov eax,edi + mov dword [edi],0 + mov dword [edi+4],0 + add edi,8 + call undefined_data + jmp qword_ok + get_qword: + dec esi call get_qword_value stosd mov eax,edx stosd + qword_ok: cmp edi,[symbols_list] jae out_of_memory find_next_data_qword: @@ -458,6 +719,8 @@ data_file: reserve_bytes: push edi call get_dword_value + or ch,ch + jnz invalid_use_of_symbol mov ecx,eax mov edx,ecx add edx,edi @@ -466,17 +729,15 @@ reserve_bytes: jae out_of_memory xor al,al rep stosb - undefined_data: + reserved_data: pop eax - cmp eax,[undefined_data_end] - je mark_undefined_data - mov [undefined_data_start],eax - mark_undefined_data: - mov [undefined_data_end],edi + call undefined_data jmp line_assembled reserve_words: push edi call get_dword_value + or ch,ch + jnz invalid_use_of_symbol mov ecx,eax mov edx,ecx shl edx,1 @@ -487,10 +748,12 @@ reserve_words: jae out_of_memory xor eax,eax rep stosw - jmp undefined_data + jmp reserved_data reserve_dwords: push edi call get_dword_value + or ch,ch + jnz invalid_use_of_symbol mov ecx,eax mov edx,ecx shl edx,1 @@ -503,10 +766,12 @@ reserve_dwords: jae out_of_memory xor eax,eax rep stosd - jmp undefined_data + jmp reserved_data reserve_pwords: push edi call get_dword_value + or ch,ch + jnz invalid_use_of_symbol mov ecx,eax shl ecx,1 jc out_of_memory @@ -520,10 +785,12 @@ reserve_pwords: jae out_of_memory xor eax,eax rep stosw - jmp undefined_data + jmp reserved_data reserve_qwords: push edi call get_dword_value + or ch,ch + jnz invalid_use_of_symbol mov ecx,eax shl ecx,1 jc out_of_memory @@ -538,7 +805,7 @@ reserve_qwords: jae out_of_memory xor eax,eax rep stosd - jmp undefined_data + jmp reserved_data simple_instruction: stosb @@ -670,13 +937,18 @@ basic_instruction: stosb jmp line_assembled basic_mem_imm_32bit: + push [import_value] call get_dword_value + mov ebp,[import_value] + pop [import_value] mov dword [value],eax mov al,[base_code] shr al,3 mov [postbyte_register],al call operand_32bit_prefix pop ecx ebx edx + cmp [value_type],0 + jne basic_mem_imm_relocation cmp dword [value],80h jb basic_mem_simm_8bit cmp dword [value],-80h @@ -686,6 +958,21 @@ basic_instruction: mov eax,dword [value] stosd jmp line_assembled + basic_mem_imm_relocation: + mov [base_code],81h + call store_instruction + mov eax,dword [value] + cmp [value_type],2 + je basic_mem_imported + call mark_relocation + stosd + jmp line_assembled + basic_mem_imported: + mov [import_value],ebp + call mark_import_relocation + call mark_relocation + stosd + jmp line_assembled basic_reg: push edi mov edi,general_registers @@ -858,6 +1145,8 @@ basic_instruction: mov bl,[postbyte_register] and bl,111b or ah,bl + or ch,ch + jnz basic_reg_imm_relocation cmp edx,80h jb basic_reg_simm_8bit cmp edx,-80h @@ -869,6 +1158,22 @@ basic_instruction: mov eax,edx stosd jmp line_assembled + basic_reg_imm_relocation: + or bl,bl + jz basic_eax_imm_relocation + mov al,81h + stosw + mov eax,edx + cmp ch,2 + je basic_reg_imported + call mark_relocation + stosd + jmp line_assembled + basic_reg_imported: + call mark_import_relocation + call mark_relocation + stosd + jmp line_assembled basic_eax_imm: mov al,[base_code] add al,5 @@ -876,6 +1181,21 @@ basic_instruction: mov eax,edx stosd jmp line_assembled + basic_eax_imm_relocation: + mov al,[base_code] + add al,5 + stosb + mov eax,edx + cmp ch,2 + je basic_eax_imported + call mark_relocation + stosd + jmp line_assembled + basic_eax_imported: + call mark_import_relocation + call mark_relocation + stosd + jmp line_assembled single_operand_instruction: mov [base_code],0F6h mov [postbyte_register],al @@ -1114,6 +1434,8 @@ imul_instruction: jmp line_assembled imul_reg_mem_imm_32bit: call get_dword_value + or ch,ch + jnz invalid_use_of_symbol mov dword [value],eax pop ecx ebx edx mov [base_code],69h @@ -1243,6 +1565,8 @@ imul_instruction: jmp line_assembled imul_reg_reg_imm_32bit: call get_dword_value + or ch,ch + jnz invalid_use_of_symbol mov dword [value],eax pop ebx edx call operand_32bit_prefix @@ -1256,6 +1580,35 @@ imul_instruction: mov eax,dword [value] stosd jmp line_assembled +aa_instruction: + push eax + push edi + mov edi,size_operators + call get_operator + pop edi + or al,al + jnz aa_imm8 + aa_find_operand: + lodsb + cmp al,20h + je aa_find_operand + dec esi + mov bl,10 + or al,al + jz aa_store + cmp al,3Bh + je aa_store + mov al,1 + aa_imm8: + cmp al,1 + ja invalid_operand_size + call get_byte_value + mov bl,al + aa_store: + pop eax + mov ah,bl + stosw + jmp line_assembled int_instruction: push edi mov edi,size_operators @@ -1355,6 +1708,8 @@ push_instruction: push_imm_optimized_32bit: call get_dword_value mov edx,eax + or ch,ch + jnz push_imm_32bit_relocation cmp eax,100h jb push_imm_8bit mov al,68h @@ -1362,6 +1717,20 @@ push_instruction: mov eax,edx stosd jmp push_done + push_imm_32bit_relocation: + mov al,68h + stosb + mov eax,edx + cmp ch,2 + je push_imported + call mark_relocation + stosd + jmp push_done + push_imported: + call mark_import_relocation + call mark_relocation + stosd + jmp push_done push_imm_optimized_16bit: call get_word_value cmp eax,100h @@ -1390,6 +1759,8 @@ push_instruction: call get_dword_value mov edx,eax call operand_32bit_prefix + or ch,ch + jnz push_imm_32bit_relocation mov al,68h stosb mov eax,edx @@ -1644,6 +2015,8 @@ conditional_jump: sub eax,[current_offset] add eax,[org_start] sub eax,2 + cmp ch,2 + je conditional_jump_imported cmp bl,1 je conditional_jump_8bit cmp bl,2 @@ -1652,23 +2025,25 @@ conditional_jump: je conditional_jump_32bit or bl,bl jnz invalid_operand_size - cmp eax,8000h - jge conditional_jump_32bit - cmp eax,-8000h - jl conditional_jump_32bit cmp eax,80h - jge conditional_jump_16bit + jb conditional_jump_8bit cmp eax,-80h - jl conditional_jump_16bit - conditional_jump_8bit: + jae conditional_jump_8bit + cmp [code_type],16 + je conditional_jump_16bit + conditional_jump_32bit: + sub eax,4 mov edx,eax - mov ah,al - mov al,[base_code] + mov ecx,edi + call operand_32bit_prefix + sub edx,edi + add edx,ecx + mov ah,[base_code] + add ah,10h + mov al,0Fh stosw - cmp edx,80h - jge jump_out_of_range - cmp edx,-80h - jl jump_out_of_range + mov eax,edx + stosd jmp line_assembled conditional_jump_16bit: sub eax,2 @@ -1688,7 +2063,31 @@ conditional_jump: cmp eax,-8000h jl jump_out_of_range jmp line_assembled - conditional_jump_32bit: + conditional_jump_8bit: + mov edx,eax + mov ah,al + mov al,[base_code] + stosw + cmp edx,80h + jge jump_out_of_range + cmp edx,-80h + jl jump_out_of_range + jmp line_assembled + jump_out_of_range: + cmp [error_line],0 + jne line_assembled + mov eax,[current_line] + mov [error_line],eax + mov eax,[home_line] + mov [error_home_line],eax + mov [error],relative_jump_out_of_range + jmp line_assembled + conditional_jump_imported: + or bl,bl + jz conditional_jump_imported_32bit + cmp bl,4 + jne invalid_use_of_symbol + conditional_jump_imported_32bit: sub eax,4 mov edx,eax mov ecx,edi @@ -1700,17 +2099,9 @@ conditional_jump: mov al,0Fh stosw mov eax,edx + call mark_import_relocation stosd jmp line_assembled - jump_out_of_range: - cmp [error_line],0 - jne line_assembled - mov eax,[current_line] - mov [error_line],eax - mov eax,[home_line] - mov [error_home_line],eax - mov [error],relative_jump_out_of_range - jmp line_assembled jcxz_instruction: mov [base_code],al push edi @@ -1724,6 +2115,8 @@ jcxz_instruction: cmp [jump_type],2 je invalid_operand call get_dword_value + cmp ch,2 + je invalid_use_of_symbol sub eax,[current_offset] add eax,[org_start] mov bl,[operand_size] @@ -1760,6 +2153,8 @@ jecxz_instruction: cmp [jump_type],2 je invalid_operand call get_dword_value + cmp ch,2 + je invalid_use_of_symbol sub eax,[current_offset] add eax,[org_start] mov bl,[operand_size] @@ -1805,6 +2200,8 @@ loop_instruction: cmp [jump_type],2 je invalid_operand call get_dword_value + cmp ch,2 + je invalid_use_of_symbol sub eax,[current_offset] add eax,[org_start] mov bl,[operand_size] @@ -1940,11 +2337,15 @@ call_instruction: push edi mov edi,size_operators call get_operator - mov [operand_size],al pop edi push esi + push eax call get_dword_value pop ebx + mov [operand_size],bl + pop ebx + cmp ch,2 + je call_imported cmp byte [esi],':' je call_far cmp [jump_type],2 @@ -2037,6 +2438,30 @@ call_instruction: mov eax,edx stosw jmp line_assembled + call_imported: + cmp byte [esi],':' + je invalid_use_of_symbol + cmp [jump_type],2 + je invalid_operand + cmp [operand_size],0 + je call_imported_32bit + cmp [operand_size],4 + jne invalid_use_of_symbol + call_imported_32bit: + sub eax,[current_offset] + add eax,[org_start] + sub eax,5 + mov edx,eax + mov ecx,edi + call operand_32bit_prefix + sub edx,edi + add edx,ecx + mov al,0E8h + stosb + mov eax,edx + call mark_import_relocation + stosd + jmp line_assembled jmp_instruction: push edi mov edi,jump_operators @@ -2153,11 +2578,15 @@ jmp_instruction: push edi mov edi,size_operators call get_operator - mov [operand_size],al pop edi push esi + push eax call get_dword_value pop ebx + mov [operand_size],bl + pop ebx + cmp ch,2 + je jmp_imported cmp byte [esi],':' je jmp_far cmp [jump_type],2 @@ -2266,6 +2695,30 @@ jmp_instruction: mov eax,edx stosw jmp line_assembled + jmp_imported: + cmp byte [esi],':' + je invalid_use_of_symbol + cmp [jump_type],2 + je invalid_operand + cmp [operand_size],0 + je jmp_imported_32bit + cmp [operand_size],4 + jne invalid_use_of_symbol + jmp_imported_32bit: + sub eax,[current_offset] + add eax,[org_start] + sub eax,5 + mov edx,eax + mov ecx,edi + call operand_32bit_prefix + sub edx,edi + add edx,ecx + mov al,0E9h + stosb + mov eax,edx + call mark_import_relocation + stosd + jmp line_assembled ret_instruction: lodsb cmp al,20h @@ -2416,7 +2869,10 @@ test_instruction: stosw jmp line_assembled test_mem_imm_32bit: + push [import_value] call get_dword_value + mov ebp,[import_value] + pop [import_value] mov dword [value],eax mov [postbyte_register],0 mov [base_code],0F7h @@ -2424,6 +2880,20 @@ test_instruction: pop ecx ebx edx call store_instruction mov eax,dword [value] + cmp [value_type],2 + je test_mem_imported + cmp [value_type],0 + jnz test_mem_imm_32bit_relocation + stosd + jmp line_assembled + test_mem_imm_32bit_relocation: + call mark_relocation + stosd + jmp line_assembled + test_mem_imported: + mov [import_value],ebp + call mark_import_relocation + call mark_relocation stosd jmp line_assembled test_reg: @@ -2547,6 +3017,8 @@ test_instruction: mov ah,11000000b mov bl,[postbyte_register] and bl,111b + or ch,ch + jnz test_reg_imm_32bit_relocation or bl,bl jz test_eax_imm or ah,bl @@ -2555,12 +3027,43 @@ test_instruction: mov eax,edx stosd jmp line_assembled + test_reg_imm_32bit_relocation: + or bl,bl + jz test_eax_imm_relocation + or ah,bl + mov al,0F7h + stosw + mov eax,edx + cmp ch,2 + je test_reg_imported + call mark_relocation + stosd + jmp line_assembled + test_reg_imported: + call mark_import_relocation + call mark_relocation + stosd + jmp line_assembled test_eax_imm: mov al,0A9h stosb mov eax,edx stosd jmp line_assembled + test_eax_imm_relocation: + mov al,0A9h + stosb + mov eax,edx + cmp ch,2 + je test_eax_imported + call mark_relocation + stosd + jmp line_assembled + test_eax_imported: + call mark_import_relocation + call mark_relocation + stosd + jmp line_assembled xchg_instruction: mov [base_code],86h call get_memory_address @@ -2732,6 +3235,8 @@ mov_instruction: call store_instruction jmp line_assembled mov_mem_al: + or ch,ch + jnz mov_mem_al_relocation cmp edx,8000h jb mov_mem_address16_al cmp edx,-8000h @@ -2743,6 +3248,22 @@ mov_instruction: mov eax,edx stosd jmp line_assembled + mov_mem_al_relocation: + call address_32bit_prefix + call store_segment_prefix + mov al,0A2h + stosb + mov eax,edx + cmp ch,2 + je mov_mem_al_imported + call mark_relocation + stosd + jmp line_assembled + mov_mem_al_imported: + call mark_import_relocation + call mark_relocation + stosd + jmp line_assembled mov_mem_address16_al: call address_16bit_prefix call store_segment_prefix @@ -2761,6 +3282,8 @@ mov_instruction: jmp line_assembled mov_mem_ax: call operand_16bit_prefix + or ch,ch + jnz mov_mem_ax_relocation cmp edx,8000h jb mov_mem_address16_ax cmp edx,-8000h @@ -2772,6 +3295,22 @@ mov_instruction: mov eax,edx stosd jmp line_assembled + mov_mem_ax_relocation: + call address_32bit_prefix + call store_segment_prefix + mov al,0A3h + stosb + mov eax,edx + cmp ch,2 + je mov_mem_ax_imported + call mark_relocation + stosd + jmp line_assembled + mov_mem_ax_imported: + call mark_import_relocation + call mark_relocation + stosd + jmp line_assembled mov_mem_address16_ax: call address_16bit_prefix call store_segment_prefix @@ -2790,6 +3329,8 @@ mov_instruction: jmp line_assembled mov_mem_eax: call operand_32bit_prefix + or ch,ch + jnz mov_mem_ax_relocation cmp edx,8000h jb mov_mem_address16_eax cmp edx,-8000h @@ -2876,7 +3417,10 @@ mov_instruction: stosw jmp line_assembled mov_mem_imm_32bit: + push [import_value] call get_dword_value + mov ebp,[import_value] + pop [import_value] mov dword [value],eax mov [postbyte_register],0 mov [base_code],0C7h @@ -2884,6 +3428,18 @@ mov_instruction: pop ecx ebx edx call store_instruction mov eax,dword [value] + cmp [value_type],0 + je mov_mem_imm_32bit_store + cmp ch,2 + je mov_mem_imported + call mark_relocation + mov_mem_imm_32bit_store: + stosd + jmp line_assembled + mov_mem_imported: + mov [import_value],ebp + call mark_import_relocation + call mark_relocation stosd jmp line_assembled mov_reg: @@ -3083,6 +3639,17 @@ mov_instruction: add al,0B8h stosb mov eax,edx + or ch,ch + jz mov_reg_imm_32bit_store + cmp ch,2 + je mov_reg_imported + call mark_relocation + mov_reg_imm_32bit_store: + stosd + jmp line_assembled + mov_reg_imported: + call mark_import_relocation + call mark_relocation stosd jmp line_assembled mov_sreg: @@ -3875,6 +4442,30 @@ lods_instruction: cmp [operand_size],0 je operand_size_not_specified jmp invalid_operand_size +xlat_instruction: + call get_memory_address + jc xlatb_instruction + or eax,eax + jnz invalid_address + or bl,bl + jnz invalid_address + cmp bh,23h + je xlat_16bit + cmp bh,43h + jne invalid_address + call address_32bit_prefix + jmp xlat_store + xlat_16bit: + call address_16bit_prefix + xlat_store: + call store_segment_prefix + mov al,D7h + cmp [operand_size],1 + jbe simple_instruction + jmp invalid_operand_size + xlatb_instruction: + mov al,D7h + jmp simple_instruction ins_instruction: call get_memory_address jc invalid_operand @@ -5174,13 +5765,16 @@ store_instruction: address_bp: mov al,110b postbyte_16bit: + or ch,ch + jnz invalid_use_of_symbol or edx,edx jz address cmp edx,128 jb address_8bit_value cmp edx,-128 jae address_8bit_value - cmp edx,-32768 + address_16bit_value: + cmp edx,-8000h jl value_out_of_range or al,10000000b mov cl,[postbyte_register] @@ -5238,6 +5832,8 @@ store_instruction: or ah,bl and bh,111b or ah,bh + or ch,ch + jnz sib_address_32bit_value cmp bh,5 je address_value or edx,edx @@ -5247,11 +5843,22 @@ store_instruction: jb sib_address_8bit_value cmp edx,-128 jae sib_address_8bit_value + sib_address_32bit_value: or al,10000000b mov cl,[postbyte_register] shl cl,3 or al,cl stosw + or ch,ch + jz store_sib_address_32bit_value + cmp ch,2 + je sib_address_imported_value + call mark_relocation + jmp store_sib_address_32bit_value + sib_address_imported_value: + call mark_import_relocation + call mark_relocation + store_sib_address_32bit_value: mov eax,edx stosd ret @@ -5279,6 +5886,16 @@ store_instruction: shl cl,3 or al,cl stosw + or ch,ch + jz store_address_32bit_value + cmp ch,2 + je address_imported_value + call mark_relocation + jmp store_address_32bit_value + address_imported_value: + call mark_import_relocation + call mark_relocation + store_address_32bit_value: mov eax,edx stosd ret @@ -5291,17 +5908,30 @@ store_instruction: and al,111b cmp al,4 je zero_index_register + or ch,ch + jnz simple_address_32bit_value or edx,edx jz simple_address cmp edx,80h jb simple_address_8bit_value cmp edx,-80h jae simple_address_8bit_value + simple_address_32bit_value: or al,10000000b mov cl,[postbyte_register] shl cl,3 or al,cl stosb + or ch,ch + jz store_simple_address_32bit_value + cmp ch,2 + je simple_address_imported_value + call mark_relocation + jmp store_simple_address_32bit_value + simple_address_imported_value: + call mark_import_relocation + call mark_relocation + store_simple_address_32bit_value: mov eax,edx stosd ret @@ -5323,10 +5953,13 @@ store_instruction: stosb ret address_immediate: - cmp edx,8000h + cmp [code_type],16 + je addressing_16bit + or ch,ch + jnz address_immediate_32bit + cmp edx,10000h jb address_immediate_16bit - cmp edx,-8000h - jae address_immediate_16bit + address_immediate_32bit: call address_32bit_prefix call store_instruction_code mov al,101b @@ -5334,9 +5967,27 @@ store_instruction: shl cl,3 or al,cl stosb + or ch,ch + jz store_32bit_address + cmp ch,2 + je address_32bit_imported_value + call mark_relocation + jmp store_32bit_address + address_32bit_imported_value: + call mark_import_relocation + call mark_relocation + store_32bit_address: mov eax,edx stosd ret + addressing_16bit: + or ch,ch + jnz invalid_use_of_symbol + cmp edx,10000h + jge address_immediate_32bit + cmp edx,-8000h + jl address_immediate_32bit + movzx edx,dx address_immediate_16bit: call address_16bit_prefix call store_instruction_code @@ -5370,12 +6021,43 @@ store_instruction: stosb instruction_prefix_ok: ret +mark_relocation: + push eax ebx + mov eax,edi + sub eax,[org_start] + mov ebx,[relocations_end] + mov [ebx],eax + add ebx,4 + cmp ebx,[relocations_memory_end] + jae out_of_memory + mov [relocations_end],ebx + pop ebx eax + ret +mark_import_relocation: + push eax ebx + mov eax,edi + sub eax,[org_start] + mov ebx,[import_relocations_end] + mov [ebx],eax + add ebx,4 + mov eax,[import_value] + mov [ebx],eax + add ebx,4 + cmp ebx,[import_relocations_memory_end] + jae out_of_memory + mov [import_relocations_end],ebx + pop ebx eax + ret default_code_type db 16 code_type db 0 org_start dd 0 +virtual_mode db 0 +stored_org dd 0 +stored_offset dd 0 entry_point dd 0 entry_code_type db 0 +program_relocatable db 0 current_pass db 0 current_line dd 0 @@ -5396,3 +6078,6 @@ extended_code db 0 jump_type db 0 undefined_data_start dd 0 undefined_data_end dd 0 +import_number dd 0 +label temp_byte byte +temp_dword dd 0 diff --git a/SOURCE/ERRORS.INC b/SOURCE/ERRORS.INC index c9e0a0e..cefc2ba 100644 --- a/SOURCE/ERRORS.INC +++ b/SOURCE/ERRORS.INC @@ -26,6 +26,9 @@ invalid_argument: illegal_instruction: mov edi,_illegal_instruction jmp assembler_error +instruction_not_allowed: + mov edi,_instruction_not_allowed + jmp assembler_error invalid_operand: mov edi,_invalid_operand jmp assembler_error @@ -50,6 +53,9 @@ invalid_address: invalid_value: mov edi,_invalid_value jmp assembler_error +invalid_use_of_symbol: + mov edi,_invalid_use_of_symbol + jmp assembler_error value_out_of_range: mov edi,_value_out_of_range jmp assembler_error @@ -183,6 +189,7 @@ _invalid_macro_arguments db 'invalid macro arguments',0 _unexpected_characters db 'unexpected characters',0 _invalid_argument db 'invalid argument',0 _illegal_instruction db 'illegal instruction',0 +_instruction_not_allowed db 'instruction not allowed',0 _invalid_operand db 'invalid operand',0 _invalid_operand_size db 'invalid size of operand',0 _operand_size_not_specified db 'operand size not specified',0 @@ -191,6 +198,7 @@ _address_sizes_do_not_agree db 'address sizes do not agree',0 _invalid_expression db 'invalid expression',0 _invalid_address db 'invalid address',0 _invalid_value db 'invalid value',0 +_invalid_use_of_symbol db 'invalid use of symbol',0 _value_out_of_range db 'value out of range',0 _relative_jump_out_of_range db 'relative jump out of range',0 _extra_characters_on_line db 'extra characters on line',0 diff --git a/SOURCE/EXPRESSI.INC b/SOURCE/EXPRESSI.INC index cf997b8..603261d 100644 --- a/SOURCE/EXPRESSI.INC +++ b/SOURCE/EXPRESSI.INC @@ -5,6 +5,8 @@ get_byte_value: mov [expression_start],esi call get_expression jc invalid_value + cmp byte [edi+26],0 + jne invalid_use_of_symbol cmp word [edi+24],0 jne invalid_value mov eax,[edi] @@ -27,6 +29,8 @@ get_word_value: mov [expression_start],esi call get_expression jc invalid_value + cmp byte [edi+26],0 + jne invalid_use_of_symbol cmp word [edi+24],0 jne invalid_value check_word_value: @@ -53,6 +57,8 @@ get_dword_value: jc invalid_value cmp word [edi+24],0 jne invalid_value + mov ch,byte [edi+26] + mov [value_type],ch check_dword_value: mov eax,[edi] cmp dword [edi+4],0 @@ -71,6 +77,8 @@ get_pword_value: mov [expression_start],esi call get_expression jc invalid_value + cmp byte [edi+26],0 + jne invalid_use_of_symbol cmp word [edi+24],0 jne invalid_value mov eax,[edi] @@ -87,6 +95,8 @@ get_qword_value: mov [expression_start],esi call get_expression jc invalid_value + cmp byte [edi+26],0 + jne invalid_use_of_symbol cmp word [edi+24],0 jne invalid_value mov eax,[edi] @@ -125,7 +135,8 @@ get_memory_address: cmp al,']' jne invalid_address xor bx,bx - xor cl,cl + xor cx,cx + mov ch,byte [edi+26] cmp word [edi+24],0 je check_dword_value mov al,[edi+24] @@ -199,11 +210,10 @@ get_memory_address: or bl,bl jnz address_register_error mov bl,al - mov ecx,[edx] - cmp ecx,255 + mov cl,[edx] + cmp dword [edx],255 ja address_register_error - clc - ret + jmp address_register_ok address_register_error: add esp,4 jmp bad_expression @@ -227,16 +237,19 @@ get_memory_address: value_positive: mov al,10h stosb + mov byte [edi+26],0 jmp get_value value_negative: mov al,11h stosb + mov byte [edi+26],0 jmp get_value value_start: lodsb cmp al,20h je value_start dec esi + mov byte [edi+26],0 mov ebp,edi mov edi,single_operand_operators call get_operator @@ -291,6 +304,7 @@ get_memory_address: store_symbol_value: mov dword [ds:ebp],eax mov dword [ds:ebp+4],edx + mov byte [ds:ebp+26],ch value_operator: mov edi,operators call get_operator @@ -343,6 +357,11 @@ get_memory_address: je calculate_shr jmp calculate_done calculate_add: + mov al,[esi+26] + and al,[edi+26] + jnz invalid_use_of_symbol + mov al,[edi+26] + or [esi+26],al mov eax,[edi] add [esi],eax mov eax,[edi+4] @@ -396,6 +415,19 @@ get_memory_address: add esp,4 jmp calculate_error calculate_sub: + mov al,[esi+26] + or al,[edi+26] + jz sub_allowed + cmp al,1 + jne invalid_use_of_symbol + mov al,[esi+26] + and al,[esi+26] + cmp al,1 + jne invalid_use_of_symbol + xor al,al + mov [esi+26],al + mov [edi+26],al + sub_allowed: mov eax,[edi] sub [esi],eax mov eax,[edi+4] @@ -416,6 +448,9 @@ get_memory_address: adc dword [ebx+4],0 jmp add_register_start calculate_mul: + mov al,[esi+26] + or al,[edi+26] + jnz invalid_use_of_symbol cmp word [esi+24],0 jne mul_start mov eax,[esi] @@ -511,6 +546,9 @@ get_memory_address: stc ret calculate_div: + mov al,[esi+26] + or al,[edi+26] + jnz invalid_use_of_symbol call div_64 cmp word [edi+24],0 jne calculate_error @@ -597,23 +635,35 @@ get_memory_address: div_ok: ret calculate_mod: + mov al,[esi+26] + or al,[edi+26] + jnz invalid_use_of_symbol call div_64 mov [esi],eax mov [esi+4],edx jmp calculate_done calculate_and: + mov al,[esi+26] + or al,[edi+26] + jnz invalid_use_of_symbol mov eax,[edi] and [esi],eax mov eax,[edi+4] and [esi+4],eax jmp calculate_done calculate_or: + mov al,[esi+26] + or al,[edi+26] + jnz invalid_use_of_symbol mov eax,[edi] or [esi],eax mov eax,[edi+4] or [esi+4],eax jmp calculate_done calculate_xor: + mov al,[esi+26] + or al,[edi+26] + jnz invalid_use_of_symbol cmp [value_size],1 je xor_byte cmp [value_size],2 @@ -661,6 +711,8 @@ get_memory_address: xor [esi+4],ax jmp calculate_done calculate_not: + cmp byte [esi+26],0 + jnz invalid_use_of_symbol mov dword [esi],0 mov dword [esi+4],0 cmp [value_size],1 @@ -717,6 +769,9 @@ get_memory_address: mov [esi+4],ax jmp calculate_done calculate_shl: + mov al,[esi+26] + or al,[edi+26] + jnz invalid_use_of_symbol mov eax,dword [edi+4] test eax,1 shl 31 jnz shl_negative @@ -747,6 +802,9 @@ get_memory_address: add dword [edi],1 adc dword [edi+4],0 calculate_shr: + mov al,[esi+26] + or al,[edi+26] + jnz invalid_use_of_symbol mov eax,dword [edi+4] test eax,1 shl 31 jnz shr_negative @@ -982,3 +1040,5 @@ expression_start dd 0 number_start dd 0 value_size db 0 value dd 0 +value_type db 0 +import_value dd 0 diff --git a/SOURCE/FASM.ASM b/SOURCE/FASM.ASM index 7341478..29071b7 100644 --- a/SOURCE/FASM.ASM +++ b/SOURCE/FASM.ASM @@ -3,9 +3,9 @@ ; by privalov ; started at: 1999-03-23 14:24:33 ; version 0.90 finished at: 1999-05-04 15:23:26 +; version 1.00 finished at: 1999-07-01 21:38:14 HF -code 32 entry start include 'tables.inc' @@ -16,7 +16,6 @@ include 'preprocessor.inc' include 'assembler.inc' start: - call get_params cmp [params],0 je information @@ -35,6 +34,31 @@ start: jc allocation_error mov [additional_memory],edx add [additional_memory_end],edx + mov ax,4811h + mov edx,8000h + mov [relocations_memory_end],edx + int 31h + mov [relocations_memory],edx + add [relocations_memory_end],edx + mov ax,4811h + mov edx,8000h + mov [exports_memory_end],edx + int 31h + mov [exports_memory],edx + add [exports_memory_end],edx + mov ax,4811h + mov edx,10000h + mov [imports_memory_end],edx + int 31h + mov [imports_memory],edx + mov [imports_end],edx + add [imports_memory_end],edx + mov ax,4811h + mov edx,10000h + mov [import_relocations_memory_end],edx + int 31h + mov [import_relocations_memory],edx + add [import_relocations_memory_end],edx mov ax,4810h int 31h sub edx,4000h @@ -66,10 +90,10 @@ start: je save_HF_program jmp save_raw_code save_HF_program: - cmp [entry_code_type],32 - jne HF_code_type_ok + push ebx + call convert_imports + pop ebx or [HF_attributes],1 - HF_code_type_ok: mov eax,[code_size] mov ecx,eax mov edi,[code_start] @@ -88,6 +112,36 @@ start: add eax,ecx sub eax,10h mov [HF_size],eax + cmp [program_relocatable],0 + je HF_relocations_ok + or [HF_attributes],10b + mov eax,[relocations_end] + sub eax,[relocations_memory] + mov [relocations_size],eax + mov [relocations_size+4],eax + or eax,eax + jz HF_relocations_ok + add [HF_size],10h + add [HF_size],eax + HF_relocations_ok: + mov eax,[exports_end] + sub eax,[exports_memory] + mov [exports_size],eax + mov [exports_size+4],eax + or eax,eax + jz HF_exports_ok + add [HF_size],10h + add [HF_size],eax + HF_exports_ok: + mov eax,[imports_end] + sub eax,[imports_memory] + mov [imports_size],eax + mov [imports_size+4],eax + or eax,eax + jz HF_imports_ok + add [HF_size],10h + add [HF_size],eax + HF_imports_ok: mov eax,[entry_point] mov [HF_initial_EIP],eax mov [HF_initial_ESP],0 @@ -97,6 +151,40 @@ start: mov ecx,[code_size] mov ah,40h int 21h + cmp [program_relocatable],0 + je relocations_saved + cmp [relocations_size],0 + je relocations_saved + mov edx,relocations_header + mov ecx,10h + mov ah,40h + int 21h + mov edx,[relocations_memory] + mov ecx,[relocations_size] + mov ah,40h + int 21h + relocations_saved: + cmp [exports_size],0 + je exports_saved + mov edx,exports_header + mov ecx,10h + mov ah,40h + int 21h + mov edx,[exports_memory] + mov ecx,[exports_size] + mov ah,40h + int 21h + exports_saved: + cmp [imports_size],0 + je exit + mov edx,imports_header + mov ecx,10h + mov ah,40h + int 21h + mov edx,[imports_memory] + mov ecx,[imports_size] + mov ah,40h + int 21h jmp exit save_raw_code: mov edx,[code_start] @@ -198,8 +286,115 @@ get_params: stosb ret -_information db 'flat assembler version 0.90',0Dh,0Ah - db 'copyright (c) 1999 by privalov',0Dh,0Ah +macro skip_string + { + local _loop + _loop: + lodsb + or al,al + jnz _loop + } + +convert_imports: + mov edi,[imports_end] + mov esi,[imports_memory] + find_DLL: + cmp esi,[imports_end] + jae imports_converted + cmp byte [esi],0Dh + je next_import_entry + mov ebx,edi + mov [value],edi + jmp copy_DLL_name + next_import_entry: + skip_string + skip_string + jmp find_DLL + copy_DLL_name: + lodsb + stosb + or al,al + jnz copy_DLL_name + mov [temp_dword],edi + mov ebp,edi + mov esi,ebx + mov ebx,edi + sub ebx,esi + mov edi,[imports_memory] + mov [import_number],0 + find_import_for_current_DLL: + cmp edi,[imports_end] + jae current_DLL_ok + mov edx,edi + mov ecx,ebx + push esi + repe cmpsb + jne next_import + mov byte [edx],0Dh + mov esi,edi + mov edi,ebp + copy_import_name: + lodsb + stosb + or al,al + jnz copy_import_name + push ebx ebp + mov ebp,edi + mov ecx,[import_number] + mov ebx,[import_relocations_memory] + add edi,4 + copy_import_relocations: + cmp ebx,[import_relocations_end] + je import_relocations_ok + cmp dword [ebx+4],ecx + jne next_import_relocation + mov eax,[ebx] + stosd + next_import_relocation: + add ebx,8 + jmp copy_import_relocations + import_relocations_ok: + mov eax,edi + sub eax,ebp + shr eax,2 + dec eax + mov [ds:ebp],eax + pop ebp ebx + or eax,eax + jz import_converted + mov ebp,edi + import_converted: + mov edi,esi + pop esi + inc [import_number] + jmp find_import_for_current_DLL + next_import: + pop esi + xchg esi,edi + skip_string + skip_string + xchg esi,edi + inc [import_number] + jmp find_import_for_current_DLL + current_DLL_ok: + mov esi,[imports_memory] + mov edi,ebp + cmp edi,[temp_dword] + je empty_DLL + xor al,al + stosb + jmp find_DLL + empty_DLL: + mov edi,[value] + jmp find_DLL + imports_converted: + mov eax,[imports_end] + mov [imports_memory],eax + mov [imports_end],edi + ret + +_information db 'flat assembler version 1.00',0Dh,0Ah + db 'copyright (c) 1999-2000 by privalov',0Dh,0Ah db 'usage: fasm source output',0Dh,0Ah db 0 @@ -217,6 +412,18 @@ HF_header: HF_code_size dd 0,0 HF_header_end: +relocations_header: + dd 'relt',0 + relocations_size dd 0,0 + +exports_header: + dd 'expt',0 + exports_size dd 0,0 + +imports_header: + dd 'impt',0 + imports_size dd 0,0 + input_file rd 1 output_file rd 1 @@ -224,9 +431,21 @@ memory_start dd 0 memory_end dd 0 additional_memory dd 0 additional_memory_end dd 0 +relocations_memory dd 0 +relocations_memory_end dd 0 +relocations_end dd 0 +exports_memory dd 0 +exports_memory_end dd 0 +exports_end dd 0 +imports_memory dd 0 +imports_memory_end dd 0 +imports_end dd 0 +import_relocations_memory dd 0 +import_relocations_memory_end dd 0 +import_relocations_end dd 0 source_start dd 0 +code_start dd 0 +code_size dd 0 params rb 100h switches rb 100h -code_start dd 0 -code_size dd 0 diff --git a/SOURCE/PREPROCE.INC b/SOURCE/PREPROCE.INC index d18799d..4967368 100644 --- a/SOURCE/PREPROCE.INC +++ b/SOURCE/PREPROCE.INC @@ -93,19 +93,22 @@ preprocess_file: je lf_character cmp al,0Dh je cr_character + or al,al + jz line_end stosb jmp copy_line lf_character: + lodsb cmp al,0Dh je line_end dec esi jmp line_end cr_character: + lodsb cmp al,0Ah je line_end dec esi line_end: - add esi,2 xor al,al stosb ret @@ -432,12 +435,41 @@ use_macro: mov ebp,esi find_argument_value_end: lodsb + cmp al,27h + je skip_argument_string cmp al,',' je argument_value_end or al,al jz argument_value_end cmp al,';' + je argument_value_end + cmp al,20h jne find_argument_value_end + push esi + check_argument_spaces: + lodsb + cmp al,20h + je check_argument_spaces + cmp al,',' + je no_argument_spaces + or al,al + jz no_argument_spaces + cmp al,';' + je no_argument_spaces + add esp,4 + jmp find_argument_value_end + no_argument_spaces: + pop esi + jmp argument_value_end + skip_argument_string: + lodsb + cmp al,27h + jne skip_argument_string + lodsb + cmp al,27h + je skip_argument_string + dec esi + jmp find_argument_value_end argument_value_end: dec esi xchg esi,ebx @@ -476,11 +508,14 @@ use_macro: cmp al,',' je next_argument dec ebx + check_arguments: lodsb - cmp al,0 - je arguments_ok + or al,al + jz arguments_ok cmp al,';' je arguments_ok + cmp al,20h + je check_arguments jmp invalid_macro_arguments next_argument: lodsb @@ -528,6 +563,8 @@ use_macro: repne scasb mov edi,ebx je special_character + cmp al,'.' + je special_character cmp al,27h je skip_string dec esi @@ -545,12 +582,15 @@ use_macro: repe cmpsb jnz next_macro_variable mov al,[esi] + cmp al,'.' + je macro_variable_ok mov ebx,edi mov edi,special_characters+1 movzx ecx,[special_characters] repne scasb mov edi,ebx jne next_macro_variable + macro_variable_ok: pop edi mov ebx,ebp movzx ecx,byte [ebx] @@ -737,8 +777,30 @@ HF_directive: mov edx,[current_line] mov byte [edx+4],':' mov [program_format],48h + mov [default_code_type],32 + push edi + mov edi,program_types + call get_operator + pop edi + or al,al + jz check_directive_line + cmp al,1 + je HF_relocatable + check_directive_line: + lodsb + or al,al + jz directive_ok + cmp al,';' + je directive_ok + cmp al,20h + je check_directive_line + jmp extra_characters_on_line + directive_ok: pop ebp edi esi ecx ret + HF_relocatable: + mov [program_relocatable],1 + jmp check_directive_line file_number db 0 files_list dd 0 diff --git a/SOURCE/SYMBOLS.INC b/SOURCE/SYMBOLS.INC index 2ec1b41..11f50b4 100644 --- a/SOURCE/SYMBOLS.INC +++ b/SOURCE/SYMBOLS.INC @@ -52,6 +52,7 @@ create_symbol: pop edx eax mov [ebx],eax mov [ebx+4],edx + mov byte [ebx+10],0 pop edi esi cmp ebx,edi jbe out_of_memory @@ -109,7 +110,11 @@ get_symbol: mov eax,[current_offset] sub eax,[org_start] xor edx,edx - mov cl,2 + mov cx,2 + cmp [program_relocatable],0 + je got_symbol + mov ch,1 + got_symbol: ret get_symbol_from_list: mov edi,[symbols_list] @@ -138,14 +143,14 @@ get_symbol: cmp [current_pass],0 je no_symbol_yet symbol_undefined: - xor cl,cl + xor cx,cx ret no_symbol_yet: mov esi,edx add esi,ebp xor eax,eax xor edx,edx - mov cl,1 + mov cx,1 ret symbol_found: cmp ah,'.' @@ -163,6 +168,18 @@ get_symbol: mov eax,[ebx] mov edx,[ebx+4] mov cl,3 + mov ch,[ebx+10] + cmp ch,2 + je imported_symbol + cmp ch,1 + jne got_symbol + cmp [program_relocatable],0 + jne got_symbol + xor ch,ch + ret + imported_symbol: + mov [import_value],eax + xor eax,eax ret symbols_list dd 0 diff --git a/SOURCE/TABLES.INC b/SOURCE/TABLES.INC index 7d3cade..c037ad3 100644 --- a/SOURCE/TABLES.INC +++ b/SOURCE/TABLES.INC @@ -134,6 +134,11 @@ jump_operators: special_operators: db 2,'at',1 + db 4,'from',2 + db 0 + +end_operators: + db 7,'virtual',1 db 0 code_types: @@ -141,6 +146,10 @@ code_types: db 2,'32',32 db 0 +program_types: + db 11,'relocatable',1 + db 0 + index_registers: db 3,'eax',40h db 3,'ecx',41h @@ -274,6 +283,10 @@ instructions: dd simple_instruction db 3,'aas',3Fh dd simple_instruction + db 3,'aam',D4h + dd aa_instruction + db 3,'aad',D5h + dd aa_instruction db 5,'pusha',60h dd simple_instruction db 4,'popa',61h @@ -371,6 +384,8 @@ instructions: db 5,'scasd',AFh dd simple_instruction_32bit db 4,'xlat',D7h + dd xlat_instruction + db 5,'xlatb',D7h dd simple_instruction db 4,'lock',F0h dd prefix_instruction @@ -864,6 +879,8 @@ instructions: dd prefix_instruction db 3,'org',0 dd org_directive + db 7,'virtual',0 + dd virtual_directive db 4,'code',0 dd code_directive db 5,'label',0 @@ -872,6 +889,12 @@ instructions: dd times_directive db 5,'entry',0 dd entry_directive + db 6,'export',0 + dd export_directive + db 6,'import',0 + dd import_directive + db 3,'end',0 + dd end_directive data_instructions: db 2,'db',1 dd data_bytes diff --git a/SYNTAX.ASM b/SYNTAX.ASM new file mode 100644 index 0000000..ce872ef --- /dev/null +++ b/SYNTAX.ASM @@ -0,0 +1,65 @@ + +; there is no documentation yet, so here are some examples of syntax: +; (note: all instructions and labels are case sensitive) + +; - memory addressing + + mov [cs:bx+si+10],al ; full 16-bit address + mov [ebx*5],al ; simple 32-bit address + +; - defining size of arguments + + push dword 0 ; not very complicated + mov word [esi],4 ; argument size must be defined here + mov [esi],word 4 ; also correct + +; - data instructions + + dw 1,2 ; two words + rb 5 ; reserve five bytes + file 'syntax.asm' ; include file contents + +; - labels and constants + +alfa: ; simple label + label beta ; as above + label gamma byte ; low byte of delta dword +delta dd 0 ; data label +epsilon = alfa + 1 ; constant definition + +; - jump and call instructions + + jmp alfa ; simple jump + jmp near byte beta ; short jump + jmp near dword beta ; force dword size + jmp 10h:50h ; far jump + call far pword [1000h] ; 32-bit far call + call far dword [delta] ; 16-bit far call + call near dword [delta] ; 32-bit near call + +; - conditional jumps + + je alfa ; will be optimized + jge byte alfa ; force byte (error if out of range) + jb dword alfa ; force dword (no optimization) + +; - values + + db 12 ; decimal + db 101111b ; binary + db ABh ; hexadecimal (case sensitive!) + +; - calculations + + db not (8 or 4) ; logical + dw 2+4*5+10 mod 3 ; arithmetic + dq 8000000001*45000h ; 64-bit + +; - macroinstructions + +times 5 db 90h ; five bytes with value 90h +macro alfa number { db number } ; simple macro definition +macro beta number ; also correct + { + db number + }