unreleased version 1.00

This commit is contained in:
Tomasz Grysztar 1999-07-01 21:38:14 +02:00
parent 61a1789231
commit 613ec371a5
8 changed files with 1200 additions and 61 deletions

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

65
SYNTAX.ASM Normal file
View file

@ -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
}