Subversion Repositories Kolibri OS

Compare Revisions

Ignore whitespace Rev 156 → Rev 157

/programs/develop/fasm/trunk/TABLES.INC
File deleted
/programs/develop/fasm/trunk/assemble.inc
4,1948 → 4,1948
; All rights reserved.
 
assembler:
xor eax,eax
mov [stub_size],eax
mov [number_of_sections],eax
mov [current_pass],ax
mov [resolver_flags],eax
xor eax,eax
mov [stub_size],eax
mov [number_of_sections],eax
mov [current_pass],ax
mov [resolver_flags],eax
assembler_loop:
mov eax,[labels_list]
mov [display_buffer],eax
mov eax,[additional_memory]
mov [free_additional_memory],eax
mov eax,[additional_memory_end]
mov [structures_buffer],eax
mov esi,[source_start]
mov edi,[code_start]
xor eax,eax
mov dword [adjustment],eax
mov dword [adjustment+4],eax
mov dword [org_origin],edi
mov dword [org_origin+4],eax
mov [org_start],edi
mov [org_registers],eax
mov [org_symbol],eax
mov [error_line],eax
mov [counter],eax
mov [format_flags],eax
mov [number_of_relocations],eax
mov [undefined_data_end],eax
mov [next_pass_needed],al
mov [output_format],al
mov [labels_type],al
mov [virtual_data],al
mov [code_type],16
mov eax,[labels_list]
mov [display_buffer],eax
mov eax,[additional_memory]
mov [free_additional_memory],eax
mov eax,[additional_memory_end]
mov [structures_buffer],eax
mov esi,[source_start]
mov edi,[code_start]
xor eax,eax
mov dword [adjustment],eax
mov dword [adjustment+4],eax
mov dword [org_origin],edi
mov dword [org_origin+4],eax
mov [org_start],edi
mov [org_registers],eax
mov [org_symbol],eax
mov [error_line],eax
mov [counter],eax
mov [format_flags],eax
mov [number_of_relocations],eax
mov [undefined_data_end],eax
mov [next_pass_needed],al
mov [output_format],al
mov [labels_type],al
mov [virtual_data],al
mov [code_type],16
pass_loop:
call assemble_line
jnc pass_loop
mov eax,[additional_memory_end]
cmp eax,[structures_buffer]
je pass_done
sub eax,20h
mov eax,[eax+4]
mov [current_line],eax
jmp missing_end_directive
call assemble_line
jnc pass_loop
mov eax,[additional_memory_end]
cmp eax,[structures_buffer]
je pass_done
sub eax,20h
mov eax,[eax+4]
mov [current_line],eax
jmp missing_end_directive
pass_done:
call close_pass
mov eax,[labels_list]
call close_pass
mov eax,[labels_list]
check_symbols:
cmp eax,[memory_end]
jae symbols_checked
test byte [eax+8],8
jz symbol_defined_ok
mov cx,[current_pass]
cmp cx,[eax+18]
jne symbol_defined_ok
test byte [eax+8],1
jz symbol_defined_ok
sub cx,[eax+16]
cmp cx,1
jne symbol_defined_ok
and byte [eax+8],not 1
or [next_pass_needed],-1
cmp eax,[memory_end]
jae symbols_checked
test byte [eax+8],8
jz symbol_defined_ok
mov cx,[current_pass]
cmp cx,[eax+18]
jne symbol_defined_ok
test byte [eax+8],1
jz symbol_defined_ok
sub cx,[eax+16]
cmp cx,1
jne symbol_defined_ok
and byte [eax+8],not 1
or [next_pass_needed],-1
symbol_defined_ok:
test byte [eax+8],10h
jz use_prediction_ok
mov cx,[current_pass]
and byte [eax+8],not 10h
test byte [eax+8],20h
jnz check_use_prediction
cmp cx,[eax+18]
jne use_prediction_ok
test byte [eax+8],8
jz use_prediction_ok
jmp use_misprediction
test byte [eax+8],10h
jz use_prediction_ok
mov cx,[current_pass]
and byte [eax+8],not 10h
test byte [eax+8],20h
jnz check_use_prediction
cmp cx,[eax+18]
jne use_prediction_ok
test byte [eax+8],8
jz use_prediction_ok
jmp use_misprediction
check_use_prediction:
test byte [eax+8],8
jz use_misprediction
cmp cx,[eax+18]
je use_prediction_ok
test byte [eax+8],8
jz use_misprediction
cmp cx,[eax+18]
je use_prediction_ok
use_misprediction:
or [next_pass_needed],-1
or [next_pass_needed],-1
use_prediction_ok:
test byte [eax+8],40h
jz check_next_symbol
and byte [eax+8],not 40h
test byte [eax+8],4
jnz define_misprediction
mov cx,[current_pass]
test byte [eax+8],80h
jnz check_define_prediction
cmp cx,[eax+16]
jne check_next_symbol
test byte [eax+8],1
jz check_next_symbol
jmp define_misprediction
test byte [eax+8],40h
jz check_next_symbol
and byte [eax+8],not 40h
test byte [eax+8],4
jnz define_misprediction
mov cx,[current_pass]
test byte [eax+8],80h
jnz check_define_prediction
cmp cx,[eax+16]
jne check_next_symbol
test byte [eax+8],1
jz check_next_symbol
jmp define_misprediction
check_define_prediction:
test byte [eax+8],1
jz define_misprediction
cmp cx,[eax+16]
je check_next_symbol
test byte [eax+8],1
jz define_misprediction
cmp cx,[eax+16]
je check_next_symbol
define_misprediction:
or [next_pass_needed],-1
or [next_pass_needed],-1
check_next_symbol:
add eax,LABEL_STRUCTURE_SIZE
jmp check_symbols
add eax,LABEL_STRUCTURE_SIZE
jmp check_symbols
symbols_checked:
cmp [next_pass_needed],0
jne next_pass
mov eax,[error_line]
or eax,eax
jz assemble_ok
mov [current_line],eax
jmp near [error]
cmp [next_pass_needed],0
jne next_pass
mov eax,[error_line]
or eax,eax
jz assemble_ok
mov [current_line],eax
jmp near [error]
next_pass:
inc [current_pass]
mov ax,[current_pass]
cmp ax,[passes_limit]
je code_cannot_be_generated
jmp assembler_loop
inc [current_pass]
mov ax,[current_pass]
cmp ax,[passes_limit]
je code_cannot_be_generated
jmp assembler_loop
assemble_ok:
ret
ret
 
assemble_line:
mov eax,[display_buffer]
sub eax,100h
cmp edi,eax
ja out_of_memory
lods byte [esi]
cmp al,1
je assemble_instruction
jb source_end
cmp al,3
jb define_label
je define_constant
cmp al,0Fh
je new_line
cmp al,13h
je code_type_setting
cmp al,10h
jne illegal_instruction
lods byte [esi]
jmp segment_prefix
mov eax,[display_buffer]
sub eax,100h
cmp edi,eax
ja out_of_memory
lods byte [esi]
cmp al,1
je assemble_instruction
jb source_end
cmp al,3
jb define_label
je define_constant
cmp al,0Fh
je new_line
cmp al,13h
je code_type_setting
cmp al,10h
jne illegal_instruction
lods byte [esi]
jmp segment_prefix
code_type_setting:
lods byte [esi]
mov [code_type],al
jmp line_assembled
lods byte [esi]
mov [code_type],al
jmp line_assembled
new_line:
lods dword [esi]
mov [current_line],eax
mov [prefixed_instruction],0
lods dword [esi]
mov [current_line],eax
mov [prefixed_instruction],0
continue_line:
cmp byte [esi],0Fh
je line_assembled
jmp assemble_line
cmp byte [esi],0Fh
je line_assembled
jmp assemble_line
define_label:
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov ebx,eax
lods byte [esi]
mov cl,al
mov eax,edi
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
mov ch,[labels_type]
cmp [virtual_data],0
jne make_virtual_label
or byte [ebx+9],1
xchg eax,[ebx]
xchg edx,[ebx+4]
sub eax,[ebx]
sbb edx,[ebx+4]
mov dword [adjustment],eax
mov dword [adjustment+4],edx
or eax,edx
setnz ah
jmp finish_label_symbol
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov ebx,eax
lods byte [esi]
mov cl,al
mov eax,edi
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
mov ch,[labels_type]
cmp [virtual_data],0
jne make_virtual_label
or byte [ebx+9],1
xchg eax,[ebx]
xchg edx,[ebx+4]
sub eax,[ebx]
sbb edx,[ebx+4]
mov dword [adjustment],eax
mov dword [adjustment+4],edx
or eax,edx
setnz ah
jmp finish_label_symbol
make_virtual_label:
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
finish_label_symbol:
cmp cl,[ebx+10]
mov [ebx+10],cl
setne al
or ah,al
cmp ch,[ebx+11]
mov [ebx+11],ch
setne al
or ah,al
mov edx,[org_registers]
cmp edx,[ebx+12]
mov [ebx+12],edx
setne al
or ah,al
or ch,ch
jz label_symbol_ok
mov edx,[org_symbol]
cmp edx,[ebx+20]
mov [ebx+20],edx
setne al
or ah,al
cmp cl,[ebx+10]
mov [ebx+10],cl
setne al
or ah,al
cmp ch,[ebx+11]
mov [ebx+11],ch
setne al
or ah,al
mov edx,[org_registers]
cmp edx,[ebx+12]
mov [ebx+12],edx
setne al
or ah,al
or ch,ch
jz label_symbol_ok
mov edx,[org_symbol]
cmp edx,[ebx+20]
mov [ebx+20],edx
setne al
or ah,al
label_symbol_ok:
mov cx,[current_pass]
xchg [ebx+16],cx
mov edx,[current_line]
mov [ebx+28],edx
and byte [ebx+8],not 2
test byte [ebx+8],1
jz new_label
cmp cx,[ebx+16]
je symbol_already_defined
inc cx
sub cx,[ebx+16]
setnz al
or ah,al
jz continue_line
test byte [ebx+8],8
jz continue_line
mov cx,[current_pass]
cmp cx,[ebx+18]
jne continue_line
or [next_pass_needed],-1
jmp continue_line
mov cx,[current_pass]
xchg [ebx+16],cx
mov edx,[current_line]
mov [ebx+28],edx
and byte [ebx+8],not 2
test byte [ebx+8],1
jz new_label
cmp cx,[ebx+16]
je symbol_already_defined
inc cx
sub cx,[ebx+16]
setnz al
or ah,al
jz continue_line
test byte [ebx+8],8
jz continue_line
mov cx,[current_pass]
cmp cx,[ebx+18]
jne continue_line
or [next_pass_needed],-1
jmp continue_line
new_label:
or byte [ebx+8],1
jmp continue_line
or byte [ebx+8],1
jmp continue_line
define_constant:
lods dword [esi]
inc esi
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov edx,[eax+8]
push edx
cmp [current_pass],0
je get_constant_value
test dl,4
jnz get_constant_value
mov cx,[current_pass]
cmp cx,[eax+16]
je get_constant_value
and dl,not 1
mov [eax+8],dl
lods dword [esi]
inc esi
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov edx,[eax+8]
push edx
cmp [current_pass],0
je get_constant_value
test dl,4
jnz get_constant_value
mov cx,[current_pass]
cmp cx,[eax+16]
je get_constant_value
and dl,not 1
mov [eax+8],dl
get_constant_value:
push eax
mov al,byte [esi-1]
push eax
call get_value
pop ebx
mov ch,bl
pop ebx
pop dword [ebx+8]
cmp ebx,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
xor cl,cl
mov ch,[value_type]
cmp ch,3
je invalid_use_of_symbol
push eax
mov al,byte [esi-1]
push eax
call get_value
pop ebx
mov ch,bl
pop ebx
pop dword [ebx+8]
cmp ebx,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
xor cl,cl
mov ch,[value_type]
cmp ch,3
je invalid_use_of_symbol
make_constant:
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
cmp cl,[ebx+10]
mov [ebx+10],cl
setne al
or ah,al
cmp ch,[ebx+11]
mov [ebx+11],ch
setne al
or ah,al
xor edx,edx
cmp edx,[ebx+12]
mov [ebx+12],edx
setne al
or ah,al
or ch,ch
jz constant_symbol_ok
mov edx,[symbol_identifier]
cmp edx,[ebx+20]
mov [ebx+20],edx
setne al
or ah,al
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
cmp cl,[ebx+10]
mov [ebx+10],cl
setne al
or ah,al
cmp ch,[ebx+11]
mov [ebx+11],ch
setne al
or ah,al
xor edx,edx
cmp edx,[ebx+12]
mov [ebx+12],edx
setne al
or ah,al
or ch,ch
jz constant_symbol_ok
mov edx,[symbol_identifier]
cmp edx,[ebx+20]
mov [ebx+20],edx
setne al
or ah,al
constant_symbol_ok:
mov cx,[current_pass]
xchg [ebx+16],cx
mov edx,[current_line]
mov [ebx+28],edx
test byte [ebx+8],1
jz new_constant
cmp cx,[ebx+16]
jne redeclare_constant
test byte [ebx+8],2
jz symbol_already_defined
or byte [ebx+8],4
jmp instruction_assembled
mov cx,[current_pass]
xchg [ebx+16],cx
mov edx,[current_line]
mov [ebx+28],edx
test byte [ebx+8],1
jz new_constant
cmp cx,[ebx+16]
jne redeclare_constant
test byte [ebx+8],2
jz symbol_already_defined
or byte [ebx+8],4
jmp instruction_assembled
redeclare_constant:
inc cx
sub cx,[ebx+16]
setnz al
or ah,al
jz instruction_assembled
test byte [ebx+8],4
jnz instruction_assembled
test byte [ebx+8],8
jz instruction_assembled
mov cx,[current_pass]
cmp cx,[ebx+18]
jne instruction_assembled
or [next_pass_needed],-1
jmp instruction_assembled
inc cx
sub cx,[ebx+16]
setnz al
or ah,al
jz instruction_assembled
test byte [ebx+8],4
jnz instruction_assembled
test byte [ebx+8],8
jz instruction_assembled
mov cx,[current_pass]
cmp cx,[ebx+18]
jne instruction_assembled
or [next_pass_needed],-1
jmp instruction_assembled
new_constant:
or byte [ebx+8],1+2
jmp instruction_assembled
or byte [ebx+8],1+2
jmp instruction_assembled
assemble_instruction:
mov [operand_size],0
mov [size_override],0
mov [operand_prefix],0
mov [rex_prefix],0
mov [immediate_size],0
movzx ebx,word [esi]
mov al,[esi+2]
add ebx,assembler
add esi,3
jmp near ebx
mov [operand_size],0
mov [size_override],0
mov [operand_prefix],0
mov [rex_prefix],0
mov [immediate_size],0
movzx ebx,word [esi]
mov al,[esi+2]
add ebx,assembler
add esi,3
jmp near ebx
instruction_assembled:
mov al,[esi]
cmp al,0Fh
je line_assembled
or al,al
jnz extra_characters_on_line
mov al,[esi]
cmp al,0Fh
je line_assembled
or al,al
jnz extra_characters_on_line
line_assembled:
clc
ret
clc
ret
source_end:
dec esi
stc
ret
dec esi
stc
ret
skip_line:
call skip_symbol
jnc skip_line
ret
call skip_symbol
jnc skip_line
ret
skip_symbol:
lods byte [esi]
or al,al
jz nothing_to_skip
cmp al,0Fh
je nothing_to_skip
cmp al,1
je skip_instruction
cmp al,2
je skip_label
cmp al,3
je skip_label
cmp al,20h
jb skip_assembler_symbol
cmp al,'('
je skip_expression
cmp al,'['
je skip_address
lods byte [esi]
or al,al
jz nothing_to_skip
cmp al,0Fh
je nothing_to_skip
cmp al,1
je skip_instruction
cmp al,2
je skip_label
cmp al,3
je skip_label
cmp al,20h
jb skip_assembler_symbol
cmp al,'('
je skip_expression
cmp al,'['
je skip_address
skip_done:
clc
ret
clc
ret
skip_label:
add esi,2
add esi,2
skip_instruction:
add esi,2
add esi,2
skip_assembler_symbol:
inc esi
jmp skip_done
inc esi
jmp skip_done
skip_address:
mov al,[esi]
and al,11110000b
cmp al,60h
jb skip_expression
cmp al,70h
ja skip_expression
inc esi
jmp skip_address
mov al,[esi]
and al,11110000b
cmp al,60h
jb skip_expression
cmp al,70h
ja skip_expression
inc esi
jmp skip_address
skip_expression:
lods byte [esi]
or al,al
jz skip_string
cmp al,'.'
je skip_fp_value
cmp al,')'
je skip_done
cmp al,']'
je skip_done
cmp al,'!'
je skip_expression
cmp al,0Fh
je skip_expression
cmp al,10h
je skip_register
cmp al,11h
je skip_label_value
cmp al,80h
jae skip_expression
movzx eax,al
add esi,eax
jmp skip_expression
lods byte [esi]
or al,al
jz skip_string
cmp al,'.'
je skip_fp_value
cmp al,')'
je skip_done
cmp al,']'
je skip_done
cmp al,'!'
je skip_expression
cmp al,0Fh
je skip_expression
cmp al,10h
je skip_register
cmp al,11h
je skip_label_value
cmp al,80h
jae skip_expression
movzx eax,al
add esi,eax
jmp skip_expression
skip_label_value:
add esi,3
add esi,3
skip_register:
inc esi
jmp skip_expression
inc esi
jmp skip_expression
skip_fp_value:
add esi,12
jmp skip_done
add esi,12
jmp skip_done
skip_string:
lods dword [esi]
add esi,eax
inc esi
jmp skip_done
lods dword [esi]
add esi,eax
inc esi
jmp skip_done
nothing_to_skip:
dec esi
stc
ret
dec esi
stc
ret
 
org_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_qword_value
mov cl,[value_type]
test cl,1
jnz invalid_use_of_symbol
mov [labels_type],cl
mov ecx,edi
sub ecx,eax
adc edx,0
neg edx
mov dword [org_origin],ecx
mov dword [org_origin+4],edx
mov [org_registers],0
mov [org_start],edi
mov edx,[symbol_identifier]
mov [org_symbol],edx
cmp [output_format],1
ja instruction_assembled
cmp edi,[code_start]
jne instruction_assembled
cmp eax,100h
jne instruction_assembled
bts [format_flags],0
jmp instruction_assembled
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_qword_value
mov cl,[value_type]
test cl,1
jnz invalid_use_of_symbol
mov [labels_type],cl
mov ecx,edi
sub ecx,eax
adc edx,0
neg edx
mov dword [org_origin],ecx
mov dword [org_origin+4],edx
mov [org_registers],0
mov [org_start],edi
mov edx,[symbol_identifier]
mov [org_symbol],edx
cmp [output_format],1
ja instruction_assembled
cmp edi,[code_start]
jne instruction_assembled
cmp eax,100h
jne instruction_assembled
bts [format_flags],0
jmp instruction_assembled
label_directive:
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
mov ebx,eax
xor cl,cl
lods byte [esi]
cmp al,':'
je get_label_size
dec esi
cmp al,11h
jne label_size_ok
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
mov ebx,eax
xor cl,cl
lods byte [esi]
cmp al,':'
je get_label_size
dec esi
cmp al,11h
jne label_size_ok
get_label_size:
lods word [esi]
cmp al,11h
jne invalid_argument
mov cl,ah
lods word [esi]
cmp al,11h
jne invalid_argument
mov cl,ah
label_size_ok:
mov eax,edi
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
mov ebp,[org_registers]
cmp byte [esi],80h
je get_free_label_value
mov ch,[labels_type]
push [org_symbol]
pop [address_symbol]
cmp [virtual_data],0
jne make_free_label
or byte [ebx+9],1
xchg eax,[ebx]
xchg edx,[ebx+4]
sub eax,[ebx]
sbb edx,[ebx+4]
mov dword [adjustment],eax
mov dword [adjustment+4],edx
or eax,edx
setne ah
jmp finish_label
mov eax,edi
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
mov ebp,[org_registers]
cmp byte [esi],80h
je get_free_label_value
mov ch,[labels_type]
push [org_symbol]
pop [address_symbol]
cmp [virtual_data],0
jne make_free_label
or byte [ebx+9],1
xchg eax,[ebx]
xchg edx,[ebx+4]
sub eax,[ebx]
sbb edx,[ebx+4]
mov dword [adjustment],eax
mov dword [adjustment+4],edx
or eax,edx
setne ah
jmp finish_label
get_free_label_value:
inc esi
lods byte [esi]
cmp al,'('
jne invalid_argument
push dword [ebx+8]
push ebx ecx
and byte [ebx+8],not 1
cmp byte [esi],'.'
je invalid_value
call get_address_value
or bh,bh
setnz ch
xchg ch,cl
mov bp,cx
shl ebp,16
xchg bl,bh
mov bp,bx
pop ecx ebx
pop dword [ebx+8]
mov ch,[value_type]
or ch,ch
jz make_free_label
cmp ch,4
je make_free_label
cmp ch,2
jne invalid_use_of_symbol
inc esi
lods byte [esi]
cmp al,'('
jne invalid_argument
push dword [ebx+8]
push ebx ecx
and byte [ebx+8],not 1
cmp byte [esi],'.'
je invalid_value
call get_address_value
or bh,bh
setnz ch
xchg ch,cl
mov bp,cx
shl ebp,16
xchg bl,bh
mov bp,bx
pop ecx ebx
pop dword [ebx+8]
mov ch,[value_type]
or ch,ch
jz make_free_label
cmp ch,4
je make_free_label
cmp ch,2
jne invalid_use_of_symbol
make_free_label:
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
jmp finish_label
and byte [ebx+9],not 1
cmp eax,[ebx]
mov [ebx],eax
setne ah
cmp edx,[ebx+4]
mov [ebx+4],edx
setne al
or ah,al
jmp finish_label
finish_label:
cmp cl,[ebx+10]
mov [ebx+10],cl
setne al
or ah,al
cmp ch,[ebx+11]
mov [ebx+11],ch
setne al
or ah,al
cmp ebp,[ebx+12]
mov [ebx+12],ebp
setne al
or ah,al
or ch,ch
jz free_label_symbol_ok
mov edx,[address_symbol]
cmp edx,[ebx+20]
mov [ebx+20],edx
setne al
or ah,al
cmp cl,[ebx+10]
mov [ebx+10],cl
setne al
or ah,al
cmp ch,[ebx+11]
mov [ebx+11],ch
setne al
or ah,al
cmp ebp,[ebx+12]
mov [ebx+12],ebp
setne al
or ah,al
or ch,ch
jz free_label_symbol_ok
mov edx,[address_symbol]
cmp edx,[ebx+20]
mov [ebx+20],edx
setne al
or ah,al
free_label_symbol_ok:
mov cx,[current_pass]
xchg [ebx+16],cx
mov edx,[current_line]
mov [ebx+28],edx
and byte [ebx+8],not 2
test byte [ebx+8],1
jz new_free_label
cmp cx,[ebx+16]
je symbol_already_defined
inc cx
sub cx,[ebx+16]
setnz al
or ah,al
jz instruction_assembled
test byte [ebx+8],8
jz instruction_assembled
mov cx,[current_pass]
cmp cx,[ebx+18]
jne instruction_assembled
or [next_pass_needed],-1
jmp instruction_assembled
mov cx,[current_pass]
xchg [ebx+16],cx
mov edx,[current_line]
mov [ebx+28],edx
and byte [ebx+8],not 2
test byte [ebx+8],1
jz new_free_label
cmp cx,[ebx+16]
je symbol_already_defined
inc cx
sub cx,[ebx+16]
setnz al
or ah,al
jz instruction_assembled
test byte [ebx+8],8
jz instruction_assembled
mov cx,[current_pass]
cmp cx,[ebx+18]
jne instruction_assembled
or [next_pass_needed],-1
jmp instruction_assembled
new_free_label:
or byte [ebx+8],1
jmp instruction_assembled
or byte [ebx+8],1
jmp instruction_assembled
load_directive:
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
push eax
mov al,1
cmp byte [esi],11h
jne load_size_ok
lods byte [esi]
lods byte [esi]
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
push eax
mov al,1
cmp byte [esi],11h
jne load_size_ok
lods byte [esi]
lods byte [esi]
load_size_ok:
cmp al,8
ja invalid_value
mov [operand_size],al
mov dword [value],0
mov dword [value+4],0
lods word [esi]
cmp ax,82h+'(' shl 8
jne invalid_argument
cmp al,8
ja invalid_value
mov [operand_size],al
mov dword [value],0
mov dword [value+4],0
lods word [esi]
cmp ax,82h+'(' shl 8
jne invalid_argument
load_from_code:
cmp byte [esi],'.'
je invalid_value
call get_relative_offset
neg eax
cmp [next_pass_needed],0
jne load_address_ok
cmp [value_type],0
jne invalid_use_of_symbol
cmp byte [esi],'.'
je invalid_value
call get_relative_offset
neg eax
cmp [next_pass_needed],0
jne load_address_ok
cmp [value_type],0
jne invalid_use_of_symbol
load_address_ok:
push esi edi
mov esi,edi
sub esi,eax
jc bad_load_address
cmp esi,[org_start]
jb bad_load_address
mov edi,value
movzx ecx,[operand_size]
cmp ecx,eax
ja bad_load_address
rep movs byte [edi],[esi]
jmp value_loaded
push esi edi
mov esi,edi
sub esi,eax
jc bad_load_address
cmp esi,[org_start]
jb bad_load_address
mov edi,value
movzx ecx,[operand_size]
cmp ecx,eax
ja bad_load_address
rep movs byte [edi],[esi]
jmp value_loaded
bad_load_address:
cmp [error_line],0
jne value_loaded
mov eax,[current_line]
mov [error_line],eax
mov [error],value_out_of_range
cmp [error_line],0
jne value_loaded
mov eax,[current_line]
mov [error_line],eax
mov [error],value_out_of_range
value_loaded:
pop edi esi
mov eax,dword [value]
mov edx,dword [value+4]
pop ebx
xor cx,cx
jmp make_constant
pop edi esi
mov eax,dword [value]
mov edx,dword [value+4]
pop ebx
xor cx,cx
jmp make_constant
store_directive:
cmp byte [esi],11h
je sized_store
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_byte_value
xor edx,edx
movzx eax,al
mov [operand_size],1
jmp store_value_ok
cmp byte [esi],11h
je sized_store
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_byte_value
xor edx,edx
movzx eax,al
mov [operand_size],1
jmp store_value_ok
sized_store:
call get_value
call get_value
store_value_ok:
cmp [value_type],0
jne invalid_use_of_symbol
mov dword [value],eax
mov dword [value+4],edx
lods word [esi]
cmp ax,80h+'(' shl 8
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_relative_offset
neg eax
cmp [next_pass_needed],0
jne store_address_ok
cmp [value_type],0
jne invalid_use_of_symbol
cmp [value_type],0
jne invalid_use_of_symbol
mov dword [value],eax
mov dword [value+4],edx
lods word [esi]
cmp ax,80h+'(' shl 8
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_relative_offset
neg eax
cmp [next_pass_needed],0
jne store_address_ok
cmp [value_type],0
jne invalid_use_of_symbol
store_address_ok:
push esi edi
sub edi,eax
jc bad_store_address
cmp edi,[org_start]
jb bad_store_address
mov esi,value
movzx ecx,[operand_size]
cmp ecx,eax
ja bad_store_address
rep movs byte [edi],[esi]
mov eax,edi
pop edi esi
cmp edi,[undefined_data_end]
jne instruction_assembled
cmp eax,[undefined_data_start]
jbe instruction_assembled
mov [undefined_data_start],eax
jmp instruction_assembled
push esi edi
sub edi,eax
jc bad_store_address
cmp edi,[org_start]
jb bad_store_address
mov esi,value
movzx ecx,[operand_size]
cmp ecx,eax
ja bad_store_address
rep movs byte [edi],[esi]
mov eax,edi
pop edi esi
cmp edi,[undefined_data_end]
jne instruction_assembled
cmp eax,[undefined_data_start]
jbe instruction_assembled
mov [undefined_data_start],eax
jmp instruction_assembled
bad_store_address:
pop edi esi
cmp [error_line],0
jne instruction_assembled
mov eax,[current_line]
mov [error_line],eax
mov [error],value_out_of_range
jmp instruction_assembled
pop edi esi
cmp [error_line],0
jne instruction_assembled
mov eax,[current_line]
mov [error_line],eax
mov [error],value_out_of_range
jmp instruction_assembled
 
display_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],0
jne display_byte
inc esi
lods dword [esi]
mov ecx,eax
push edi
mov edi,[display_buffer]
sub edi,4
sub edi,eax
mov [display_buffer],edi
rep movs byte [edi],[esi]
stos dword [edi]
pop edi
inc esi
jmp display_next
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],0
jne display_byte
inc esi
lods dword [esi]
mov ecx,eax
push edi
mov edi,[display_buffer]
sub edi,4
sub edi,eax
mov [display_buffer],edi
rep movs byte [edi],[esi]
stos dword [edi]
pop edi
inc esi
jmp display_next
display_byte:
call get_byte_value
push edi
mov edi,[display_buffer]
sub edi,4+1
mov [display_buffer],edi
stos byte [edi]
mov eax,1
stos dword [edi]
pop edi
call get_byte_value
push edi
mov edi,[display_buffer]
sub edi,4+1
mov [display_buffer],edi
stos byte [edi]
mov eax,1
stos dword [edi]
pop edi
display_next:
cmp edi,[display_buffer]
ja out_of_memory
lods byte [esi]
cmp al,','
je display_directive
dec esi
jmp instruction_assembled
cmp edi,[display_buffer]
ja out_of_memory
lods byte [esi]
cmp al,','
je display_directive
dec esi
jmp instruction_assembled
flush_display_buffer:
mov eax,[display_buffer]
or eax,eax
jz display_done
mov esi,[labels_list]
cmp esi,eax
je display_done
mov eax,[display_buffer]
or eax,eax
jz display_done
mov esi,[labels_list]
cmp esi,eax
je display_done
display_messages:
sub esi,4
mov ecx,[esi]
sub esi,ecx
push esi
call display_block
pop esi
cmp esi,[display_buffer]
jne display_messages
mov eax,[labels_list]
mov [display_buffer],eax
sub esi,4
mov ecx,[esi]
sub esi,ecx
push esi
call display_block
pop esi
cmp esi,[display_buffer]
jne display_messages
mov eax,[labels_list]
mov [display_buffer],eax
display_done:
ret
ret
times_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne times_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne times_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
times_value_ok:
cmp eax,0
je zero_times
jl negative_times
cmp byte [esi],':'
jne times_argument_ok
inc esi
cmp eax,0
je zero_times
jl negative_times
cmp byte [esi],':'
jne times_argument_ok
inc esi
times_argument_ok:
push [counter]
push [counter_limit]
mov [counter_limit],eax
mov [counter],1
push [counter]
push [counter_limit]
mov [counter_limit],eax
mov [counter],1
times_loop:
mov eax,esp
sub eax,100h
jc stack_overflow
cmp eax,[stack_limit]
jb stack_overflow
push esi
or [prefixed_instruction],-1
call continue_line
mov eax,[counter_limit]
cmp [counter],eax
je times_done
inc [counter]
pop esi
jmp times_loop
mov eax,esp
sub eax,100h
jc stack_overflow
cmp eax,[stack_limit]
jb stack_overflow
push esi
or [prefixed_instruction],-1
call continue_line
mov eax,[counter_limit]
cmp [counter],eax
je times_done
inc [counter]
pop esi
jmp times_loop
times_done:
pop eax
pop [counter_limit]
pop [counter]
jmp instruction_assembled
pop eax
pop [counter_limit]
pop [counter]
jmp instruction_assembled
negative_times:
cmp [error_line],0
jne zero_times
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
cmp [error_line],0
jne zero_times
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
zero_times:
call skip_line
jmp instruction_assembled
call skip_line
jmp instruction_assembled
 
virtual_directive:
lods byte [esi]
cmp al,80h
jne virtual_at_current
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_address_value
mov ebp,[address_symbol]
xor ch,ch
or bh,bh
jz set_virtual
mov ch,1
jmp set_virtual
lods byte [esi]
cmp al,80h
jne virtual_at_current
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_address_value
mov ebp,[address_symbol]
xor ch,ch
or bh,bh
jz set_virtual
mov ch,1
jmp set_virtual
virtual_at_current:
dec esi
mov al,[labels_type]
mov [value_type],al
mov ebp,[org_symbol]
mov eax,edi
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
mov bx,word [org_registers]
mov cx,word [org_registers+2]
xchg bh,bl
xchg ch,cl
dec esi
mov al,[labels_type]
mov [value_type],al
mov ebp,[org_symbol]
mov eax,edi
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
mov bx,word [org_registers]
mov cx,word [org_registers+2]
xchg bh,bl
xchg ch,cl
set_virtual:
push [org_registers]
mov byte [org_registers],bh
mov byte [org_registers+1],bl
mov byte [org_registers+2],ch
mov byte [org_registers+3],cl
call allocate_structure_data
mov word [ebx],virtual_directive-assembler
not eax
not edx
add eax,1
adc edx,0
add eax,edi
adc edx,0
xchg dword [org_origin],eax
xchg dword [org_origin+4],edx
mov [ebx+10h],eax
mov [ebx+14h],edx
pop eax
mov [ebx+18h],eax
mov al,[virtual_data]
mov [ebx+2],al
mov al,[labels_type]
mov [ebx+3],al
mov eax,edi
xchg eax,[org_start]
mov [ebx+0Ch],eax
xchg ebp,[org_symbol]
mov [ebx+1Ch],ebp
mov [ebx+8],edi
mov eax,[current_line]
mov [ebx+4],eax
or [virtual_data],-1
mov al,[value_type]
test al,1
jnz invalid_use_of_symbol
mov [labels_type],al
jmp instruction_assembled
push [org_registers]
mov byte [org_registers],bh
mov byte [org_registers+1],bl
mov byte [org_registers+2],ch
mov byte [org_registers+3],cl
call allocate_structure_data
mov word [ebx],virtual_directive-assembler
not eax
not edx
add eax,1
adc edx,0
add eax,edi
adc edx,0
xchg dword [org_origin],eax
xchg dword [org_origin+4],edx
mov [ebx+10h],eax
mov [ebx+14h],edx
pop eax
mov [ebx+18h],eax
mov al,[virtual_data]
mov [ebx+2],al
mov al,[labels_type]
mov [ebx+3],al
mov eax,edi
xchg eax,[org_start]
mov [ebx+0Ch],eax
xchg ebp,[org_symbol]
mov [ebx+1Ch],ebp
mov [ebx+8],edi
mov eax,[current_line]
mov [ebx+4],eax
or [virtual_data],-1
mov al,[value_type]
test al,1
jnz invalid_use_of_symbol
mov [labels_type],al
jmp instruction_assembled
allocate_structure_data:
mov ebx,[structures_buffer]
sub ebx,20h
cmp ebx,[free_additional_memory]
jb out_of_memory
mov [structures_buffer],ebx
ret
mov ebx,[structures_buffer]
sub ebx,20h
cmp ebx,[free_additional_memory]
jb out_of_memory
mov [structures_buffer],ebx
ret
find_structure_data:
mov ebx,[structures_buffer]
mov ebx,[structures_buffer]
scan_structures:
cmp ebx,[additional_memory_end]
je no_such_structure
cmp ax,[ebx]
je structure_data_found
add ebx,20h
jmp scan_structures
cmp ebx,[additional_memory_end]
je no_such_structure
cmp ax,[ebx]
je structure_data_found
add ebx,20h
jmp scan_structures
structure_data_found:
ret
ret
no_such_structure:
stc
ret
stc
ret
end_virtual:
call find_structure_data
jc unexpected_instruction
mov al,[ebx+2]
mov [virtual_data],al
mov al,[ebx+3]
mov [labels_type],al
mov eax,[ebx+10h]
mov dword [org_origin],eax
mov eax,[ebx+14h]
mov dword [org_origin+4],eax
mov eax,[ebx+18h]
mov [org_registers],eax
mov eax,[ebx+0Ch]
mov [org_start],eax
mov eax,[ebx+1Ch]
mov [org_symbol],eax
mov edi,[ebx+8]
call find_structure_data
jc unexpected_instruction
mov al,[ebx+2]
mov [virtual_data],al
mov al,[ebx+3]
mov [labels_type],al
mov eax,[ebx+10h]
mov dword [org_origin],eax
mov eax,[ebx+14h]
mov dword [org_origin+4],eax
mov eax,[ebx+18h]
mov [org_registers],eax
mov eax,[ebx+0Ch]
mov [org_start],eax
mov eax,[ebx+1Ch]
mov [org_symbol],eax
mov edi,[ebx+8]
remove_structure_data:
push esi edi
mov esi,[structures_buffer]
mov ecx,ebx
sub ecx,esi
lea edi,[esi+20h]
mov [structures_buffer],edi
shr ecx,2
rep movs dword [edi],[esi]
pop edi esi
ret
push esi edi
mov esi,[structures_buffer]
mov ecx,ebx
sub ecx,esi
lea edi,[esi+20h]
mov [structures_buffer],edi
shr ecx,2
rep movs dword [edi],[esi]
pop edi esi
ret
repeat_directive:
cmp [prefixed_instruction],0
jne unexpected_instruction
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne repeat_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
cmp [prefixed_instruction],0
jne unexpected_instruction
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne repeat_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
repeat_value_ok:
cmp eax,0
je zero_repeat
jl negative_repeat
call allocate_structure_data
mov word [ebx],repeat_directive-assembler
xchg eax,[counter_limit]
mov [ebx+10h],eax
mov eax,1
xchg eax,[counter]
mov [ebx+14h],eax
mov [ebx+8],esi
mov eax,[current_line]
mov [ebx+4],eax
jmp instruction_assembled
cmp eax,0
je zero_repeat
jl negative_repeat
call allocate_structure_data
mov word [ebx],repeat_directive-assembler
xchg eax,[counter_limit]
mov [ebx+10h],eax
mov eax,1
xchg eax,[counter]
mov [ebx+14h],eax
mov [ebx+8],esi
mov eax,[current_line]
mov [ebx+4],eax
jmp instruction_assembled
end_repeat:
cmp [prefixed_instruction],0
jne unexpected_instruction
call find_structure_data
jc unexpected_instruction
mov eax,[counter_limit]
inc [counter]
cmp [counter],eax
jbe continue_repeating
cmp [prefixed_instruction],0
jne unexpected_instruction
call find_structure_data
jc unexpected_instruction
mov eax,[counter_limit]
inc [counter]
cmp [counter],eax
jbe continue_repeating
stop_repeat:
mov eax,[ebx+10h]
mov [counter_limit],eax
mov eax,[ebx+14h]
mov [counter],eax
call remove_structure_data
jmp instruction_assembled
mov eax,[ebx+10h]
mov [counter_limit],eax
mov eax,[ebx+14h]
mov [counter],eax
call remove_structure_data
jmp instruction_assembled
continue_repeating:
mov esi,[ebx+8]
jmp instruction_assembled
mov esi,[ebx+8]
jmp instruction_assembled
negative_repeat:
cmp [error_line],0
jne zero_repeat
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
cmp [error_line],0
jne zero_repeat
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
zero_repeat:
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
call find_end_repeat
jmp instruction_assembled
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
call find_end_repeat
jmp instruction_assembled
find_end_repeat:
call find_structure_end
cmp ax,repeat_directive-assembler
jne unexpected_instruction
ret
call find_structure_end
cmp ax,repeat_directive-assembler
jne unexpected_instruction
ret
while_directive:
cmp [prefixed_instruction],0
jne unexpected_instruction
call allocate_structure_data
mov word [ebx],while_directive-assembler
mov eax,1
xchg eax,[counter]
mov [ebx+10h],eax
mov [ebx+8],esi
mov eax,[current_line]
mov [ebx+4],eax
cmp [prefixed_instruction],0
jne unexpected_instruction
call allocate_structure_data
mov word [ebx],while_directive-assembler
mov eax,1
xchg eax,[counter]
mov [ebx+10h],eax
mov [ebx+8],esi
mov eax,[current_line]
mov [ebx+4],eax
do_while:
push ebx
call calculate_logical_expression
or al,al
jnz while_true
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
push ebx
call calculate_logical_expression
or al,al
jnz while_true
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
stop_while:
call find_end_while
pop ebx
mov eax,[ebx+10h]
mov [counter],eax
call remove_structure_data
jmp instruction_assembled
call find_end_while
pop ebx
mov eax,[ebx+10h]
mov [counter],eax
call remove_structure_data
jmp instruction_assembled
while_true:
pop ebx
jmp instruction_assembled
pop ebx
jmp instruction_assembled
end_while:
cmp [prefixed_instruction],0
jne unexpected_instruction
call find_structure_data
jc unexpected_instruction
mov eax,[ebx+4]
mov [current_line],eax
inc [counter]
jz too_many_repeats
mov esi,[ebx+8]
jmp do_while
cmp [prefixed_instruction],0
jne unexpected_instruction
call find_structure_data
jc unexpected_instruction
mov eax,[ebx+4]
mov [current_line],eax
inc [counter]
jz too_many_repeats
mov esi,[ebx+8]
jmp do_while
find_end_while:
call find_structure_end
cmp ax,while_directive-assembler
jne unexpected_instruction
ret
call find_structure_end
cmp ax,while_directive-assembler
jne unexpected_instruction
ret
if_directive:
cmp [prefixed_instruction],0
jne unexpected_instruction
call calculate_logical_expression
mov dl,al
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
or dl,dl
jnz if_true
call find_else
jc instruction_assembled
mov al,[esi]
cmp al,1
jne else_true
cmp word [esi+1],if_directive-assembler
jne else_true
add esi,4
jmp if_directive
cmp [prefixed_instruction],0
jne unexpected_instruction
call calculate_logical_expression
mov dl,al
mov al,[esi]
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
or dl,dl
jnz if_true
call find_else
jc instruction_assembled
mov al,[esi]
cmp al,1
jne else_true
cmp word [esi+1],if_directive-assembler
jne else_true
add esi,4
jmp if_directive
if_true:
xor al,al
xor al,al
make_if_structure:
call allocate_structure_data
mov word [ebx],if_directive-assembler
mov byte [ebx+2],al
mov eax,[current_line]
mov [ebx+4],eax
jmp instruction_assembled
call allocate_structure_data
mov word [ebx],if_directive-assembler
mov byte [ebx+2],al
mov eax,[current_line]
mov [ebx+4],eax
jmp instruction_assembled
else_true:
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
or al,-1
jmp make_if_structure
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
or al,-1
jmp make_if_structure
else_directive:
cmp [prefixed_instruction],0
jne unexpected_instruction
mov ax,if_directive-assembler
call find_structure_data
jc unexpected_instruction
cmp byte [ebx+2],0
jne unexpected_instruction
cmp [prefixed_instruction],0
jne unexpected_instruction
mov ax,if_directive-assembler
call find_structure_data
jc unexpected_instruction
cmp byte [ebx+2],0
jne unexpected_instruction
found_else:
mov al,[esi]
cmp al,1
jne skip_else
cmp word [esi+1],if_directive-assembler
jne skip_else
add esi,4
call find_else
jnc found_else
call remove_structure_data
jmp instruction_assembled
mov al,[esi]
cmp al,1
jne skip_else
cmp word [esi+1],if_directive-assembler
jne skip_else
add esi,4
call find_else
jnc found_else
call remove_structure_data
jmp instruction_assembled
skip_else:
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
call find_end_if
call remove_structure_data
jmp instruction_assembled
or al,al
jz missing_end_directive
cmp al,0Fh
jne extra_characters_on_line
call find_end_if
call remove_structure_data
jmp instruction_assembled
end_if:
cmp [prefixed_instruction],0
jne unexpected_instruction
call find_structure_data
jc unexpected_instruction
call remove_structure_data
jmp instruction_assembled
cmp [prefixed_instruction],0
jne unexpected_instruction
call find_structure_data
jc unexpected_instruction
call remove_structure_data
jmp instruction_assembled
find_else:
call find_structure_end
cmp ax,else_directive-assembler
je else_found
cmp ax,if_directive-assembler
jne unexpected_instruction
stc
ret
call find_structure_end
cmp ax,else_directive-assembler
je else_found
cmp ax,if_directive-assembler
jne unexpected_instruction
stc
ret
else_found:
clc
ret
clc
ret
find_end_if:
call find_structure_end
cmp ax,if_directive-assembler
jne unexpected_instruction
ret
call find_structure_end
cmp ax,if_directive-assembler
jne unexpected_instruction
ret
find_structure_end:
push [error_line]
mov eax,[current_line]
mov [error_line],eax
push [error_line]
mov eax,[current_line]
mov [error_line],eax
find_end_directive:
call skip_line
lods byte [esi]
cmp al,0Fh
jne no_end_directive
lods dword [esi]
mov [current_line],eax
call skip_line
lods byte [esi]
cmp al,0Fh
jne no_end_directive
lods dword [esi]
mov [current_line],eax
skip_labels:
cmp byte [esi],2
jne labels_ok
add esi,6
jmp skip_labels
cmp byte [esi],2
jne labels_ok
add esi,6
jmp skip_labels
labels_ok:
cmp byte [esi],1
jne find_end_directive
mov ax,[esi+1]
cmp ax,prefix_instruction-assembler
je find_end_directive
add esi,4
cmp ax,repeat_directive-assembler
je skip_repeat
cmp ax,while_directive-assembler
je skip_while
cmp ax,if_directive-assembler
je skip_if
cmp ax,else_directive-assembler
je structure_end
cmp ax,end_directive-assembler
jne find_end_directive
cmp byte [esi],1
jne find_end_directive
mov ax,[esi+1]
add esi,4
cmp ax,repeat_directive-assembler
je structure_end
cmp ax,while_directive-assembler
je structure_end
cmp ax,if_directive-assembler
jne find_end_directive
cmp byte [esi],1
jne find_end_directive
mov ax,[esi+1]
cmp ax,prefix_instruction-assembler
je find_end_directive
add esi,4
cmp ax,repeat_directive-assembler
je skip_repeat
cmp ax,while_directive-assembler
je skip_while
cmp ax,if_directive-assembler
je skip_if
cmp ax,else_directive-assembler
je structure_end
cmp ax,end_directive-assembler
jne find_end_directive
cmp byte [esi],1
jne find_end_directive
mov ax,[esi+1]
add esi,4
cmp ax,repeat_directive-assembler
je structure_end
cmp ax,while_directive-assembler
je structure_end
cmp ax,if_directive-assembler
jne find_end_directive
structure_end:
pop [error_line]
ret
pop [error_line]
ret
no_end_directive:
mov eax,[error_line]
mov [current_line],eax
jmp missing_end_directive
mov eax,[error_line]
mov [current_line],eax
jmp missing_end_directive
skip_repeat:
call find_end_repeat
jmp find_end_directive
call find_end_repeat
jmp find_end_directive
skip_while:
call find_end_while
jmp find_end_directive
call find_end_while
jmp find_end_directive
skip_if:
call skip_if_block
jmp find_end_directive
call skip_if_block
jmp find_end_directive
skip_if_block:
call find_else
jc if_block_skipped
cmp byte [esi],1
jne skip_after_else
cmp word [esi+1],if_directive-assembler
jne skip_after_else
add esi,4
jmp skip_if_block
call find_else
jc if_block_skipped
cmp byte [esi],1
jne skip_after_else
cmp word [esi+1],if_directive-assembler
jne skip_after_else
add esi,4
jmp skip_if_block
skip_after_else:
call find_end_if
call find_end_if
if_block_skipped:
ret
ret
end_directive:
lods byte [esi]
cmp al,1
jne invalid_argument
lods word [esi]
inc esi
cmp ax,virtual_directive-assembler
je end_virtual
cmp ax,repeat_directive-assembler
je end_repeat
cmp ax,while_directive-assembler
je end_while
cmp ax,if_directive-assembler
je end_if
cmp ax,data_directive-assembler
je end_data
jmp invalid_argument
lods byte [esi]
cmp al,1
jne invalid_argument
lods word [esi]
inc esi
cmp ax,virtual_directive-assembler
je end_virtual
cmp ax,repeat_directive-assembler
je end_repeat
cmp ax,while_directive-assembler
je end_while
cmp ax,if_directive-assembler
je end_if
cmp ax,data_directive-assembler
je end_data
jmp invalid_argument
break_directive:
mov ebx,[structures_buffer]
mov al,[esi]
or al,al
jz find_breakable_structure
cmp al,0Fh
jne extra_characters_on_line
mov ebx,[structures_buffer]
mov al,[esi]
or al,al
jz find_breakable_structure
cmp al,0Fh
jne extra_characters_on_line
find_breakable_structure:
cmp ebx,[additional_memory_end]
je unexpected_instruction
mov ax,[ebx]
cmp ax,repeat_directive-assembler
je break_repeat
cmp ax,while_directive-assembler
je break_while
cmp ax,if_directive-assembler
je break_if
add ebx,20h
jmp find_breakable_structure
cmp ebx,[additional_memory_end]
je unexpected_instruction
mov ax,[ebx]
cmp ax,repeat_directive-assembler
je break_repeat
cmp ax,while_directive-assembler
je break_while
cmp ax,if_directive-assembler
je break_if
add ebx,20h
jmp find_breakable_structure
break_if:
push [current_line]
mov eax,[ebx+4]
mov [current_line],eax
call remove_structure_data
call skip_if_block
pop [current_line]
mov ebx,[structures_buffer]
jmp find_breakable_structure
push [current_line]
mov eax,[ebx+4]
mov [current_line],eax
call remove_structure_data
call skip_if_block
pop [current_line]
mov ebx,[structures_buffer]
jmp find_breakable_structure
break_repeat:
push ebx
call find_end_repeat
pop ebx
jmp stop_repeat
push ebx
call find_end_repeat
pop ebx
jmp stop_repeat
break_while:
push ebx
jmp stop_while
push ebx
jmp stop_while
 
data_bytes:
call define_data
lods byte [esi]
cmp al,'('
je get_byte
cmp al,'?'
jne invalid_argument
mov eax,edi
mov byte [edi],0
inc edi
jmp undefined_data
call define_data
lods byte [esi]
cmp al,'('
je get_byte
cmp al,'?'
jne invalid_argument
mov eax,edi
mov byte [edi],0
inc edi
jmp undefined_data
get_byte:
cmp byte [esi],0
je get_string
call get_byte_value
stos byte [edi]
ret
cmp byte [esi],0
je get_string
call get_byte_value
stos byte [edi]
ret
get_string:
inc esi
lods dword [esi]
mov ecx,eax
lea eax,[edi+ecx]
cmp eax,[display_buffer]
ja out_of_memory
rep movs byte [edi],[esi]
inc esi
ret
inc esi
lods dword [esi]
mov ecx,eax
lea eax,[edi+ecx]
cmp eax,[display_buffer]
ja out_of_memory
rep movs byte [edi],[esi]
inc esi
ret
undefined_data:
cmp [virtual_data],0
je mark_undefined_data
ret
cmp [virtual_data],0
je mark_undefined_data
ret
mark_undefined_data:
cmp eax,[undefined_data_end]
je undefined_data_ok
mov [undefined_data_start],eax
cmp eax,[undefined_data_end]
je undefined_data_ok
mov [undefined_data_start],eax
undefined_data_ok:
mov [undefined_data_end],edi
ret
mov [undefined_data_end],edi
ret
define_data:
cmp edi,[display_buffer]
jae out_of_memory
cmp byte [esi],'('
jne simple_data_value
mov ebx,esi
inc esi
call skip_expression
xchg esi,ebx
cmp byte [ebx],81h
jne simple_data_value
inc esi
call get_dword_value
cmp [next_pass_needed],0
jne dup_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
cmp edi,[display_buffer]
jae out_of_memory
cmp byte [esi],'('
jne simple_data_value
mov ebx,esi
inc esi
call skip_expression
xchg esi,ebx
cmp byte [ebx],81h
jne simple_data_value
inc esi
call get_dword_value
cmp [next_pass_needed],0
jne dup_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
dup_value_ok:
inc esi
cmp eax,0
jg dup_positive
cmp [error_line],0
jne dup_invalid
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
inc esi
cmp eax,0
jg dup_positive
cmp [error_line],0
jne dup_invalid
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
dup_invalid:
mov eax,1
mov eax,1
dup_positive:
cmp byte [esi],'{'
jne duplicate_single_data_value
inc esi
cmp byte [esi],'{'
jne duplicate_single_data_value
inc esi
duplicate_data:
push eax esi
push eax esi
duplicated_values:
cmp edi,[display_buffer]
jae out_of_memory
call near dword [esp+8]
lods byte [esi]
cmp al,','
je duplicated_values
cmp al,'}'
jne invalid_argument
pop ebx eax
dec eax
jz data_defined
mov esi,ebx
jmp duplicate_data
cmp edi,[display_buffer]
jae out_of_memory
call near dword [esp+8]
lods byte [esi]
cmp al,','
je duplicated_values
cmp al,'}'
jne invalid_argument
pop ebx eax
dec eax
jz data_defined
mov esi,ebx
jmp duplicate_data
duplicate_single_data_value:
cmp edi,[display_buffer]
jae out_of_memory
push eax esi
call near dword [esp+8]
pop ebx eax
dec eax
jz data_defined
mov esi,ebx
jmp duplicate_single_data_value
cmp edi,[display_buffer]
jae out_of_memory
push eax esi
call near dword [esp+8]
pop ebx eax
dec eax
jz data_defined
mov esi,ebx
jmp duplicate_single_data_value
simple_data_value:
cmp edi,[display_buffer]
jae out_of_memory
call near dword [esp]
cmp edi,[display_buffer]
jae out_of_memory
call near dword [esp]
data_defined:
lods byte [esi]
cmp al,','
je define_data
dec esi
add esp,4
jmp instruction_assembled
lods byte [esi]
cmp al,','
je define_data
dec esi
add esp,4
jmp instruction_assembled
data_unicode:
or [base_code],-1
jmp define_words
or [base_code],-1
jmp define_words
data_words:
mov [base_code],0
mov [base_code],0
define_words:
call define_data
lods byte [esi]
cmp al,'('
je get_word
cmp al,'?'
jne invalid_argument
mov eax,edi
mov word [edi],0
scas word [edi]
jmp undefined_data
ret
call define_data
lods byte [esi]
cmp al,'('
je get_word
cmp al,'?'
jne invalid_argument
mov eax,edi
mov word [edi],0
scas word [edi]
jmp undefined_data
ret
get_word:
cmp [base_code],0
je word_data_value
cmp byte [esi],0
je word_string
cmp [base_code],0
je word_data_value
cmp byte [esi],0
je word_string
word_data_value:
call get_word_value
call mark_relocation
stos word [edi]
ret
call get_word_value
call mark_relocation
stos word [edi]
ret
word_string:
inc esi
lods dword [esi]
mov ecx,eax
jecxz word_string_ok
lea eax,[edi+ecx*2]
cmp eax,[display_buffer]
ja out_of_memory
xor ah,ah
inc esi
lods dword [esi]
mov ecx,eax
jecxz word_string_ok
lea eax,[edi+ecx*2]
cmp eax,[display_buffer]
ja out_of_memory
xor ah,ah
copy_word_string:
lods byte [esi]
stos word [edi]
loop copy_word_string
lods byte [esi]
stos word [edi]
loop copy_word_string
word_string_ok:
inc esi
ret
inc esi
ret
data_dwords:
call define_data
lods byte [esi]
cmp al,'('
je get_dword
cmp al,'?'
jne invalid_argument
mov eax,edi
mov dword [edi],0
scas dword [edi]
jmp undefined_data
call define_data
lods byte [esi]
cmp al,'('
je get_dword
cmp al,'?'
jne invalid_argument
mov eax,edi
mov dword [edi],0
scas dword [edi]
jmp undefined_data
get_dword:
push esi
call get_dword_value
pop ebx
cmp byte [esi],':'
je complex_dword
call mark_relocation
stos dword [edi]
ret
push esi
call get_dword_value
pop ebx
cmp byte [esi],':'
je complex_dword
call mark_relocation
stos dword [edi]
ret
complex_dword:
mov esi,ebx
cmp byte [esi],'.'
je invalid_value
call get_word_value
push eax
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_word_value
call mark_relocation
stos word [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
mov esi,ebx
cmp byte [esi],'.'
je invalid_value
call get_word_value
push eax
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_word_value
call mark_relocation
stos word [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
data_pwords:
call define_data
lods byte [esi]
cmp al,'('
je get_pword
cmp al,'?'
jne invalid_argument
mov eax,edi
mov dword [edi],0
scas dword [edi]
mov word [edi],0
scas word [edi]
jmp undefined_data
call define_data
lods byte [esi]
cmp al,'('
je get_pword
cmp al,'?'
jne invalid_argument
mov eax,edi
mov dword [edi],0
scas dword [edi]
mov word [edi],0
scas word [edi]
jmp undefined_data
get_pword:
push esi
call get_pword_value
pop ebx
cmp byte [esi],':'
je complex_pword
call mark_relocation
stos dword [edi]
mov ax,dx
stos word [edi]
ret
push esi
call get_pword_value
pop ebx
cmp byte [esi],':'
je complex_pword
call mark_relocation
stos dword [edi]
mov ax,dx
stos word [edi]
ret
complex_pword:
mov esi,ebx
cmp byte [esi],'.'
je invalid_value
call get_word_value
push eax
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_dword_value
call mark_relocation
stos dword [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
mov esi,ebx
cmp byte [esi],'.'
je invalid_value
call get_word_value
push eax
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_dword_value
call mark_relocation
stos dword [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
data_qwords:
call define_data
lods byte [esi]
cmp al,'('
je get_qword
cmp al,'?'
jne invalid_argument
mov eax,edi
mov dword [edi],0
scas dword [edi]
mov dword [edi],0
scas dword [edi]
jmp undefined_data
call define_data
lods byte [esi]
cmp al,'('
je get_qword
cmp al,'?'
jne invalid_argument
mov eax,edi
mov dword [edi],0
scas dword [edi]
mov dword [edi],0
scas dword [edi]
jmp undefined_data
get_qword:
call get_qword_value
call mark_relocation
stos dword [edi]
mov eax,edx
stos dword [edi]
ret
call get_qword_value
call mark_relocation
stos dword [edi]
mov eax,edx
stos dword [edi]
ret
data_twords:
call define_data
lods byte [esi]
cmp al,'('
je get_tword
cmp al,'?'
jne invalid_argument
mov eax,edi
mov dword [edi],0
scas dword [edi]
mov dword [edi],0
scas dword [edi]
mov word [edi],0
scas word [edi]
jmp undefined_data
call define_data
lods byte [esi]
cmp al,'('
je get_tword
cmp al,'?'
jne invalid_argument
mov eax,edi
mov dword [edi],0
scas dword [edi]
mov dword [edi],0
scas dword [edi]
mov word [edi],0
scas word [edi]
jmp undefined_data
get_tword:
cmp byte [esi],'.'
jne complex_tword
inc esi
cmp word [esi+8],8000h
je fp_zero_tword
mov eax,[esi]
stos dword [edi]
mov eax,[esi+4]
stos dword [edi]
mov ax,[esi+8]
add ax,3FFFh
cmp ax,8000h
jae value_out_of_range
mov bl,[esi+11]
shl bx,15
or ax,bx
stos word [edi]
add esi,13
ret
cmp byte [esi],'.'
jne complex_tword
inc esi
cmp word [esi+8],8000h
je fp_zero_tword
mov eax,[esi]
stos dword [edi]
mov eax,[esi+4]
stos dword [edi]
mov ax,[esi+8]
add ax,3FFFh
cmp ax,8000h
jae value_out_of_range
mov bl,[esi+11]
shl bx,15
or ax,bx
stos word [edi]
add esi,13
ret
fp_zero_tword:
xor eax,eax
stos dword [edi]
stos dword [edi]
mov al,[esi+11]
shl ax,15
stos word [edi]
add esi,13
ret
xor eax,eax
stos dword [edi]
stos dword [edi]
mov al,[esi+11]
shl ax,15
stos word [edi]
add esi,13
ret
complex_tword:
call get_word_value
push eax
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_qword_value
call mark_relocation
stos dword [edi]
mov eax,edx
stos dword [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
call get_word_value
push eax
inc esi
lods byte [esi]
cmp al,'('
jne invalid_operand
mov al,[value_type]
push eax
cmp byte [esi],'.'
je invalid_value
call get_qword_value
call mark_relocation
stos dword [edi]
mov eax,edx
stos dword [edi]
pop eax
mov [value_type],al
pop eax
call mark_relocation
stos word [edi]
ret
data_file:
lods word [esi]
cmp ax,'('
jne invalid_argument
add esi,4
call open_binary_file
mov eax,[esi-4]
lea esi,[esi+eax+1]
mov al,2
xor edx,edx
call lseek
push eax
xor edx,edx
cmp byte [esi],':'
jne position_ok
inc esi
cmp byte [esi],'('
jne invalid_argument
inc esi
cmp byte [esi],'.'
je invalid_value
push ebx
call get_dword_value
pop ebx
mov edx,eax
sub [esp],edx
lods word [esi]
cmp ax,'('
jne invalid_argument
add esi,4
call open_binary_file
mov eax,[esi-4]
lea esi,[esi+eax+1]
mov al,2
xor edx,edx
call lseek
push eax
xor edx,edx
cmp byte [esi],':'
jne position_ok
inc esi
cmp byte [esi],'('
jne invalid_argument
inc esi
cmp byte [esi],'.'
je invalid_value
push ebx
call get_dword_value
pop ebx
mov edx,eax
sub [esp],edx
position_ok:
cmp byte [esi],','
jne size_ok
inc esi
cmp byte [esi],'('
jne invalid_argument
inc esi
cmp byte [esi],'.'
je invalid_value
push ebx edx
call get_dword_value
pop edx ebx
mov [esp],eax
cmp byte [esi],','
jne size_ok
inc esi
cmp byte [esi],'('
jne invalid_argument
inc esi
cmp byte [esi],'.'
je invalid_value
push ebx edx
call get_dword_value
pop edx ebx
mov [esp],eax
size_ok:
xor al,al
call lseek
pop ecx
mov edx,edi
add edi,ecx
jc out_of_memory
cmp edi,[display_buffer]
ja out_of_memory
call read
jc error_reading_file
call close
lods byte [esi]
cmp al,','
je data_file
dec esi
jmp instruction_assembled
xor al,al
call lseek
pop ecx
mov edx,edi
add edi,ecx
jc out_of_memory
cmp edi,[display_buffer]
ja out_of_memory
call read
jc error_reading_file
call close
lods byte [esi]
cmp al,','
je data_file
dec esi
jmp instruction_assembled
open_binary_file:
push esi
push edi
mov esi,[current_line]
mov esi,[esi]
push esi
push edi
mov esi,[current_line]
mov esi,[esi]
get_current_path:
lodsb
stosb
or al,al
jnz get_current_path
lodsb
stosb
or al,al
jnz get_current_path
cut_current_path:
cmp edi,[esp]
je current_path_ok
cmp byte [edi-1],'\'
je current_path_ok
cmp byte [edi-1],'/'
je current_path_ok
dec edi
jmp cut_current_path
cmp edi,[esp]
je current_path_ok
cmp byte [edi-1],'\'
je current_path_ok
cmp byte [edi-1],'/'
je current_path_ok
dec edi
jmp cut_current_path
current_path_ok:
mov esi,[esp+4]
call preprocess_path
pop edx
mov esi,edx
call open
jnc file_opened
mov edi,esi
mov esi,[esp]
push edi
call preprocess_path
pop edx
mov esi,edx
call open
jc file_not_found
mov esi,[esp+4]
call preprocess_path
pop edx
mov esi,edx
call open
jnc file_opened
mov edi,esi
mov esi,[esp]
push edi
call preprocess_path
pop edx
mov esi,edx
call open
jc file_not_found
file_opened:
mov edi,esi
pop esi
ret
mov edi,esi
pop esi
ret
reserve_bytes:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rb_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rb_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
rb_value_ok:
cmp eax,0
jl reserve_negative
mov ecx,eax
mov edx,ecx
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_bytes
add edi,ecx
jmp reserved_data
cmp eax,0
jl reserve_negative
mov ecx,eax
mov edx,ecx
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_bytes
add edi,ecx
jmp reserved_data
zero_bytes:
xor eax,eax
shr ecx,1
jnc bytes_stosb_ok
stos byte [edi]
xor eax,eax
shr ecx,1
jnc bytes_stosb_ok
stos byte [edi]
bytes_stosb_ok:
shr ecx,1
jnc bytes_stosw_ok
stos word [edi]
shr ecx,1
jnc bytes_stosw_ok
stos word [edi]
bytes_stosw_ok:
rep stos dword [edi]
rep stos dword [edi]
reserved_data:
pop eax
call undefined_data
jmp instruction_assembled
pop eax
call undefined_data
jmp instruction_assembled
reserve_negative:
cmp [error_line],0
jne instruction_assembled
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
jmp instruction_assembled
cmp [error_line],0
jne instruction_assembled
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_value
jmp instruction_assembled
reserve_words:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rw_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rw_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
rw_value_ok:
cmp eax,0
jl reserve_negative
mov ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
cmp eax,0
jl reserve_negative
mov ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
zero_words:
xor eax,eax
shr ecx,1
jnc words_stosw_ok
stos word [edi]
xor eax,eax
shr ecx,1
jnc words_stosw_ok
stos word [edi]
words_stosw_ok:
rep stos dword [edi]
jmp reserved_data
rep stos dword [edi]
jmp reserved_data
reserve_dwords:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rd_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rd_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
rd_value_ok:
cmp eax,0
jl reserve_negative
mov ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_dwords
lea edi,[edi+ecx*4]
jmp reserved_data
cmp eax,0
jl reserve_negative
mov ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_dwords
lea edi,[edi+ecx*4]
jmp reserved_data
zero_dwords:
xor eax,eax
rep stos dword [edi]
jmp reserved_data
xor eax,eax
rep stos dword [edi]
jmp reserved_data
reserve_pwords:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rp_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rp_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
rp_value_ok:
cmp eax,0
jl reserve_negative
mov ecx,eax
shl ecx,1
jc out_of_memory
add ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
cmp eax,0
jl reserve_negative
mov ecx,eax
shl ecx,1
jc out_of_memory
add ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
reserve_qwords:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rq_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rq_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
rq_value_ok:
cmp eax,0
jl reserve_negative
mov ecx,eax
shl ecx,1
jc out_of_memory
mov edx,ecx
shl edx,1
jc out_of_memory
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_dwords
lea edi,[edi+ecx*4]
jmp reserved_data
cmp eax,0
jl reserve_negative
mov ecx,eax
shl ecx,1
jc out_of_memory
mov edx,ecx
shl edx,1
jc out_of_memory
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_dwords
lea edi,[edi+ecx*4]
jmp reserved_data
reserve_twords:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rt_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [next_pass_needed],0
jne rt_value_ok
cmp [value_type],0
jne invalid_use_of_symbol
rt_value_ok:
cmp eax,0
jl reserve_negative
mov ecx,eax
shl ecx,2
jc out_of_memory
add ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
cmp eax,0
jl reserve_negative
mov ecx,eax
shl ecx,2
jc out_of_memory
add ecx,eax
mov edx,ecx
shl edx,1
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je zero_words
lea edi,[edi+ecx*2]
jmp reserved_data
align_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,eax
dec edx
test eax,edx
jnz negative_times
or eax,eax
jz negative_times
cmp eax,1
je instruction_assembled
mov ecx,edi
sub ecx,dword [org_origin]
cmp [org_registers],0
jne section_not_aligned_enough
cmp [labels_type],0
je make_alignment
cmp [output_format],3
je pe_alignment
mov ebx,[org_symbol]
cmp byte [ebx],0
jne section_not_aligned_enough
cmp eax,[ebx+10h]
jbe make_alignment
jmp section_not_aligned_enough
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,eax
dec edx
test eax,edx
jnz negative_times
or eax,eax
jz negative_times
cmp eax,1
je instruction_assembled
mov ecx,edi
sub ecx,dword [org_origin]
cmp [org_registers],0
jne section_not_aligned_enough
cmp [labels_type],0
je make_alignment
cmp [output_format],3
je pe_alignment
mov ebx,[org_symbol]
cmp byte [ebx],0
jne section_not_aligned_enough
cmp eax,[ebx+10h]
jbe make_alignment
jmp section_not_aligned_enough
pe_alignment:
cmp eax,1000h
ja section_not_aligned_enough
cmp eax,1000h
ja section_not_aligned_enough
make_alignment:
dec eax
and ecx,eax
jz instruction_assembled
neg ecx
add ecx,eax
inc ecx
mov edx,ecx
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je nops
add edi,ecx
jmp reserved_data
dec eax
and ecx,eax
jz instruction_assembled
neg ecx
add ecx,eax
inc ecx
mov edx,ecx
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
ja out_of_memory
push edi
cmp [next_pass_needed],0
je nops
add edi,ecx
jmp reserved_data
nops:
mov eax,90909090h
shr ecx,1
jnc nops_stosb_ok
stos byte [edi]
mov eax,90909090h
shr ecx,1
jnc nops_stosb_ok
stos byte [edi]
nops_stosb_ok:
shr ecx,1
jnc nops_stosw_ok
stos word [edi]
shr ecx,1
jnc nops_stosw_ok
stos word [edi]
nops_stosw_ok:
rep stos dword [edi]
jmp reserved_data
rep stos dword [edi]
jmp reserved_data
/programs/develop/fasm/trunk/build_en.bat
1,4 → 1,5
@erase lang.inc
@echo lang fix en >lang.inc
@fasm fasm.asm fasm
@erase lang.inc
@pause
/programs/develop/fasm/trunk/build_ru.bat
1,4 → 1,5
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm fasm.asm fasm
@erase lang.inc
@pause
/programs/develop/fasm/trunk/expressi.inc
4,2685 → 4,2691
; All rights reserved.
 
convert_expression:
push ebp
call get_fp_value
jnc fp_expression
mov [current_offset],esp
push ebp
call get_fp_value
jnc fp_expression
mov [current_offset],esp
expression_loop:
push edi
mov edi,single_operand_operators
call get_operator
pop edi
or al,al
jz expression_element
push eax
jmp expression_loop
push edi
mov edi,single_operand_operators
call get_operator
pop edi
or al,al
jz expression_element
push eax
jmp expression_loop
expression_element:
mov al,[esi]
cmp al,1Ah
je expression_number
cmp al,22h
je expression_number
cmp al,'('
je expression_number
mov al,'!'
stos byte [edi]
jmp expression_operator
mov al,[esi]
cmp al,1Ah
je expression_number
cmp al,22h
je expression_number
cmp al,'('
je expression_number
mov al,'!'
stos byte [edi]
jmp expression_operator
expression_number:
call convert_number
call convert_number
expression_operator:
push edi
mov edi,operators
call get_operator
pop edi
or al,al
jz expression_end
push edi
mov edi,operators
call get_operator
pop edi
or al,al
jz expression_end
operators_loop:
cmp esp,[current_offset]
je push_operator
mov bl,al
and bl,0F0h
mov bh,byte [esp]
and bh,0F0h
cmp bl,bh
ja push_operator
pop ebx
mov byte [edi],bl
inc edi
jmp operators_loop
cmp esp,[current_offset]
je push_operator
mov bl,al
and bl,0F0h
mov bh,byte [esp]
and bh,0F0h
cmp bl,bh
ja push_operator
pop ebx
mov byte [edi],bl
inc edi
jmp operators_loop
push_operator:
push eax
jmp expression_loop
push eax
jmp expression_loop
expression_end:
cmp esp,[current_offset]
je expression_converted
pop eax
stos byte [edi]
jmp expression_end
cmp esp,[current_offset]
je expression_converted
pop eax
stos byte [edi]
jmp expression_end
expression_converted:
pop ebp
ret
pop ebp
ret
fp_expression:
mov al,'.'
stos byte [edi]
mov eax,[fp_value]
stos dword [edi]
mov eax,[fp_value+4]
stos dword [edi]
mov eax,[fp_value+8]
stos dword [edi]
pop ebp
ret
mov al,'.'
stos byte [edi]
mov eax,[fp_value]
stos dword [edi]
mov eax,[fp_value+4]
stos dword [edi]
mov eax,[fp_value+8]
stos dword [edi]
pop ebp
ret
 
convert_number:
lea eax,[edi-10h]
cmp eax,[labels_list]
jae out_of_memory
cmp byte [esi],'('
je expression_value
inc edi
call get_number
jc symbol_value
or ebp,ebp
jz valid_number
mov byte [edi-1],0Fh
ret
lea eax,[edi-10h]
cmp eax,[labels_list]
jae out_of_memory
cmp byte [esi],'('
je expression_value
inc edi
call get_number
jc symbol_value
or ebp,ebp
jz valid_number
mov byte [edi-1],0Fh
ret
valid_number:
cmp dword [edi+4],0
jne qword_number
cmp word [edi+2],0
jne dword_number
cmp byte [edi+1],0
jne word_number
cmp dword [edi+4],0
jne qword_number
cmp word [edi+2],0
jne dword_number
cmp byte [edi+1],0
jne word_number
byte_number:
mov byte [edi-1],1
inc edi
ret
mov byte [edi-1],1
inc edi
ret
qword_number:
mov byte [edi-1],8
add edi,8
ret
mov byte [edi-1],8
add edi,8
ret
dword_number:
mov byte [edi-1],4
scas dword [edi]
ret
mov byte [edi-1],4
scas dword [edi]
ret
word_number:
mov byte [edi-1],2
scas word [edi]
ret
mov byte [edi-1],2
scas word [edi]
ret
expression_value:
mov eax,esp
sub eax,100h
jc stack_overflow
cmp eax,[stack_limit]
jb stack_overflow
inc esi
push [current_offset]
call convert_expression
pop [current_offset]
lods byte [esi]
cmp al,')'
jne invalid_expression
ret
mov eax,esp
sub eax,100h
jc stack_overflow
cmp eax,[stack_limit]
jb stack_overflow
inc esi
push [current_offset]
call convert_expression
pop [current_offset]
lods byte [esi]
cmp al,')'
jne invalid_expression
ret
symbol_value:
push edi
mov edi,address_registers
call get_operator
or al,al
jnz register_value
mov edi,directive_operators
call get_operator
pop edi
or al,al
jnz broken_value
lods byte [esi]
cmp al,1Ah
jne invalid_value
lods byte [esi]
movzx ecx,al
call get_label_id
push edi
mov edi,address_registers
call get_operator
or al,al
jnz register_value
mov edi,directive_operators
call get_operator
pop edi
or al,al
jnz broken_value
lods byte [esi]
cmp al,1Ah
jne invalid_value
lods byte [esi]
movzx ecx,al
call get_label_id
store_label_value:
mov byte [edi-1],11h
stos dword [edi]
ret
mov byte [edi-1],11h
stos dword [edi]
ret
broken_value:
mov eax,0Fh
jmp store_label_value
mov eax,0Fh
jmp store_label_value
register_value:
pop edi
mov byte [edi-1],10h
stos byte [edi]
ret
pop edi
mov byte [edi-1],10h
stos byte [edi]
ret
 
get_number:
xor ebp,ebp
lods byte [esi]
cmp al,22h
je get_text_number
cmp al,1Ah
jne not_number
lods byte [esi]
movzx ecx,al
mov [number_start],esi
mov al,[esi]
cmp al,'$'
je number_begin
sub al,30h
cmp al,9
ja invalid_number
xor ebp,ebp
lods byte [esi]
cmp al,22h
je get_text_number
cmp al,1Ah
jne not_number
lods byte [esi]
movzx ecx,al
mov [number_start],esi
mov al,[esi]
cmp al,'$'
je number_begin
sub al,30h
cmp al,9
ja invalid_number
number_begin:
mov ebx,esi
add esi,ecx
push esi
dec esi
mov dword [edi],0
mov dword [edi+4],0
cmp byte [ebx],'$'
je pascal_hex_number
cmp word [ebx],'0x'
je get_hex_number
mov al,[esi]
dec esi
cmp al,'h'
je get_hex_number
cmp al,'b'
je get_bin_number
cmp al,'d'
je get_dec_number
cmp al,'o'
je get_oct_number
cmp al,'H'
je get_hex_number
cmp al,'B'
je get_bin_number
cmp al,'D'
je get_dec_number
cmp al,'O'
je get_oct_number
inc esi
mov ebx,esi
add esi,ecx
push esi
dec esi
mov dword [edi],0
mov dword [edi+4],0
cmp byte [ebx],'$'
je pascal_hex_number
cmp word [ebx],'0x'
je get_hex_number
mov al,[esi]
dec esi
cmp al,'h'
je get_hex_number
cmp al,'b'
je get_bin_number
cmp al,'d'
je get_dec_number
cmp al,'o'
je get_oct_number
cmp al,'H'
je get_hex_number
cmp al,'B'
je get_bin_number
cmp al,'D'
je get_dec_number
cmp al,'O'
je get_oct_number
inc esi
get_dec_number:
mov ebx,esi
mov esi,[number_start]
mov ebx,esi
mov esi,[number_start]
get_dec_digit:
cmp esi,ebx
ja number_ok
xor edx,edx
mov eax,[edi]
shld edx,eax,2
shl eax,2
add eax,[edi]
adc edx,0
add eax,eax
adc edx,edx
mov [edi],eax
mov eax,[edi+4]
add eax,eax
jc dec_out_of_range
add eax,eax
jc dec_out_of_range
add eax,[edi+4]
jc dec_out_of_range
add eax,eax
jc dec_out_of_range
add eax,edx
jc dec_out_of_range
mov [edi+4],eax
movzx eax,byte [esi]
sub al,30h
cmp al,9
ja bad_number
add [edi],eax
adc dword [edi+4],0
jc dec_out_of_range
inc esi
jmp get_dec_digit
cmp esi,ebx
ja number_ok
xor edx,edx
mov eax,[edi]
shld edx,eax,2
shl eax,2
add eax,[edi]
adc edx,0
add eax,eax
adc edx,edx
mov [edi],eax
mov eax,[edi+4]
add eax,eax
jc dec_out_of_range
add eax,eax
jc dec_out_of_range
add eax,[edi+4]
jc dec_out_of_range
add eax,eax
jc dec_out_of_range
add eax,edx
jc dec_out_of_range
mov [edi+4],eax
movzx eax,byte [esi]
sub al,30h
cmp al,9
ja bad_number
add [edi],eax
adc dword [edi+4],0
jc dec_out_of_range
inc esi
jmp get_dec_digit
dec_out_of_range:
or ebp,-1
inc esi
jmp get_dec_digit
or ebp,-1
inc esi
jmp get_dec_digit
bad_number:
pop eax
pop eax
invalid_number:
mov esi,[number_start]
dec esi
mov esi,[number_start]
dec esi
not_number:
dec esi
stc
ret
dec esi
stc
ret
get_bin_number:
xor bl,bl
xor bl,bl
get_bin_digit:
cmp esi,[number_start]
jb number_ok
movzx eax,byte [esi]
sub al,30h
cmp al,1
ja bad_number
xor edx,edx
mov cl,bl
dec esi
cmp bl,64
je bin_out_of_range
inc bl
cmp cl,32
jae bin_digit_high
shl eax,cl
or dword [edi],eax
jmp get_bin_digit
cmp esi,[number_start]
jb number_ok
movzx eax,byte [esi]
sub al,30h
cmp al,1
ja bad_number
xor edx,edx
mov cl,bl
dec esi
cmp bl,64
je bin_out_of_range
inc bl
cmp cl,32
jae bin_digit_high
shl eax,cl
or dword [edi],eax
jmp get_bin_digit
bin_digit_high:
sub cl,32
shl eax,cl
or dword [edi+4],eax
jmp get_bin_digit
sub cl,32
shl eax,cl
or dword [edi+4],eax
jmp get_bin_digit
bin_out_of_range:
or al,al
jz get_bin_digit
or ebp,-1
jmp get_bin_digit
or al,al
jz get_bin_digit
or ebp,-1
jmp get_bin_digit
pascal_hex_number:
cmp cl,1
je bad_number
cmp cl,1
je bad_number
get_hex_number:
xor bl,bl
xor bl,bl
get_hex_digit:
cmp esi,[number_start]
jb number_ok
movzx eax,byte [esi]
cmp al,'x'
je hex_number_ok
cmp al,'$'
je pascal_hex_ok
sub al,30h
cmp al,9
jbe hex_digit_ok
sub al,7
cmp al,15
jbe hex_letter_digit_ok
sub al,20h
cmp al,15
ja bad_number
cmp esi,[number_start]
jb number_ok
movzx eax,byte [esi]
cmp al,'x'
je hex_number_ok
cmp al,'$'
je pascal_hex_ok
sub al,30h
cmp al,9
jbe hex_digit_ok
sub al,7
cmp al,15
jbe hex_letter_digit_ok
sub al,20h
cmp al,15
ja bad_number
hex_letter_digit_ok:
cmp al,10
jb bad_number
cmp al,10
jb bad_number
hex_digit_ok:
xor edx,edx
mov cl,bl
dec esi
cmp bl,64
je hex_out_of_range
add bl,4
cmp cl,32
jae hex_digit_high
shl eax,cl
or dword [edi],eax
jmp get_hex_digit
xor edx,edx
mov cl,bl
dec esi
cmp bl,64
je hex_out_of_range
add bl,4
cmp cl,32
jae hex_digit_high
shl eax,cl
or dword [edi],eax
jmp get_hex_digit
hex_digit_high:
sub cl,32
shl eax,cl
or dword [edi+4],eax
jmp get_hex_digit
sub cl,32
shl eax,cl
or dword [edi+4],eax
jmp get_hex_digit
hex_out_of_range:
or al,al
jz get_hex_digit
or ebp,-1
jmp get_hex_digit
or al,al
jz get_hex_digit
or ebp,-1
jmp get_hex_digit
get_oct_number:
xor bl,bl
xor bl,bl
get_oct_digit:
cmp esi,[number_start]
jb number_ok
movzx eax,byte [esi]
sub al,30h
cmp al,7
ja bad_number
cmp esi,[number_start]
jb number_ok
movzx eax,byte [esi]
sub al,30h
cmp al,7
ja bad_number
oct_digit_ok:
xor edx,edx
mov cl,bl
dec esi
cmp bl,64
jae oct_out_of_range
add bl,3
cmp cl,30
je oct_digit_wrap
ja oct_digit_high
shl eax,cl
or dword [edi],eax
jmp get_oct_digit
xor edx,edx
mov cl,bl
dec esi
cmp bl,64
jae oct_out_of_range
add bl,3
cmp cl,30
je oct_digit_wrap
ja oct_digit_high
shl eax,cl
or dword [edi],eax
jmp get_oct_digit
oct_digit_wrap:
shl eax,cl
adc dword [edi+4],0
or dword [edi],eax
jmp get_oct_digit
shl eax,cl
adc dword [edi+4],0
or dword [edi],eax
jmp get_oct_digit
oct_digit_high:
sub cl,32
shl eax,cl
or dword [edi+4],eax
jmp get_oct_digit
sub cl,32
shl eax,cl
or dword [edi+4],eax
jmp get_oct_digit
oct_out_of_range:
or al,al
jz get_oct_digit
or ebp,-1
jmp get_oct_digit
or al,al
jz get_oct_digit
or ebp,-1
jmp get_oct_digit
hex_number_ok:
dec esi
dec esi
pascal_hex_ok:
cmp esi,[number_start]
jne bad_number
cmp esi,[number_start]
jne bad_number
number_ok:
pop esi
pop esi
number_done:
clc
ret
clc
ret
get_text_number:
lods dword [esi]
mov edx,eax
xor bl,bl
mov dword [edi],0
mov dword [edi+4],0
lods dword [esi]
mov edx,eax
xor bl,bl
mov dword [edi],0
mov dword [edi+4],0
get_text_character:
sub edx,1
jc number_done
movzx eax,byte [esi]
inc esi
mov cl,bl
cmp bl,64
je text_out_of_range
add bl,8
cmp cl,32
jae text_character_high
shl eax,cl
or dword [edi],eax
jmp get_text_character
sub edx,1
jc number_done
movzx eax,byte [esi]
inc esi
mov cl,bl
cmp bl,64
je text_out_of_range
add bl,8
cmp cl,32
jae text_character_high
shl eax,cl
or dword [edi],eax
jmp get_text_character
text_character_high:
sub cl,32
shl eax,cl
or dword [edi+4],eax
jmp get_text_character
sub cl,32
shl eax,cl
or dword [edi+4],eax
jmp get_text_character
text_out_of_range:
or ebp,-1
jmp get_text_character
or ebp,-1
jmp get_text_character
 
get_fp_value:
push edi esi
lods byte [esi]
cmp al,1Ah
je fp_value_start
cmp al,'-'
je fp_sign_ok
cmp al,'+'
jne not_fp_value
push edi esi
lods byte [esi]
cmp al,1Ah
je fp_value_start
cmp al,'-'
je fp_sign_ok
cmp al,'+'
jne not_fp_value
fp_sign_ok:
lods byte [esi]
cmp al,1Ah
jne not_fp_value
lods byte [esi]
cmp al,1Ah
jne not_fp_value
fp_value_start:
lods byte [esi]
movzx ecx,al
cmp cl,1
jbe not_fp_value
lea edx,[esi+1]
xor ah,ah
lods byte [esi]
movzx ecx,al
cmp cl,1
jbe not_fp_value
lea edx,[esi+1]
xor ah,ah
check_fp_value:
lods byte [esi]
cmp al,'.'
je fp_character_dot
cmp al,'E'
je fp_character_exp
cmp al,'e'
je fp_character_exp
cmp al,'F'
je fp_last_character
cmp al,'f'
je fp_last_character
lods byte [esi]
cmp al,'.'
je fp_character_dot
cmp al,'E'
je fp_character_exp
cmp al,'e'
je fp_character_exp
cmp al,'F'
je fp_last_character
cmp al,'f'
je fp_last_character
digit_expected:
cmp al,'0'
jb not_fp_value
cmp al,'9'
ja not_fp_value
jmp fp_character_ok
cmp al,'0'
jb not_fp_value
cmp al,'9'
ja not_fp_value
jmp fp_character_ok
fp_character_dot:
cmp esi,edx
je not_fp_value
or ah,ah
jnz not_fp_value
or ah,1
lods byte [esi]
loop digit_expected
cmp esi,edx
je not_fp_value
or ah,ah
jnz not_fp_value
or ah,1
lods byte [esi]
loop digit_expected
not_fp_value:
pop esi edi
stc
ret
pop esi edi
stc
ret
fp_last_character:
cmp cl,1
jne not_fp_value
or ah,4
jmp fp_character_ok
cmp cl,1
jne not_fp_value
or ah,4
jmp fp_character_ok
fp_character_exp:
cmp esi,edx
je not_fp_value
cmp ah,1
ja not_fp_value
or ah,2
cmp ecx,1
jne fp_character_ok
cmp byte [esi],'+'
je fp_exp_sign
cmp byte [esi],'-'
jne fp_character_ok
cmp esi,edx
je not_fp_value
cmp ah,1
ja not_fp_value
or ah,2
cmp ecx,1
jne fp_character_ok
cmp byte [esi],'+'
je fp_exp_sign
cmp byte [esi],'-'
jne fp_character_ok
fp_exp_sign:
inc esi
cmp byte [esi],1Ah
jne not_fp_value
inc esi
lods byte [esi]
movzx ecx,al
inc ecx
inc esi
cmp byte [esi],1Ah
jne not_fp_value
inc esi
lods byte [esi]
movzx ecx,al
inc ecx
fp_character_ok:
dec ecx
jnz check_fp_value
or ah,ah
jz not_fp_value
pop esi
lods byte [esi]
mov [fp_sign],0
cmp al,1Ah
je fp_get
inc esi
cmp al,'+'
je fp_get
mov [fp_sign],1
dec ecx
jnz check_fp_value
or ah,ah
jz not_fp_value
pop esi
lods byte [esi]
mov [fp_sign],0
cmp al,1Ah
je fp_get
inc esi
cmp al,'+'
je fp_get
mov [fp_sign],1
fp_get:
lods byte [esi]
movzx ecx,al
xor edx,edx
mov edi,fp_value
mov [edi],edx
mov [edi+4],edx
mov [edi+12],edx
call fp_optimize
mov [fp_format],0
mov al,[esi]
lods byte [esi]
movzx ecx,al
xor edx,edx
mov edi,fp_value
mov [edi],edx
mov [edi+4],edx
mov [edi+12],edx
call fp_optimize
mov [fp_format],0
mov al,[esi]
fp_before_dot:
lods byte [esi]
cmp al,'.'
je fp_dot
cmp al,'E'
je fp_exponent
cmp al,'e'
je fp_exponent
cmp al,'F'
je fp_done
cmp al,'f'
je fp_done
sub al,30h
mov edi,fp_value+16
xor edx,edx
mov dword [edi+12],edx
mov dword [edi],edx
mov dword [edi+4],edx
mov [edi+7],al
mov dl,7
mov dword [edi+8],edx
call fp_optimize
mov edi,fp_value
push ecx
mov ecx,10
call fp_mul
pop ecx
mov ebx,fp_value+16
call fp_add
loop fp_before_dot
lods byte [esi]
cmp al,'.'
je fp_dot
cmp al,'E'
je fp_exponent
cmp al,'e'
je fp_exponent
cmp al,'F'
je fp_done
cmp al,'f'
je fp_done
sub al,30h
mov edi,fp_value+16
xor edx,edx
mov dword [edi+12],edx
mov dword [edi],edx
mov dword [edi+4],edx
mov [edi+7],al
mov dl,7
mov dword [edi+8],edx
call fp_optimize
mov edi,fp_value
push ecx
mov ecx,10
call fp_mul
pop ecx
mov ebx,fp_value+16
call fp_add
loop fp_before_dot
fp_dot:
mov edi,fp_value+16
xor edx,edx
mov [edi],edx
mov [edi+4],edx
mov byte [edi+7],80h
mov [edi+8],edx
mov dword [edi+12],edx
dec ecx
jz fp_done
mov edi,fp_value+16
xor edx,edx
mov [edi],edx
mov [edi+4],edx
mov byte [edi+7],80h
mov [edi+8],edx
mov dword [edi+12],edx
dec ecx
jz fp_done
fp_after_dot:
lods byte [esi]
cmp al,'E'
je fp_exponent
cmp al,'e'
je fp_exponent
cmp al,'F'
je fp_done
cmp al,'f'
je fp_done
inc [fp_format]
cmp [fp_format],80h
jne fp_counter_ok
mov [fp_format],7Fh
lods byte [esi]
cmp al,'E'
je fp_exponent
cmp al,'e'
je fp_exponent
cmp al,'F'
je fp_done
cmp al,'f'
je fp_done
inc [fp_format]
cmp [fp_format],80h
jne fp_counter_ok
mov [fp_format],7Fh
fp_counter_ok:
dec esi
mov edi,fp_value+16
push ecx
mov ecx,10
call fp_div
push dword [edi]
push dword [edi+4]
push dword [edi+8]
push dword [edi+12]
lods byte [esi]
sub al,30h
movzx ecx,al
call fp_mul
mov ebx,edi
mov edi,fp_value
call fp_add
mov edi,fp_value+16
pop dword [edi+12]
pop dword [edi+8]
pop dword [edi+4]
pop dword [edi]
pop ecx
loop fp_after_dot
jmp fp_done
dec esi
mov edi,fp_value+16
push ecx
mov ecx,10
call fp_div
push dword [edi]
push dword [edi+4]
push dword [edi+8]
push dword [edi+12]
lods byte [esi]
sub al,30h
movzx ecx,al
call fp_mul
mov ebx,edi
mov edi,fp_value
call fp_add
mov edi,fp_value+16
pop dword [edi+12]
pop dword [edi+8]
pop dword [edi+4]
pop dword [edi]
pop ecx
loop fp_after_dot
jmp fp_done
fp_exponent:
or [fp_format],80h
xor edx,edx
xor ebp,ebp
dec ecx
jnz get_exponent
cmp byte [esi],'+'
je fp_exponent_sign
cmp byte [esi],'-'
jne fp_done
not ebp
or [fp_format],80h
xor edx,edx
xor ebp,ebp
dec ecx
jnz get_exponent
cmp byte [esi],'+'
je fp_exponent_sign
cmp byte [esi],'-'
jne fp_done
not ebp
fp_exponent_sign:
add esi,2
lods byte [esi]
movzx ecx,al
add esi,2
lods byte [esi]
movzx ecx,al
get_exponent:
movzx eax,byte [esi]
inc esi
sub al,30h
cmp al,10
jae exponent_ok
imul edx,10
cmp edx,8000h
jae value_out_of_range
add edx,eax
loop get_exponent
movzx eax,byte [esi]
inc esi
sub al,30h
cmp al,10
jae exponent_ok
imul edx,10
cmp edx,8000h
jae value_out_of_range
add edx,eax
loop get_exponent
exponent_ok:
mov edi,fp_value
or edx,edx
jz fp_done
mov ecx,edx
or ebp,ebp
jnz fp_negative_power
mov edi,fp_value
or edx,edx
jz fp_done
mov ecx,edx
or ebp,ebp
jnz fp_negative_power
fp_power:
push ecx
mov ecx,10
call fp_mul
pop ecx
loop fp_power
jmp fp_done
push ecx
mov ecx,10
call fp_mul
pop ecx
loop fp_power
jmp fp_done
fp_negative_power:
push ecx
mov ecx,10
call fp_div
pop ecx
loop fp_negative_power
push ecx
mov ecx,10
call fp_div
pop ecx
loop fp_negative_power
fp_done:
mov edi,fp_value
mov al,[fp_format]
mov [edi+10],al
mov al,[fp_sign]
mov [edi+11],al
test byte [edi+15],80h
jz fp_ok
add dword [edi],1
adc dword [edi+4],0
jnc fp_ok
mov eax,[edi+4]
shrd [edi],eax,1
shr eax,1
or eax,80000000h
mov [edi+4],eax
inc word [edi+8]
mov edi,fp_value
mov al,[fp_format]
mov [edi+10],al
mov al,[fp_sign]
mov [edi+11],al
test byte [edi+15],80h
jz fp_ok
add dword [edi],1
adc dword [edi+4],0
jnc fp_ok
mov eax,[edi+4]
shrd [edi],eax,1
shr eax,1
or eax,80000000h
mov [edi+4],eax
inc word [edi+8]
fp_ok:
pop edi
clc
ret
pop edi
clc
ret
fp_mul:
or ecx,ecx
jz fp_zero
mov eax,[edi+12]
mul ecx
mov [edi+12],eax
mov ebx,edx
mov eax,[edi]
mul ecx
add eax,ebx
adc edx,0
mov [edi],eax
mov ebx,edx
mov eax,[edi+4]
mul ecx
add eax,ebx
adc edx,0
mov [edi+4],eax
or ecx,ecx
jz fp_zero
mov eax,[edi+12]
mul ecx
mov [edi+12],eax
mov ebx,edx
mov eax,[edi]
mul ecx
add eax,ebx
adc edx,0
mov [edi],eax
mov ebx,edx
mov eax,[edi+4]
mul ecx
add eax,ebx
adc edx,0
mov [edi+4],eax
.loop:
or edx,edx
jz .done
mov eax,[edi]
shrd [edi+12],eax,1
mov eax,[edi+4]
shrd [edi],eax,1
shrd eax,edx,1
mov [edi+4],eax
shr edx,1
inc dword [edi+8]
cmp dword [edi+8],8000h
jge value_out_of_range
jmp .loop
or edx,edx
jz .done
mov eax,[edi]
shrd [edi+12],eax,1
mov eax,[edi+4]
shrd [edi],eax,1
shrd eax,edx,1
mov [edi+4],eax
shr edx,1
inc dword [edi+8]
cmp dword [edi+8],8000h
jge value_out_of_range
jmp .loop
.done:
ret
ret
fp_div:
mov eax,[edi+4]
xor edx,edx
div ecx
mov [edi+4],eax
mov eax,[edi]
div ecx
mov [edi],eax
mov eax,[edi+12]
div ecx
mov [edi+12],eax
mov ebx,eax
or ebx,[edi]
or ebx,[edi+4]
jz fp_zero
mov eax,[edi+4]
xor edx,edx
div ecx
mov [edi+4],eax
mov eax,[edi]
div ecx
mov [edi],eax
mov eax,[edi+12]
div ecx
mov [edi+12],eax
mov ebx,eax
or ebx,[edi]
or ebx,[edi+4]
jz fp_zero
.loop:
test byte [edi+7],80h
jnz .exp_ok
mov eax,[edi]
shld [edi+4],eax,1
mov eax,[edi+12]
shld [edi],eax,1
add eax,eax
mov [edi+12],eax
dec dword [edi+8]
add edx,edx
jmp .loop
test byte [edi+7],80h
jnz .exp_ok
mov eax,[edi]
shld [edi+4],eax,1
mov eax,[edi+12]
shld [edi],eax,1
add eax,eax
mov [edi+12],eax
dec dword [edi+8]
add edx,edx
jmp .loop
.exp_ok:
mov eax,edx
xor edx,edx
div ecx
add [edi+12],eax
adc dword [edi],0
adc dword [edi+4],0
jnc .done
mov eax,[edi+4]
mov ebx,[edi]
shrd [edi],eax,1
shrd [edi+12],ebx,1
shr eax,1
or eax,80000000h
mov [edi+4],eax
inc dword [edi+8]
mov eax,edx
xor edx,edx
div ecx
add [edi+12],eax
adc dword [edi],0
adc dword [edi+4],0
jnc .done
mov eax,[edi+4]
mov ebx,[edi]
shrd [edi],eax,1
shrd [edi+12],ebx,1
shr eax,1
or eax,80000000h
mov [edi+4],eax
inc dword [edi+8]
.done:
ret
ret
fp_add:
cmp dword [ebx+8],8000h
je .done
cmp dword [edi+8],8000h
je .copy
mov eax,[ebx+8]
cmp eax,[edi+8]
jge .exp_ok
mov eax,[edi+8]
cmp dword [ebx+8],8000h
je .done
cmp dword [edi+8],8000h
je .copy
mov eax,[ebx+8]
cmp eax,[edi+8]
jge .exp_ok
mov eax,[edi+8]
.exp_ok:
call .change_exp
xchg ebx,edi
call .change_exp
xchg ebx,edi
mov edx,[ebx+12]
mov eax,[ebx]
mov ebx,[ebx+4]
add [edi+12],edx
adc [edi],eax
adc [edi+4],ebx
jnc .done
mov eax,[edi]
shrd [edi+12],eax,1
mov eax,[edi+4]
shrd [edi],eax,1
shr eax,1
or eax,80000000h
mov [edi+4],eax
inc dword [edi+8]
call .change_exp
xchg ebx,edi
call .change_exp
xchg ebx,edi
mov edx,[ebx+12]
mov eax,[ebx]
mov ebx,[ebx+4]
add [edi+12],edx
adc [edi],eax
adc [edi+4],ebx
jnc .done
mov eax,[edi]
shrd [edi+12],eax,1
mov eax,[edi+4]
shrd [edi],eax,1
shr eax,1
or eax,80000000h
mov [edi+4],eax
inc dword [edi+8]
.done:
ret
ret
.copy:
mov eax,[ebx]
mov [edi],eax
mov eax,[ebx+4]
mov [edi+4],eax
mov eax,[ebx+8]
mov [edi+8],eax
mov eax,[ebx+12]
mov [edi+12],eax
ret
mov eax,[ebx]
mov [edi],eax
mov eax,[ebx+4]
mov [edi+4],eax
mov eax,[ebx+8]
mov [edi+8],eax
mov eax,[ebx+12]
mov [edi+12],eax
ret
.change_exp:
push ecx
mov ecx,eax
sub ecx,[ebx+8]
mov edx,[ebx+4]
jecxz .exp_done
push ecx
mov ecx,eax
sub ecx,[ebx+8]
mov edx,[ebx+4]
jecxz .exp_done
.exp_loop:
mov ebp,[ebx]
shrd [ebx+12],ebp,1
shrd [ebx],edx,1
shr edx,1
inc dword [ebx+8]
loop .exp_loop
mov ebp,[ebx]
shrd [ebx+12],ebp,1
shrd [ebx],edx,1
shr edx,1
inc dword [ebx+8]
loop .exp_loop
.exp_done:
mov [ebx+4],edx
pop ecx
ret
mov [ebx+4],edx
pop ecx
ret
fp_optimize:
mov eax,[edi]
mov ebp,[edi+4]
or ebp,[edi]
or ebp,[edi+12]
jz fp_zero
mov eax,[edi]
mov ebp,[edi+4]
or ebp,[edi]
or ebp,[edi+12]
jz fp_zero
.loop:
test byte [edi+7],80h
jnz .done
shld [edi+4],eax,1
mov ebp,[edi+12]
shld eax,ebp,1
mov [edi],eax
shl dword [edi+12],1
dec dword [edi+8]
jmp .loop
test byte [edi+7],80h
jnz .done
shld [edi+4],eax,1
mov ebp,[edi+12]
shld eax,ebp,1
mov [edi],eax
shl dword [edi+12],1
dec dword [edi+8]
jmp .loop
.done:
ret
ret
fp_zero:
mov dword [edi+8],8000h
ret
mov dword [edi+8],8000h
ret
 
calculate_expression:
mov [current_offset],edi
mov [value_undefined],0
cmp byte [esi],0
je get_string_value
cmp byte [esi],'.'
je convert_fp
mov [current_offset],edi
mov [value_undefined],0
cmp byte [esi],0
je get_string_value
cmp byte [esi],'.'
je convert_fp
calculation_loop:
lods byte [esi]
cmp al,1
je get_byte_number
cmp al,2
je get_word_number
cmp al,4
je get_dword_number
cmp al,8
je get_qword_number
cmp al,0Fh
je value_out_of_range
cmp al,10h
je get_register
cmp al,11h
je get_label
cmp al,')'
je expression_calculated
cmp al,']'
je expression_calculated
cmp al,'!'
je invalid_expression
sub edi,14h
mov ebx,edi
sub ebx,14h
cmp al,0E0h
je calculate_rva
cmp al,0D0h
je calculate_not
cmp al,083h
je calculate_neg
mov dx,[ebx+8]
or dx,[edi+8]
cmp al,80h
je calculate_add
cmp al,81h
je calculate_sub
mov ah,[ebx+12]
or ah,[edi+12]
jz absolute_values_calculation
cmp [error_line],0
jne absolute_values_calculation
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
lods byte [esi]
cmp al,1
je get_byte_number
cmp al,2
je get_word_number
cmp al,4
je get_dword_number
cmp al,8
je get_qword_number
cmp al,0Fh
je value_out_of_range
cmp al,10h
je get_register
cmp al,11h
je get_label
cmp al,')'
je expression_calculated
cmp al,']'
je expression_calculated
cmp al,'!'
je invalid_expression
sub edi,14h
mov ebx,edi
sub ebx,14h
cmp al,0E0h
je calculate_rva
cmp al,0D0h
je calculate_not
cmp al,083h
je calculate_neg
mov dx,[ebx+8]
or dx,[edi+8]
cmp al,80h
je calculate_add
cmp al,81h
je calculate_sub
mov ah,[ebx+12]
or ah,[edi+12]
jz absolute_values_calculation
cmp [error_line],0
jne absolute_values_calculation
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
absolute_values_calculation:
cmp al,90h
je calculate_mul
cmp al,91h
je calculate_div
or dx,dx
jnz invalid_expression
cmp al,0A0h
je calculate_mod
cmp al,0B0h
je calculate_and
cmp al,0B1h
je calculate_or
cmp al,0B2h
je calculate_xor
cmp al,0C0h
je calculate_shl
cmp al,0C1h
je calculate_shr
jmp invalid_expression
cmp al,90h
je calculate_mul
cmp al,91h
je calculate_div
or dx,dx
jnz invalid_expression
cmp al,0A0h
je calculate_mod
cmp al,0B0h
je calculate_and
cmp al,0B1h
je calculate_or
cmp al,0B2h
je calculate_xor
cmp al,0C0h
je calculate_shl
cmp al,0C1h
je calculate_shr
jmp invalid_expression
expression_calculated:
sub edi,14h
cmp [value_undefined],0
je expression_value_ok
xor eax,eax
mov [edi],eax
mov [edi+4],eax
mov [edi+12],al
sub edi,14h
cmp [value_undefined],0
je expression_value_ok
xor eax,eax
mov [edi],eax
mov [edi+4],eax
mov [edi+12],al
expression_value_ok:
ret
ret
get_byte_number:
mov word [edi+8],0
mov byte [edi+12],0
xor eax,eax
lods byte [esi]
stos dword [edi]
xor al,al
stos dword [edi]
add edi,0Ch
jmp calculation_loop
mov word [edi+8],0
mov byte [edi+12],0
xor eax,eax
lods byte [esi]
stos dword [edi]
xor al,al
stos dword [edi]
add edi,0Ch
jmp calculation_loop
get_word_number:
mov word [edi+8],0
mov byte [edi+12],0
xor eax,eax
lods word [esi]
stos dword [edi]
xor ax,ax
stos dword [edi]
add edi,0Ch
jmp calculation_loop
mov word [edi+8],0
mov byte [edi+12],0
xor eax,eax
lods word [esi]
stos dword [edi]
xor ax,ax
stos dword [edi]
add edi,0Ch
jmp calculation_loop
get_dword_number:
mov word [edi+8],0
mov byte [edi+12],0
movs dword [edi],[esi]
xor eax,eax
stos dword [edi]
add edi,0Ch
jmp calculation_loop
mov word [edi+8],0
mov byte [edi+12],0
movs dword [edi],[esi]
xor eax,eax
stos dword [edi]
add edi,0Ch
jmp calculation_loop
get_qword_number:
mov word [edi+8],0
mov byte [edi+12],0
movs dword [edi],[esi]
movs dword [edi],[esi]
add edi,0Ch
jmp calculation_loop
mov word [edi+8],0
mov byte [edi+12],0
movs dword [edi],[esi]
movs dword [edi],[esi]
add edi,0Ch
jmp calculation_loop
get_register:
mov byte [edi+9],0
mov byte [edi+12],0
lods byte [esi]
mov [edi+8],al
mov byte [edi+10],1
xor eax,eax
stos dword [edi]
stos dword [edi]
add edi,0Ch
jmp calculation_loop
mov byte [edi+9],0
mov byte [edi+12],0
lods byte [esi]
mov [edi+8],al
mov byte [edi+10],1
xor eax,eax
stos dword [edi]
stos dword [edi]
add edi,0Ch
jmp calculation_loop
get_label:
xor eax,eax
mov [edi+8],eax
mov [edi+12],al
mov [edi+20],eax
lods dword [esi]
cmp eax,0Fh
jb predefined_label
je reserved_word_used_as_symbol
mov ebx,eax
mov ax,[current_pass]
mov [ebx+18],ax
or byte [ebx+8],8
test byte [ebx+8],1
jz label_undefined
cmp ax,[ebx+16]
je label_defined
test byte [ebx+8],4
jnz label_undefined
test byte [ebx+9],1
jz label_defined
mov eax,[ebx]
sub eax,dword [adjustment]
stos dword [edi]
mov eax,[ebx+4]
sbb eax,dword [adjustment+4]
stos dword [edi]
mov eax,dword [adjustment]
or eax,dword [adjustment+4]
jz got_label
or [next_pass_needed],-1
jmp got_label
xor eax,eax
mov [edi+8],eax
mov [edi+12],al
mov [edi+20],eax
lods dword [esi]
cmp eax,0Fh
jb predefined_label
je reserved_word_used_as_symbol
mov ebx,eax
mov ax,[current_pass]
mov [ebx+18],ax
or byte [ebx+8],8
test byte [ebx+8],1
jz label_undefined
cmp ax,[ebx+16]
je label_defined
test byte [ebx+8],4
jnz label_undefined
test byte [ebx+9],1
jz label_defined
mov eax,[ebx]
sub eax,dword [adjustment]
stos dword [edi]
mov eax,[ebx+4]
sbb eax,dword [adjustment+4]
stos dword [edi]
mov eax,dword [adjustment]
or eax,dword [adjustment+4]
jz got_label
or [next_pass_needed],-1
jmp got_label
label_defined:
mov eax,[ebx]
stos dword [edi]
mov eax,[ebx+4]
stos dword [edi]
mov eax,[ebx]
stos dword [edi]
mov eax,[ebx+4]
stos dword [edi]
got_label:
mov al,[ebx+11]
mov [edi-8+12],al
mov eax,[ebx+12]
mov [edi-8+8],eax
mov eax,[ebx+20]
mov [edi-8+16],eax
add edi,0Ch
mov al,[ebx+10]
or al,al
jz calculation_loop
cmp [size_override],-1
je calculation_loop
cmp [size_override],0
je check_size
cmp [operand_size],0
jne calculation_loop
mov [operand_size],al
jmp calculation_loop
mov al,[ebx+11]
mov [edi-8+12],al
mov eax,[ebx+12]
mov [edi-8+8],eax
mov eax,[ebx+20]
mov [edi-8+16],eax
add edi,0Ch
mov al,[ebx+10]
or al,al
jz calculation_loop
cmp [size_override],-1
je calculation_loop
cmp [size_override],0
je check_size
cmp [operand_size],0
jne calculation_loop
mov [operand_size],al
jmp calculation_loop
check_size:
xchg [operand_size],al
or al,al
jz calculation_loop
cmp al,[operand_size]
jne operand_sizes_do_not_match
jmp calculation_loop
xchg [operand_size],al
or al,al
jz calculation_loop
cmp al,[operand_size]
jne operand_sizes_do_not_match
jmp calculation_loop
current_offset_label:
mov al,[labels_type]
mov [edi+12],al
mov eax,[org_symbol]
mov [edi+16],eax
mov eax,[current_offset]
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
stos dword [edi]
mov eax,edx
stos dword [edi]
mov eax,[org_registers]
stos dword [edi]
add edi,8
jmp calculation_loop
mov al,[labels_type]
mov [edi+12],al
mov eax,[org_symbol]
mov [edi+16],eax
mov eax,[current_offset]
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
stos dword [edi]
mov eax,edx
stos dword [edi]
mov eax,[org_registers]
stos dword [edi]
add edi,8
jmp calculation_loop
org_origin_label:
mov al,[labels_type]
mov [edi+12],al
mov eax,[org_symbol]
mov [edi+16],eax
mov eax,[org_start]
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
stos dword [edi]
mov eax,edx
stos dword [edi]
mov eax,[org_registers]
stos dword [edi]
add edi,8
jmp calculation_loop
mov al,[labels_type]
mov [edi+12],al
mov eax,[org_symbol]
mov [edi+16],eax
mov eax,[org_start]
xor edx,edx
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
stos dword [edi]
mov eax,edx
stos dword [edi]
mov eax,[org_registers]
stos dword [edi]
add edi,8
jmp calculation_loop
counter_label:
mov eax,[counter]
mov eax,[counter]
make_dword_label_value:
stos dword [edi]
xor eax,eax
stos dword [edi]
add edi,0Ch
jmp calculation_loop
stos dword [edi]
xor eax,eax
stos dword [edi]
add edi,0Ch
jmp calculation_loop
timestamp_label:
call make_timestamp
jmp make_dword_label_value
call make_timestamp
jmp make_dword_label_value
predefined_label:
or eax,eax
jz current_offset_label
cmp eax,1
je counter_label
cmp eax,2
je timestamp_label
cmp eax,3
je org_origin_label
or eax,eax
jz current_offset_label
cmp eax,1
je counter_label
cmp eax,2
je timestamp_label
cmp eax,3
je org_origin_label
label_undefined:
cmp [current_pass],1
ja undefined_value
cmp [current_pass],1
ja undefined_value
force_next_pass:
or [next_pass_needed],-1
or [next_pass_needed],-1
undefined_value:
mov byte [edi+12],0
or [value_undefined],-1
xor eax,eax
stos dword [edi]
stos dword [edi]
add edi,0Ch
cmp [error_line],0
jne calculation_loop
mov eax,[current_line]
mov [error_line],eax
mov [error],undefined_symbol
jmp calculation_loop
mov byte [edi+12],0
or [value_undefined],-1
xor eax,eax
stos dword [edi]
stos dword [edi]
add edi,0Ch
cmp [error_line],0
jne calculation_loop
mov eax,[current_line]
mov [error_line],eax
mov [error],undefined_symbol
jmp calculation_loop
calculate_add:
mov ecx,[ebx+16]
cmp byte [edi+12],0
je add_values
mov ecx,[edi+16]
cmp byte [ebx+12],0
je add_values
cmp [error_line],0
jne add_values
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
mov ecx,[ebx+16]
cmp byte [edi+12],0
je add_values
mov ecx,[edi+16]
cmp byte [ebx+12],0
je add_values
cmp [error_line],0
jne add_values
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
add_values:
mov al,[edi+12]
or [ebx+12],al
mov [ebx+16],ecx
mov eax,[edi]
add [ebx],eax
mov eax,[edi+4]
adc [ebx+4],eax
or dx,dx
jz calculation_loop
push esi
mov esi,ebx
lea ebx,[edi+10]
mov cl,[edi+8]
call add_register
lea ebx,[edi+11]
mov cl,[edi+9]
call add_register
pop esi
jmp calculation_loop
mov al,[edi+12]
or [ebx+12],al
mov [ebx+16],ecx
mov eax,[edi]
add [ebx],eax
mov eax,[edi+4]
adc [ebx+4],eax
or dx,dx
jz calculation_loop
push esi
mov esi,ebx
lea ebx,[edi+10]
mov cl,[edi+8]
call add_register
lea ebx,[edi+11]
mov cl,[edi+9]
call add_register
pop esi
jmp calculation_loop
add_register:
or cl,cl
jz add_register_done
or cl,cl
jz add_register_done
add_register_start:
cmp [esi+8],cl
jne add_in_second_slot
mov al,[ebx]
add [esi+10],al
jnz add_register_done
mov byte [esi+8],0
ret
cmp [esi+8],cl
jne add_in_second_slot
mov al,[ebx]
add [esi+10],al
jnz add_register_done
mov byte [esi+8],0
ret
add_in_second_slot:
cmp [esi+9],cl
jne create_in_first_slot
mov al,[ebx]
add [esi+11],al
jnz add_register_done
mov byte [esi+9],0
ret
cmp [esi+9],cl
jne create_in_first_slot
mov al,[ebx]
add [esi+11],al
jnz add_register_done
mov byte [esi+9],0
ret
create_in_first_slot:
cmp byte [esi+8],0
jne create_in_second_slot
mov [esi+8],cl
mov al,[ebx]
mov [esi+10],al
ret
cmp byte [esi+8],0
jne create_in_second_slot
mov [esi+8],cl
mov al,[ebx]
mov [esi+10],al
ret
create_in_second_slot:
cmp byte [esi+9],0
jne invalid_expression
mov [esi+9],cl
mov al,[ebx]
mov [esi+11],al
cmp byte [esi+9],0
jne invalid_expression
mov [esi+9],cl
mov al,[ebx]
mov [esi+11],al
add_register_done:
ret
ret
calculate_sub:
xor ah,ah
mov ah,[ebx+12]
mov al,[edi+12]
or al,al
jz sub_values
cmp al,ah
jne invalid_sub
xor ah,ah
mov ecx,[edi+16]
cmp ecx,[ebx+16]
je sub_values
cmp ecx,[org_symbol]
jne invalid_sub
test byte [ebx+12],1
jnz invalid_sub
mov ah,3
xor ah,ah
mov ah,[ebx+12]
mov al,[edi+12]
or al,al
jz sub_values
cmp al,ah
jne invalid_sub
xor ah,ah
mov ecx,[edi+16]
cmp ecx,[ebx+16]
je sub_values
cmp ecx,[org_symbol]
jne invalid_sub
test byte [ebx+12],1
jnz invalid_sub
mov ah,3
sub_values:
mov [ebx+12],ah
mov eax,[edi]
sub [ebx],eax
mov eax,[edi+4]
sbb [ebx+4],eax
or dx,dx
jz calculation_loop
push esi
mov esi,ebx
lea ebx,[edi+10]
mov cl,[edi+8]
call sub_register
lea ebx,[edi+11]
mov cl,[edi+9]
call sub_register
pop esi
jmp calculation_loop
mov [ebx+12],ah
mov eax,[edi]
sub [ebx],eax
mov eax,[edi+4]
sbb [ebx+4],eax
or dx,dx
jz calculation_loop
push esi
mov esi,ebx
lea ebx,[edi+10]
mov cl,[edi+8]
call sub_register
lea ebx,[edi+11]
mov cl,[edi+9]
call sub_register
pop esi
jmp calculation_loop
invalid_sub:
cmp [error_line],0
jne sub_values
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
jmp sub_values
cmp [error_line],0
jne sub_values
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
jmp sub_values
sub_register:
or cl,cl
jz add_register_done
neg byte [ebx]
jmp add_register_start
or cl,cl
jz add_register_done
neg byte [ebx]
jmp add_register_start
calculate_mul:
or dx,dx
jz mul_start
cmp word [ebx+8],0
jne mul_start
mov eax,[ebx]
xchg eax,[edi]
mov [ebx],eax
mov eax,[ebx+4]
xchg eax,[edi+4]
mov [ebx+4],eax
mov eax,[ebx+8]
xchg eax,[edi+8]
mov [ebx+8],eax
mov eax,[ebx+12]
xchg eax,[edi+12]
mov [ebx+12],eax
or dx,dx
jz mul_start
cmp word [ebx+8],0
jne mul_start
mov eax,[ebx]
xchg eax,[edi]
mov [ebx],eax
mov eax,[ebx+4]
xchg eax,[edi+4]
mov [ebx+4],eax
mov eax,[ebx+8]
xchg eax,[edi+8]
mov [ebx+8],eax
mov eax,[ebx+12]
xchg eax,[edi+12]
mov [ebx+12],eax
mul_start:
push esi edx
mov esi,ebx
xor bl,bl
bt dword [esi+4],31
jnc mul_first_sign_ok
not dword [esi]
not dword [esi+4]
add dword [esi],1
adc dword [esi+4],0
not bl
push esi edx
mov esi,ebx
xor bl,bl
bt dword [esi+4],31
jnc mul_first_sign_ok
not dword [esi]
not dword [esi+4]
add dword [esi],1
adc dword [esi+4],0
not bl
mul_first_sign_ok:
bt dword [edi+4],31
jnc mul_second_sign_ok
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
not bl
bt dword [edi+4],31
jnc mul_second_sign_ok
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
not bl
mul_second_sign_ok:
cmp dword [esi+4],0
jz mul_numbers
cmp dword [edi+4],0
jnz value_out_of_range
cmp dword [esi+4],0
jz mul_numbers
cmp dword [edi+4],0
jnz value_out_of_range
mul_numbers:
mov eax,[esi+4]
mul dword [edi]
or edx,edx
jnz value_out_of_range
mov ecx,eax
mov eax,[esi]
mul dword [edi+4]
or edx,edx
jnz value_out_of_range
add ecx,eax
jc value_out_of_range
mov eax,[esi]
mul dword [edi]
add edx,ecx
jc value_out_of_range
test edx,1 shl 31
jnz value_out_of_range
mov [esi],eax
mov [esi+4],edx
or bl,bl
jz mul_ok
not dword [esi]
not dword [esi+4]
add dword [esi],1
adc dword [esi+4],0
mov eax,[esi+4]
mul dword [edi]
or edx,edx
jnz value_out_of_range
mov ecx,eax
mov eax,[esi]
mul dword [edi+4]
or edx,edx
jnz value_out_of_range
add ecx,eax
jc value_out_of_range
mov eax,[esi]
mul dword [edi]
add edx,ecx
jc value_out_of_range
test edx,1 shl 31
jnz value_out_of_range
mov [esi],eax
mov [esi+4],edx
or bl,bl
jz mul_ok
not dword [esi]
not dword [esi+4]
add dword [esi],1
adc dword [esi+4],0
mul_ok:
pop edx
or dx,dx
jz mul_calculated
cmp word [edi+8],0
jne invalid_value
cmp byte [esi+8],0
je mul_first_register_ok
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
imul byte [esi+10]
mov dl,ah
cbw
cmp ah,dl
jne value_out_of_range
mov [esi+10],al
pop edx
or dx,dx
jz mul_calculated
cmp word [edi+8],0
jne invalid_value
cmp byte [esi+8],0
je mul_first_register_ok
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
imul byte [esi+10]
mov dl,ah
cbw
cmp ah,dl
jne value_out_of_range
mov [esi+10],al
mul_first_register_ok:
cmp byte [esi+9],0
je mul_calculated
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
imul byte [esi+11]
mov dl,ah
cbw
cmp ah,dl
jne value_out_of_range
mov [esi+11],al
cmp byte [esi+9],0
je mul_calculated
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
imul byte [esi+11]
mov dl,ah
cbw
cmp ah,dl
jne value_out_of_range
mov [esi+11],al
mul_calculated:
pop esi
jmp calculation_loop
pop esi
jmp calculation_loop
calculate_div:
push esi edx
mov esi,ebx
call div_64
pop edx
or dx,dx
jz div_calculated
cmp byte [esi+8],0
je div_first_register_ok
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
or al,al
jz value_out_of_range
mov al,[esi+10]
cbw
idiv byte [edi]
or ah,ah
jnz invalid_use_of_symbol
mov [esi+10],al
push esi edx
mov esi,ebx
call div_64
pop edx
or dx,dx
jz div_calculated
cmp byte [esi+8],0
je div_first_register_ok
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
or al,al
jz value_out_of_range
mov al,[esi+10]
cbw
idiv byte [edi]
or ah,ah
jnz invalid_use_of_symbol
mov [esi+10],al
div_first_register_ok:
cmp byte [esi+9],0
je div_calculated
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
or al,al
jz value_out_of_range
mov al,[esi+11]
cbw
idiv byte [edi]
or ah,ah
jnz invalid_use_of_symbol
mov [esi+11],al
cmp byte [esi+9],0
je div_calculated
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
or al,al
jz value_out_of_range
mov al,[esi+11]
cbw
idiv byte [edi]
or ah,ah
jnz invalid_use_of_symbol
mov [esi+11],al
div_calculated:
pop esi
jmp calculation_loop
pop esi
jmp calculation_loop
calculate_mod:
push esi
mov esi,ebx
call div_64
mov [esi],eax
mov [esi+4],edx
pop esi
jmp calculation_loop
push esi
mov esi,ebx
call div_64
mov [esi],eax
mov [esi+4],edx
pop esi
jmp calculation_loop
calculate_and:
mov eax,[edi]
and [ebx],eax
mov eax,[edi+4]
and [ebx+4],eax
jmp calculation_loop
mov eax,[edi]
and [ebx],eax
mov eax,[edi+4]
and [ebx+4],eax
jmp calculation_loop
calculate_or:
mov eax,[edi]
or [ebx],eax
mov eax,[edi+4]
or [ebx+4],eax
jmp calculation_loop
mov eax,[edi]
or [ebx],eax
mov eax,[edi+4]
or [ebx+4],eax
jmp calculation_loop
calculate_xor:
mov eax,[edi]
xor [ebx],eax
mov eax,[edi+4]
xor [ebx+4],eax
jmp calculation_loop
mov eax,[edi]
xor [ebx],eax
mov eax,[edi+4]
xor [ebx+4],eax
jmp calculation_loop
shr_negative:
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
calculate_shl:
mov eax,dword [edi+4]
bt eax,31
jc shl_negative
or eax,eax
jnz zero_value
mov ecx,[edi]
cmp ecx,64
jae zero_value
cmp ecx,32
jae shl_high
mov edx,[ebx+4]
mov eax,[ebx]
shld edx,eax,cl
shl eax,cl
mov [ebx],eax
mov [ebx+4],edx
jmp calculation_loop
mov eax,dword [edi+4]
bt eax,31
jc shl_negative
or eax,eax
jnz zero_value
mov ecx,[edi]
cmp ecx,64
jae zero_value
cmp ecx,32
jae shl_high
mov edx,[ebx+4]
mov eax,[ebx]
shld edx,eax,cl
shl eax,cl
mov [ebx],eax
mov [ebx+4],edx
jmp calculation_loop
shl_high:
sub cl,32
mov eax,[ebx]
shl eax,cl
mov [ebx+4],eax
mov dword [ebx],0
jmp calculation_loop
sub cl,32
mov eax,[ebx]
shl eax,cl
mov [ebx+4],eax
mov dword [ebx],0
jmp calculation_loop
shl_negative:
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
calculate_shr:
mov eax,dword [edi+4]
bt eax,31
jc shr_negative
or eax,eax
jnz zero_value
mov ecx,[edi]
cmp ecx,64
jae zero_value
cmp ecx,32
jae shr_high
mov edx,[ebx+4]
mov eax,[ebx]
shrd eax,edx,cl
shr edx,cl
mov [ebx],eax
mov [ebx+4],edx
jmp calculation_loop
mov eax,dword [edi+4]
bt eax,31
jc shr_negative
or eax,eax
jnz zero_value
mov ecx,[edi]
cmp ecx,64
jae zero_value
cmp ecx,32
jae shr_high
mov edx,[ebx+4]
mov eax,[ebx]
shrd eax,edx,cl
shr edx,cl
mov [ebx],eax
mov [ebx+4],edx
jmp calculation_loop
shr_high:
sub cl,32
mov eax,[ebx+4]
shr eax,cl
mov [ebx],eax
mov dword [ebx+4],0
jmp calculation_loop
sub cl,32
mov eax,[ebx+4]
shr eax,cl
mov [ebx],eax
mov dword [ebx+4],0
jmp calculation_loop
zero_value:
mov dword [ebx],0
mov dword [ebx+4],0
jmp calculation_loop
mov dword [ebx],0
mov dword [ebx+4],0
jmp calculation_loop
calculate_not:
cmp word [edi+8],0
jne invalid_expression
cmp byte [edi+12],0
je not_ok
cmp [error_line],0
jne not_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
cmp word [edi+8],0
jne invalid_expression
cmp byte [edi+12],0
je not_ok
cmp [error_line],0
jne not_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
not_ok:
cmp [value_size],1
je not_byte
cmp [value_size],2
je not_word
cmp [value_size],4
je not_dword
cmp [value_size],6
je not_pword
cmp [value_size],1
je not_byte
cmp [value_size],2
je not_word
cmp [value_size],4
je not_dword
cmp [value_size],6
je not_pword
not_qword:
not dword [edi]
not dword [edi+4]
add edi,14h
jmp calculation_loop
not dword [edi]
not dword [edi+4]
add edi,14h
jmp calculation_loop
not_byte:
cmp dword [edi+4],0
jne not_qword
cmp word [edi+2],0
jne not_qword
cmp byte [edi+1],0
jne not_qword
not byte [edi]
add edi,14h
jmp calculation_loop
cmp dword [edi+4],0
jne not_qword
cmp word [edi+2],0
jne not_qword
cmp byte [edi+1],0
jne not_qword
not byte [edi]
add edi,14h
jmp calculation_loop
not_word:
cmp dword [edi+4],0
jne not_qword
cmp word [edi+2],0
jne not_qword
not word [edi]
add edi,14h
jmp calculation_loop
cmp dword [edi+4],0
jne not_qword
cmp word [edi+2],0
jne not_qword
not word [edi]
add edi,14h
jmp calculation_loop
not_dword:
cmp dword [edi+4],0
jne not_qword
not dword [edi]
add edi,14h
jmp calculation_loop
cmp dword [edi+4],0
jne not_qword
not dword [edi]
add edi,14h
jmp calculation_loop
not_pword:
cmp word [edi+6],0
jne not_qword
not dword [edi]
not word [edi+4]
add edi,14h
jmp calculation_loop
cmp word [edi+6],0
jne not_qword
not dword [edi]
not word [edi+4]
add edi,14h
jmp calculation_loop
calculate_neg:
cmp word [edi+8],0
jne invalid_expression
cmp byte [edi+12],0
je neg_ok
cmp [error_line],0
jne neg_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
cmp word [edi+8],0
jne invalid_expression
cmp byte [edi+12],0
je neg_ok
cmp [error_line],0
jne neg_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
neg_ok:
mov eax,[edi]
mov edx,[edi+4]
mov dword [edi],0
mov dword [edi+4],0
sub [edi],eax
sbb [edi+4],edx
add edi,14h
jmp calculation_loop
mov eax,[edi]
mov edx,[edi+4]
mov dword [edi],0
mov dword [edi+4],0
sub [edi],eax
sbb [edi+4],edx
add edi,14h
jmp calculation_loop
calculate_rva:
cmp word [edi+8],0
jne invalid_expression
cmp [output_format],5
je calculate_gotoff
cmp [output_format],3
jne invalid_expression
test [format_flags],8
jnz pe64_rva
mov al,2
bt [resolver_flags],0
jc rva_type_ok
xor al,al
cmp word [edi+8],0
jne invalid_expression
cmp [output_format],5
je calculate_gotoff
cmp [output_format],3
jne invalid_expression
test [format_flags],8
jnz pe64_rva
mov al,2
bt [resolver_flags],0
jc rva_type_ok
xor al,al
rva_type_ok:
cmp byte [edi+12],al
je rva_ok
cmp [error_line],0
jne rva_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
cmp byte [edi+12],al
je rva_ok
cmp [error_line],0
jne rva_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
rva_ok:
mov byte [edi+12],0
mov eax,[code_start]
mov eax,[eax+34h]
cdq
sub [edi],eax
sbb [edi+4],edx
add edi,14h
jmp calculation_loop
mov byte [edi+12],0
mov eax,[code_start]
mov eax,[eax+34h]
cdq
sub [edi],eax
sbb [edi+4],edx
add edi,14h
jmp calculation_loop
pe64_rva:
mov al,4
bt [resolver_flags],0
jc pe64_rva_type_ok
xor al,al
mov al,4
bt [resolver_flags],0
jc pe64_rva_type_ok
xor al,al
pe64_rva_type_ok:
cmp byte [edi+12],al
je pe64_rva_ok
cmp [error_line],0
jne pe64_rva_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
cmp byte [edi+12],al
je pe64_rva_ok
cmp [error_line],0
jne pe64_rva_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
pe64_rva_ok:
mov byte [edi+12],0
mov eax,[code_start]
mov edx,[eax+34h]
mov eax,[eax+30h]
sub [edi],eax
sbb [edi+4],edx
add edi,14h
jmp calculation_loop
mov byte [edi+12],0
mov eax,[code_start]
mov edx,[eax+34h]
mov eax,[eax+30h]
sub [edi],eax
sbb [edi+4],edx
add edi,14h
jmp calculation_loop
calculate_gotoff:
test [format_flags],8+1
jnz invalid_expression
cmp byte [edi+12],2
je gotoff_ok
cmp [error_line],0
jne pe64_rva_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
test [format_flags],8+1
jnz invalid_expression
cmp byte [edi+12],2
je gotoff_ok
cmp [error_line],0
jne pe64_rva_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
gotoff_ok:
mov byte [edi+12],5
add edi,14h
jmp calculation_loop
mov byte [edi+12],5
add edi,14h
jmp calculation_loop
div_64:
xor ebx,ebx
cmp dword [edi],0
jne divider_ok
cmp dword [edi+4],0
jne divider_ok
cmp [next_pass_needed],0
je value_out_of_range
jmp div_done
xor ebx,ebx
cmp dword [edi],0
jne divider_ok
cmp dword [edi+4],0
jne divider_ok
cmp [next_pass_needed],0
je value_out_of_range
jmp div_done
divider_ok:
bt dword [esi+4],31
jnc div_first_sign_ok
not dword [esi]
not dword [esi+4]
add dword [esi],1
adc dword [esi+4],0
not bx
bt dword [esi+4],31
jnc div_first_sign_ok
not dword [esi]
not dword [esi+4]
add dword [esi],1
adc dword [esi+4],0
not bx
div_first_sign_ok:
bt dword [edi+4],31
jnc div_second_sign_ok
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
not bl
bt dword [edi+4],31
jnc div_second_sign_ok
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
not bl
div_second_sign_ok:
cmp dword [edi+4],0
jne div_high
mov ecx,[edi]
mov eax,[esi+4]
xor edx,edx
div ecx
mov [esi+4],eax
mov eax,[esi]
div ecx
mov [esi],eax
mov eax,edx
xor edx,edx
jmp div_done
cmp dword [edi+4],0
jne div_high
mov ecx,[edi]
mov eax,[esi+4]
xor edx,edx
div ecx
mov [esi+4],eax
mov eax,[esi]
div ecx
mov [esi],eax
mov eax,edx
xor edx,edx
jmp div_done
div_high:
mov eax,[esi+4]
xor edx,edx
div dword [edi+4]
mov ebx,[esi]
mov [esi],eax
mov dword [esi+4],0
mov ecx,edx
mul dword [edi]
mov eax,[esi+4]
xor edx,edx
div dword [edi+4]
mov ebx,[esi]
mov [esi],eax
mov dword [esi+4],0
mov ecx,edx
mul dword [edi]
div_high_loop:
cmp ecx,edx
ja div_high_done
jb div_high_large_correction
cmp ebx,eax
jae div_high_done
cmp ecx,edx
ja div_high_done
jb div_high_large_correction
cmp ebx,eax
jae div_high_done
div_high_correction:
dec dword [esi]
sub eax,[edi]
sbb edx,[edi+4]
jnc div_high_loop
dec dword [esi]
sub eax,[edi]
sbb edx,[edi+4]
jnc div_high_loop
div_high_done:
sub ebx,eax
sbb ecx,edx
mov edx,ecx
mov eax,ebx
ret
sub ebx,eax
sbb ecx,edx
mov edx,ecx
mov eax,ebx
ret
div_high_large_correction:
push eax edx
mov eax,edx
sub eax,ecx
xor edx,edx
div dword [edi+4]
shr eax,1
jz div_high_small_correction
sub [esi],eax
push eax
mul dword [edi+4]
sub dword [esp+4],eax
pop eax
mul dword [edi]
sub dword [esp+4],eax
sbb dword [esp],edx
pop edx eax
jmp div_high_loop
push eax edx
mov eax,edx
sub eax,ecx
xor edx,edx
div dword [edi+4]
shr eax,1
jz div_high_small_correction
sub [esi],eax
push eax
mul dword [edi+4]
sub dword [esp+4],eax
pop eax
mul dword [edi]
sub dword [esp+4],eax
sbb dword [esp],edx
pop edx eax
jmp div_high_loop
div_high_small_correction:
pop edx eax
jmp div_high_correction
pop edx eax
jmp div_high_correction
div_done:
or bh,bh
jz remainder_ok
not eax
not edx
add eax,1
adc edx,0
or bh,bh
jz remainder_ok
not eax
not edx
add eax,1
adc edx,0
remainder_ok:
or bl,bl
jz div_ok
not dword [esi]
not dword [esi+4]
add dword [esi],1
adc dword [esi+4],0
or bl,bl
jz div_ok
not dword [esi]
not dword [esi+4]
add dword [esi],1
adc dword [esi+4],0
div_ok:
ret
ret
convert_fp:
inc esi
mov word [edi+8],0
mov byte [edi+12],0
mov al,[value_size]
cmp al,4
je convert_fp_dword
cmp al,8
je convert_fp_qword
jmp invalid_value
inc esi
mov word [edi+8],0
mov byte [edi+12],0
mov al,[value_size]
cmp al,4
je convert_fp_dword
cmp al,8
je convert_fp_qword
jmp invalid_value
convert_fp_dword:
xor eax,eax
cmp word [esi+8],8000h
je fp_dword_store
mov bx,[esi+8]
mov eax,[esi+4]
shl eax,1
shr eax,9
jnc fp_dword_ok
inc eax
bt eax,23
jnc fp_dword_ok
and eax,1 shl 23 - 1
inc bx
shr eax,1
xor eax,eax
cmp word [esi+8],8000h
je fp_dword_store
mov bx,[esi+8]
mov eax,[esi+4]
shl eax,1
shr eax,9
jnc fp_dword_ok
inc eax
bt eax,23
jnc fp_dword_ok
and eax,1 shl 23 - 1
inc bx
shr eax,1
fp_dword_ok:
add bx,7Fh
cmp bx,100h
jae value_out_of_range
shl ebx,23
or eax,ebx
add bx,7Fh
cmp bx,100h
jae value_out_of_range
shl ebx,23
or eax,ebx
fp_dword_store:
mov bl,[esi+11]
shl ebx,31
or eax,ebx
mov [edi],eax
xor eax,eax
mov [edi+4],eax
add esi,13
ret
mov bl,[esi+11]
shl ebx,31
or eax,ebx
mov [edi],eax
xor eax,eax
mov [edi+4],eax
add esi,13
ret
convert_fp_qword:
xor eax,eax
xor edx,edx
cmp word [esi+8],8000h
je fp_qword_store
mov bx,[esi+8]
mov eax,[esi]
mov edx,[esi+4]
add eax,eax
adc edx,edx
mov ecx,edx
shr edx,12
shrd eax,ecx,12
jnc fp_qword_ok
add eax,1
adc edx,0
bt edx,20
jnc fp_qword_ok
and edx,1 shl 20 - 1
inc bx
shr edx,1
rcr eax,1
xor eax,eax
xor edx,edx
cmp word [esi+8],8000h
je fp_qword_store
mov bx,[esi+8]
mov eax,[esi]
mov edx,[esi+4]
add eax,eax
adc edx,edx
mov ecx,edx
shr edx,12
shrd eax,ecx,12
jnc fp_qword_ok
add eax,1
adc edx,0
bt edx,20
jnc fp_qword_ok
and edx,1 shl 20 - 1
inc bx
shr edx,1
rcr eax,1
fp_qword_ok:
add bx,3FFh
cmp bx,800h
jae value_out_of_range
shl ebx,20
or edx,ebx
add bx,3FFh
cmp bx,800h
jae value_out_of_range
shl ebx,20
or edx,ebx
fp_qword_store:
mov bl,[esi+11]
shl ebx,31
or edx,ebx
mov [edi],eax
mov [edi+4],edx
add esi,13
ret
mov bl,[esi+11]
shl ebx,31
or edx,ebx
mov [edi],eax
mov [edi+4],edx
add esi,13
ret
get_string_value:
inc esi
lods dword [esi]
mov ecx,eax
cmp ecx,8
ja value_out_of_range
mov edx,edi
xor eax,eax
stos dword [edi]
stos dword [edi]
mov edi,edx
rep movs byte [edi],[esi]
mov edi,edx
inc esi
mov word [edi+8],0
mov byte [edi+12],0
ret
inc esi
lods dword [esi]
mov ecx,eax
cmp ecx,8
ja value_out_of_range
mov edx,edi
xor eax,eax
stos dword [edi]
stos dword [edi]
mov edi,edx
rep movs byte [edi],[esi]
mov edi,edx
inc esi
mov word [edi+8],0
mov byte [edi+12],0
ret
 
get_byte_value:
mov [value_size],1
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
mov [value_type],0
cmp word [edi+8],0
jne invalid_value
cmp byte [edi+12],0
je check_byte_value
cmp [error_line],0
jne check_byte_value
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
mov [value_size],1
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
mov [value_type],0
cmp word [edi+8],0
jne invalid_value
cmp byte [edi+12],0
je check_byte_value
cmp [error_line],0
jne check_byte_value
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
check_byte_value:
mov eax,[edi]
mov edx,[edi+4]
or edx,edx
jz byte_positive
cmp edx,-1
jne range_exceeded
cmp eax,-80h
jb range_exceeded
ret
mov eax,[edi]
mov edx,[edi+4]
or edx,edx
jz byte_positive
cmp edx,-1
jne range_exceeded
cmp eax,-80h
jb range_exceeded
ret
byte_positive:
cmp eax,100h
jae range_exceeded
cmp eax,100h
jae range_exceeded
return_byte_value:
ret
ret
range_exceeded:
xor eax,eax
xor edx,edx
cmp [error_line],0
jne return_byte_value
mov ecx,[current_line]
mov [error_line],ecx
mov [error],value_out_of_range
ret
xor eax,eax
xor edx,edx
cmp [error_line],0
jne return_byte_value
mov ecx,[current_line]
mov [error_line],ecx
mov [error],value_out_of_range
ret
get_word_value:
mov [value_size],2
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
cmp al,2
jb check_word_value
cmp [error_line],0
jne check_word_value
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
mov [value_size],2
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
cmp al,2
jb check_word_value
cmp [error_line],0
jne check_word_value
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
check_word_value:
mov eax,[edi]
mov edx,[edi+4]
or edx,edx
jz word_positive
cmp edx,-1
jne range_exceeded
cmp eax,-8000h
jb range_exceeded
ret
mov eax,[edi]
mov edx,[edi+4]
or edx,edx
jz word_positive
cmp edx,-1
jne range_exceeded
cmp eax,-8000h
jb range_exceeded
ret
word_positive:
cmp eax,10000h
jae range_exceeded
ret
cmp eax,10000h
jae range_exceeded
ret
get_dword_value:
mov [value_size],4
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
cmp al,4
jne check_dword_value
mov [value_type],2
mov eax,[edi]
cdq
cmp edx,[edi+4]
jne range_exceeded
ret
mov [value_size],4
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
cmp al,4
jne check_dword_value
mov [value_type],2
mov eax,[edi]
cdq
cmp edx,[edi+4]
jne range_exceeded
ret
check_dword_value:
mov eax,[edi]
mov edx,[edi+4]
or edx,edx
jz dword_positive
cmp edx,-1
jne range_exceeded
bt eax,31
jnc range_exceeded
mov eax,[edi]
mov edx,[edi+4]
or edx,edx
jz dword_positive
cmp edx,-1
jne range_exceeded
bt eax,31
jnc range_exceeded
dword_positive:
ret
ret
get_pword_value:
mov [value_size],6
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
cmp al,4
jne check_pword_value
cmp [error_line],0
jne check_pword_value
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
mov [value_size],6
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
cmp al,4
jne check_pword_value
cmp [error_line],0
jne check_pword_value
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
check_pword_value:
mov eax,[edi]
mov edx,[edi+4]
cmp edx,10000h
jge range_exceeded
cmp edx,-8000h
jl range_exceeded
ret
mov eax,[edi]
mov edx,[edi+4]
cmp edx,10000h
jge range_exceeded
cmp edx,-8000h
jl range_exceeded
ret
get_qword_value:
mov [value_size],8
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
mov [value_size],8
mov [size_override],-1
call calculate_expression
mov eax,[edi+16]
mov [symbol_identifier],eax
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
check_qword_value:
mov eax,[edi]
mov edx,[edi+4]
ret
mov eax,[edi]
mov edx,[edi+4]
ret
get_value:
mov [operand_size],0
lods byte [esi]
call get_size_operator
cmp al,'('
jne invalid_value
mov al,[operand_size]
cmp al,1
je value_byte
cmp al,2
je value_word
cmp al,4
je value_dword
cmp al,6
je value_pword
cmp al,8
je value_qword
or al,al
jnz invalid_value
mov [operand_size],0
lods byte [esi]
call get_size_operator
cmp al,'('
jne invalid_value
mov al,[operand_size]
cmp al,1
je value_byte
cmp al,2
je value_word
cmp al,4
je value_dword
cmp al,6
je value_pword
cmp al,8
je value_qword
or al,al
jnz invalid_value
value_qword:
call get_qword_value
ret
call get_qword_value
ret
value_pword:
call get_pword_value
movzx edx,dx
ret
call get_pword_value
movzx edx,dx
ret
value_dword:
call get_dword_value
xor edx,edx
ret
call get_dword_value
xor edx,edx
ret
value_word:
call get_word_value
xor edx,edx
movzx eax,ax
ret
call get_word_value
xor edx,edx
movzx eax,ax
ret
value_byte:
call get_byte_value
xor edx,edx
movzx eax,al
ret
call get_byte_value
xor edx,edx
movzx eax,al
ret
get_address_value:
mov [address_size],0
mov [value_size],8
mov [address_size],0
mov [value_size],8
calculate_address:
cmp byte [esi],'.'
je invalid_address
call calculate_expression
mov eax,[edi+16]
mov [address_symbol],eax
mov al,[edi+12]
mov [value_type],al
cmp al,5
je gotoff_address
test al,1
jnz invalid_use_of_symbol
or al,al
jz address_size_ok
shl al,5
jmp address_symbol_ok
cmp byte [esi],'.'
je invalid_address
call calculate_expression
mov eax,[edi+16]
mov [address_symbol],eax
mov al,[edi+12]
mov [value_type],al
cmp al,5
je gotoff_address
test al,1
jnz invalid_use_of_symbol
or al,al
jz address_size_ok
shl al,5
jmp address_symbol_ok
gotoff_address:
mov al,40h
mov al,40h
address_symbol_ok:
mov ah,[address_size]
or [address_size],al
shr al,4
or ah,ah
jz address_size_ok
cmp al,ah
je address_size_ok
cmp ax,0408h
jne address_sizes_do_not_agree
mov [value_type],2
mov eax,[edi]
cdq
cmp edx,[edi+4]
je address_size_ok
cmp [error_line],0
jne address_size_ok
mov ecx,[current_line]
mov [error_line],ecx
mov [error],value_out_of_range
mov ah,[address_size]
or [address_size],al
shr al,4
or ah,ah
jz address_size_ok
cmp al,ah
je address_size_ok
cmp ax,0408h
jne address_sizes_do_not_agree
mov [value_type],2
mov eax,[edi]
cdq
cmp edx,[edi+4]
je address_size_ok
cmp [error_line],0
jne address_size_ok
mov ecx,[current_line]
mov [error_line],ecx
mov [error],value_out_of_range
address_size_ok:
xor bx,bx
xor cl,cl
mov ch,[address_size]
cmp word [edi+8],0
je check_immediate_address
mov al,[edi+8]
mov dl,[edi+10]
call get_address_register
mov al,[edi+9]
mov dl,[edi+11]
call get_address_register
mov ax,bx
shr ah,4
shr al,4
or bh,bh
jz check_address_registers
or bl,bl
jz check_address_registers
cmp al,ah
jne invalid_address
xor bx,bx
xor cl,cl
mov ch,[address_size]
cmp word [edi+8],0
je check_immediate_address
mov al,[edi+8]
mov dl,[edi+10]
call get_address_register
mov al,[edi+9]
mov dl,[edi+11]
call get_address_register
mov ax,bx
shr ah,4
shr al,4
or bh,bh
jz check_address_registers
or bl,bl
jz check_address_registers
cmp al,ah
jne invalid_address
check_address_registers:
or al,ah
cmp al,4
je sib_allowed
cmp al,8
je sib_allowed
or cl,cl
jz check_word_value
cmp cl,1
je check_word_value
jmp invalid_address
or al,ah
mov ah,[address_size]
and ah,0Fh
jz address_registers_sizes_ok
cmp al,ah
jne invalid_address
address_registers_sizes_ok:
cmp al,4
je sib_allowed
cmp al,8
je sib_allowed
or cl,cl
jz check_word_value
cmp cl,1
je check_word_value
jmp invalid_address
get_address_register:
or al,al
jz address_register_ok
cmp dl,1
jne scaled_register
or bh,bh
jnz scaled_register
mov bh,al
or al,al
jz address_register_ok
cmp dl,1
jne scaled_register
or bh,bh
jnz scaled_register
mov bh,al
address_register_ok:
ret
ret
scaled_register:
or bl,bl
jnz invalid_address
mov bl,al
mov cl,dl
jmp address_register_ok
or bl,bl
jnz invalid_address
mov bl,al
mov cl,dl
jmp address_register_ok
sib_allowed:
or bh,bh
jnz check_index_scale
cmp cl,2
je special_index_scale
cmp cl,3
je special_index_scale
cmp cl,5
je special_index_scale
cmp cl,9
je special_index_scale
or bh,bh
jnz check_index_scale
cmp cl,2
je special_index_scale
cmp cl,3
je special_index_scale
cmp cl,5
je special_index_scale
cmp cl,9
je special_index_scale
check_index_scale:
or cl,cl
jz address_registers_ok
cmp cl,1
je address_registers_ok
cmp cl,2
je address_registers_ok
cmp cl,4
je address_registers_ok
cmp cl,8
je address_registers_ok
jmp invalid_address
or cl,cl
jz address_registers_ok
cmp cl,1
je address_registers_ok
cmp cl,2
je address_registers_ok
cmp cl,4
je address_registers_ok
cmp cl,8
je address_registers_ok
jmp invalid_address
special_index_scale:
mov bh,bl
dec cl
mov bh,bl
dec cl
address_registers_ok:
jmp check_dword_value
jmp check_dword_value
check_immediate_address:
cmp [code_type],64
jne check_dword_value
cmp [address_size],4
je check_dword_value
jmp check_qword_value
cmp [code_type],64
jne check_dword_value
cmp [address_size],4
je check_dword_value
jmp check_qword_value
get_relative_offset:
mov [value_size],4
mov [size_override],-1
call calculate_expression
mov [value_size],4
mov [size_override],-1
call calculate_expression
calculate_relative_offset:
push esi
add edi,14h
mov esi,[display_buffer]
sub esi,7
lea eax,[esi-14h]
cmp eax,edi
jb out_of_memory
mov byte [esi],11h
xor eax,eax
mov dword [esi+1],eax
mov word [esi+5],')' shl 8 + 81h
call calculation_loop
pop esi
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
mov eax,[edi+16]
mov [symbol_identifier],eax
mov eax,[edi]
mov edx,[edi+4]
or edx,edx
jz offset_positive
cmp edx,-1
jne range_exceeded
bt eax,31
jnc range_exceeded
ret
push esi
add edi,14h
mov esi,[display_buffer]
sub esi,7
lea eax,[esi-14h]
cmp eax,edi
jb out_of_memory
mov byte [esi],11h
xor eax,eax
mov dword [esi+1],eax
mov word [esi+5],')' shl 8 + 81h
call calculation_loop
pop esi
cmp word [edi+8],0
jne invalid_value
mov al,[edi+12]
mov [value_type],al
mov eax,[edi+16]
mov [symbol_identifier],eax
mov eax,[edi]
mov edx,[edi+4]
or edx,edx
jz offset_positive
cmp edx,-1
jne range_exceeded
bt eax,31
jnc range_exceeded
ret
offset_positive:
bt eax,31
jc range_exceeded
ret
bt eax,31
jc range_exceeded
ret
 
preevaluate_logical_expression:
push edi
call preevaluate_logical_value
push edi
call preevaluate_logical_value
preevaluation_loop:
cmp al,0FFh
je invalid_logical_expression
mov dl,[esi]
inc esi
cmp dl,'|'
je preevaluate_or
cmp dl,'&'
je preevaluate_and
cmp dl,'}'
je preevaluation_done
or dl,dl
jnz invalid_logical_expression
cmp al,0FFh
je invalid_logical_expression
mov dl,[esi]
inc esi
cmp dl,'|'
je preevaluate_or
cmp dl,'&'
je preevaluate_and
cmp dl,'}'
je preevaluation_done
or dl,dl
jnz invalid_logical_expression
preevaluation_done:
pop edx
dec esi
ret
pop edx
dec esi
ret
preevaluate_or:
cmp al,'1'
je quick_true
cmp al,'0'
je leave_only_following
push edi
mov al,dl
stos byte [edi]
call preevaluate_logical_value
pop ebx
cmp al,'0'
je leave_only_preceding
cmp al,'1'
jne preevaluation_loop
stos byte [edi]
xor al,al
jmp preevaluation_loop
cmp al,'1'
je quick_true
cmp al,'0'
je leave_only_following
push edi
mov al,dl
stos byte [edi]
call preevaluate_logical_value
pop ebx
cmp al,'0'
je leave_only_preceding
cmp al,'1'
jne preevaluation_loop
stos byte [edi]
xor al,al
jmp preevaluation_loop
preevaluate_and:
cmp al,'0'
je quick_false
cmp al,'1'
je leave_only_following
push edi
mov al,dl
stos byte [edi]
call preevaluate_logical_value
pop ebx
cmp al,'1'
je leave_only_preceding
cmp al,'0'
jne preevaluation_loop
stos byte [edi]
xor al,al
jmp preevaluation_loop
cmp al,'0'
je quick_false
cmp al,'1'
je leave_only_following
push edi
mov al,dl
stos byte [edi]
call preevaluate_logical_value
pop ebx
cmp al,'1'
je leave_only_preceding
cmp al,'0'
jne preevaluation_loop
stos byte [edi]
xor al,al
jmp preevaluation_loop
leave_only_following:
mov edi,[esp]
call preevaluate_logical_value
jmp preevaluation_loop
mov edi,[esp]
call preevaluate_logical_value
jmp preevaluation_loop
leave_only_preceding:
mov edi,ebx
xor al,al
jmp preevaluation_loop
mov edi,ebx
xor al,al
jmp preevaluation_loop
quick_true:
call skip_logical_value
jc invalid_logical_expression
mov edi,[esp]
mov al,'1'
jmp preevaluation_loop
call skip_logical_value
jc invalid_logical_expression
mov edi,[esp]
mov al,'1'
jmp preevaluation_loop
quick_false:
call skip_logical_value
jc invalid_logical_expression
mov edi,[esp]
mov al,'0'
jmp preevaluation_loop
call skip_logical_value
jc invalid_logical_expression
mov edi,[esp]
mov al,'0'
jmp preevaluation_loop
invalid_logical_expression:
pop edi
mov esi,edi
mov al,0FFh
stos byte [edi]
ret
pop edi
mov esi,edi
mov al,0FFh
stos byte [edi]
ret
skip_logical_value:
cmp byte [esi],'~'
jne negation_skipped
inc esi
jmp skip_logical_value
cmp byte [esi],'~'
jne negation_skipped
inc esi
jmp skip_logical_value
negation_skipped:
cmp byte [esi],'{'
jne skip_simple_logical_value
inc esi
cmp byte [esi],'{'
jne skip_simple_logical_value
inc esi
skip_logical_expression:
call skip_logical_value
lods byte [esi]
or al,al
jz wrongly_structured_logical_expression
cmp al,0Fh
je wrongly_structured_logical_expression
cmp al,'|'
je skip_logical_expression
cmp al,'&'
je skip_logical_expression
cmp al,'}'
je logical_value_skipped
call skip_logical_value
lods byte [esi]
or al,al
jz wrongly_structured_logical_expression
cmp al,0Fh
je wrongly_structured_logical_expression
cmp al,'|'
je skip_logical_expression
cmp al,'&'
je skip_logical_expression
cmp al,'}'
je logical_value_skipped
wrongly_structured_logical_expression:
stc
ret
stc
ret
skip_simple_logical_value:
mov al,[esi]
or al,al
jz logical_value_skipped
cmp al,0Fh
je logical_value_skipped
cmp al,'}'
je logical_value_skipped
cmp al,'|'
je logical_value_skipped
cmp al,'&'
je logical_value_skipped
call skip_symbol
jmp skip_simple_logical_value
mov al,[esi]
or al,al
jz logical_value_skipped
cmp al,0Fh
je logical_value_skipped
cmp al,'}'
je logical_value_skipped
cmp al,'|'
je logical_value_skipped
cmp al,'&'
je logical_value_skipped
call skip_symbol
jmp skip_simple_logical_value
logical_value_skipped:
clc
ret
clc
ret
 
preevaluate_logical_value:
mov ebp,edi
mov ebp,edi
preevaluate_negation:
cmp byte [esi],'~'
jne preevaluate_negation_ok
movs byte [edi],[esi]
jmp preevaluate_negation
cmp byte [esi],'~'
jne preevaluate_negation_ok
movs byte [edi],[esi]
jmp preevaluate_negation
preevaluate_negation_ok:
mov ebx,esi
xor edx,edx
cmp byte [esi],'{'
jne find_logical_value_boundaries
movs byte [edi],[esi]
push ebp
call preevaluate_logical_expression
pop ebp
cmp al,0FFh
je invalid_logical_value
cmp byte [esi],'}'
jne invalid_logical_value
or al,al
jnz preevaluated_expression_value
movs byte [edi],[esi]
ret
mov ebx,esi
xor edx,edx
cmp byte [esi],'{'
jne find_logical_value_boundaries
movs byte [edi],[esi]
push ebp
call preevaluate_logical_expression
pop ebp
cmp al,0FFh
je invalid_logical_value
cmp byte [esi],'}'
jne invalid_logical_value
or al,al
jnz preevaluated_expression_value
movs byte [edi],[esi]
ret
preevaluated_expression_value:
inc esi
lea edx,[edi-1]
sub edx,ebp
test edx,1
jz expression_negation_ok
xor al,1
inc esi
lea edx,[edi-1]
sub edx,ebp
test edx,1
jz expression_negation_ok
xor al,1
expression_negation_ok:
mov edi,ebp
ret
mov edi,ebp
ret
invalid_logical_value:
mov edi,ebp
mov al,0FFh
ret
mov edi,ebp
mov al,0FFh
ret
find_logical_value_boundaries:
mov al,[esi]
or al,al
jz logical_value_boundaries_found
cmp al,'}'
je logical_value_boundaries_found
cmp al,'|'
je logical_value_boundaries_found
cmp al,'&'
je logical_value_boundaries_found
or edx,edx
jnz next_symbol_in_logical_value
cmp al,0F0h
je preevaluable_logical_operator
cmp al,0F7h
je preevaluable_logical_operator
cmp al,0F6h
jne next_symbol_in_logical_value
mov al,[esi]
or al,al
jz logical_value_boundaries_found
cmp al,'}'
je logical_value_boundaries_found
cmp al,'|'
je logical_value_boundaries_found
cmp al,'&'
je logical_value_boundaries_found
or edx,edx
jnz next_symbol_in_logical_value
cmp al,0F0h
je preevaluable_logical_operator
cmp al,0F7h
je preevaluable_logical_operator
cmp al,0F6h
jne next_symbol_in_logical_value
preevaluable_logical_operator:
mov edx,esi
mov edx,esi
next_symbol_in_logical_value:
call skip_symbol
jmp find_logical_value_boundaries
call skip_symbol
jmp find_logical_value_boundaries
logical_value_boundaries_found:
or edx,edx
jz non_preevaluable_logical_value
mov al,[edx]
cmp al,0F0h
je compare_symbols
cmp al,0F7h
je compare_symbol_types
cmp al,0F6h
je scan_symbols_list
or edx,edx
jz non_preevaluable_logical_value
mov al,[edx]
cmp al,0F0h
je compare_symbols
cmp al,0F7h
je compare_symbol_types
cmp al,0F6h
je scan_symbols_list
non_preevaluable_logical_value:
mov ecx,esi
mov esi,ebx
sub ecx,esi
jz invalid_logical_value
cmp esi,edi
je leave_logical_value_intact
rep movs byte [edi],[esi]
xor al,al
ret
mov ecx,esi
mov esi,ebx
sub ecx,esi
jz invalid_logical_value
cmp esi,edi
je leave_logical_value_intact
rep movs byte [edi],[esi]
xor al,al
ret
leave_logical_value_intact:
add edi,ecx
add esi,ecx
xor al,al
ret
add edi,ecx
add esi,ecx
xor al,al
ret
compare_symbols:
lea ecx,[esi-1]
sub ecx,edx
mov eax,edx
sub eax,ebx
cmp ecx,eax
jne preevaluated_false
push esi edi
mov esi,ebx
lea edi,[edx+1]
repe cmps byte [esi],[edi]
pop edi esi
je preevaluated_true
lea ecx,[esi-1]
sub ecx,edx
mov eax,edx
sub eax,ebx
cmp ecx,eax
jne preevaluated_false
push esi edi
mov esi,ebx
lea edi,[edx+1]
repe cmps byte [esi],[edi]
pop edi esi
je preevaluated_true
preevaluated_false:
mov eax,edi
sub eax,ebp
test eax,1
jnz store_true
mov eax,edi
sub eax,ebp
test eax,1
jnz store_true
store_false:
mov edi,ebp
mov al,'0'
ret
mov edi,ebp
mov al,'0'
ret
preevaluated_true:
mov eax,edi
sub eax,ebp
test eax,1
jnz store_false
mov eax,edi
sub eax,ebp
test eax,1
jnz store_false
store_true:
mov edi,ebp
mov al,'1'
ret
mov edi,ebp
mov al,'1'
ret
compare_symbol_types:
push esi
lea esi,[edx+1]
push esi
lea esi,[edx+1]
type_comparison:
cmp esi,[esp]
je types_compared
mov al,[esi]
cmp al,[ebx]
jne different_type
cmp al,'('
jne equal_type
mov al,[esi+1]
mov ah,[ebx+1]
cmp al,ah
je equal_type
or al,al
jz different_type
or ah,ah
jz different_type
cmp al,'.'
je different_type
cmp ah,'.'
je different_type
cmp esi,[esp]
je types_compared
mov al,[esi]
cmp al,[ebx]
jne different_type
cmp al,'('
jne equal_type
mov al,[esi+1]
mov ah,[ebx+1]
cmp al,ah
je equal_type
or al,al
jz different_type
or ah,ah
jz different_type
cmp al,'.'
je different_type
cmp ah,'.'
je different_type
equal_type:
call skip_symbol
xchg esi,ebx
call skip_symbol
xchg esi,ebx
jmp type_comparison
call skip_symbol
xchg esi,ebx
call skip_symbol
xchg esi,ebx
jmp type_comparison
types_compared:
pop esi
cmp byte [ebx],0F7h
jne preevaluated_false
jmp preevaluated_true
pop esi
cmp byte [ebx],0F7h
jne preevaluated_false
jmp preevaluated_true
different_type:
pop esi
jmp preevaluated_false
pop esi
jmp preevaluated_false
scan_symbols_list:
push edi esi
lea esi,[edx+1]
sub edx,ebx
lods byte [esi]
cmp al,'<'
jne invalid_symbols_list
push edi esi
lea esi,[edx+1]
sub edx,ebx
lods byte [esi]
cmp al,'<'
jne invalid_symbols_list
get_next_from_list:
mov edi,esi
mov edi,esi
get_from_list:
cmp byte [esi],','
je compare_in_list
cmp byte [esi],'>'
je compare_in_list
cmp esi,[esp]
jae invalid_symbols_list
call skip_symbol
jmp get_from_list
cmp byte [esi],','
je compare_in_list
cmp byte [esi],'>'
je compare_in_list
cmp esi,[esp]
jae invalid_symbols_list
call skip_symbol
jmp get_from_list
compare_in_list:
mov ecx,esi
sub ecx,edi
cmp ecx,edx
jne not_equal_length_in_list
mov esi,ebx
repe cmps byte [esi],[edi]
mov esi,edi
jne not_equal_in_list
mov ecx,esi
sub ecx,edi
cmp ecx,edx
jne not_equal_length_in_list
mov esi,ebx
repe cmps byte [esi],[edi]
mov esi,edi
jne not_equal_in_list
skip_rest_of_list:
cmp byte [esi],'>'
je check_list_end
cmp esi,[esp]
jae invalid_symbols_list
call skip_symbol
jmp skip_rest_of_list
cmp byte [esi],'>'
je check_list_end
cmp esi,[esp]
jae invalid_symbols_list
call skip_symbol
jmp skip_rest_of_list
check_list_end:
inc esi
cmp esi,[esp]
jne invalid_symbols_list
pop esi edi
jmp preevaluated_true
inc esi
cmp esi,[esp]
jne invalid_symbols_list
pop esi edi
jmp preevaluated_true
not_equal_in_list:
add esi,ecx
add esi,ecx
not_equal_length_in_list:
lods byte [esi]
cmp al,','
je get_next_from_list
cmp esi,[esp]
jne invalid_symbols_list
pop esi edi
jmp preevaluated_false
lods byte [esi]
cmp al,','
je get_next_from_list
cmp esi,[esp]
jne invalid_symbols_list
pop esi edi
jmp preevaluated_false
invalid_symbols_list:
pop esi edi
jmp invalid_logical_value
pop esi edi
jmp invalid_logical_value
 
calculate_logical_expression:
call get_logical_value
call get_logical_value
logical_loop:
cmp byte [esi],'|'
je logical_or
cmp byte [esi],'&'
je logical_and
ret
cmp byte [esi],'|'
je logical_or
cmp byte [esi],'&'
je logical_and
ret
logical_or:
inc esi
or al,al
jnz logical_value_already_determined
push eax
call get_logical_value
pop ebx
or al,bl
jmp logical_loop
inc esi
or al,al
jnz logical_value_already_determined
push eax
call get_logical_value
pop ebx
or al,bl
jmp logical_loop
logical_and:
inc esi
or al,al
jz logical_value_already_determined
push eax
call get_logical_value
pop ebx
and al,bl
jmp logical_loop
inc esi
or al,al
jz logical_value_already_determined
push eax
call get_logical_value
pop ebx
and al,bl
jmp logical_loop
logical_value_already_determined:
push eax
call skip_logical_value
jc invalid_expression
pop eax
jmp logical_loop
push eax
call skip_logical_value
jc invalid_expression
pop eax
jmp logical_loop
get_logical_value:
xor al,al
xor al,al
check_for_negation:
cmp byte [esi],'~'
jne negation_ok
inc esi
xor al,-1
jmp check_for_negation
cmp byte [esi],'~'
jne negation_ok
inc esi
xor al,-1
jmp check_for_negation
negation_ok:
push eax
mov al,[esi]
cmp al,'{'
je logical_expression
cmp al,0FFh
je invalid_expression
cmp al,88h
je check_for_defined
cmp al,89h
je check_for_used
cmp al,'0'
je given_false
cmp al,'1'
je given_true
call get_value
mov bl,[value_type]
push eax edx ebx
mov al,[esi]
or al,al
jz logical_number
cmp al,0Fh
je logical_number
cmp al,'}'
je logical_number
cmp al,'&'
je logical_number
cmp al,'|'
je logical_number
inc esi
mov [compare_type],al
call get_value
pop ebx
cmp [next_pass_needed],0
jne values_ok
cmp bl,[value_type]
jne invalid_use_of_symbol
push eax
mov al,[esi]
cmp al,'{'
je logical_expression
cmp al,0FFh
je invalid_expression
cmp al,88h
je check_for_defined
cmp al,89h
je check_for_used
cmp al,'0'
je given_false
cmp al,'1'
je given_true
call get_value
mov bl,[value_type]
push eax edx ebx
mov al,[esi]
or al,al
jz logical_number
cmp al,0Fh
je logical_number
cmp al,'}'
je logical_number
cmp al,'&'
je logical_number
cmp al,'|'
je logical_number
inc esi
mov [compare_type],al
call get_value
pop ebx
cmp [next_pass_needed],0
jne values_ok
cmp bl,[value_type]
jne invalid_use_of_symbol
values_ok:
pop ecx ebx
cmp [compare_type],'='
je check_equal
cmp [compare_type],'>'
je check_greater
cmp [compare_type],'<'
je check_less
cmp [compare_type],0F1h
je check_not_equal
cmp [compare_type],0F2h
je check_not_less
cmp [compare_type],0F3h
je check_not_greater
jmp invalid_expression
pop ecx ebx
cmp [compare_type],'='
je check_equal
cmp [compare_type],'>'
je check_greater
cmp [compare_type],'<'
je check_less
cmp [compare_type],0F1h
je check_not_equal
cmp [compare_type],0F2h
je check_not_less
cmp [compare_type],0F3h
je check_not_greater
jmp invalid_expression
check_equal:
cmp eax,ebx
jne return_false
cmp edx,ecx
jne return_false
jmp return_true
cmp eax,ebx
jne return_false
cmp edx,ecx
jne return_false
jmp return_true
check_greater:
cmp edx,ecx
jl return_true
jg return_false
cmp eax,ebx
jb return_true
jae return_false
cmp edx,ecx
jl return_true
jg return_false
cmp eax,ebx
jb return_true
jae return_false
check_less:
cmp edx,ecx
jl return_false
jg return_true
cmp eax,ebx
jbe return_false
ja return_true
cmp edx,ecx
jl return_false
jg return_true
cmp eax,ebx
jbe return_false
ja return_true
check_not_less:
cmp edx,ecx
jl return_true
jg return_false
cmp eax,ebx
jbe return_true
ja return_false
cmp edx,ecx
jl return_true
jg return_false
cmp eax,ebx
jbe return_true
ja return_false
check_not_greater:
cmp edx,ecx
jl return_false
jg return_true
cmp eax,ebx
jb return_false
jae return_true
cmp edx,ecx
jl return_false
jg return_true
cmp eax,ebx
jb return_false
jae return_true
check_not_equal:
cmp eax,ebx
jne return_true
cmp edx,ecx
jne return_true
jmp return_false
cmp eax,ebx
jne return_true
cmp edx,ecx
jne return_true
jmp return_false
logical_number:
pop ebx edx eax
or bl,bl
jnz invalid_expression
or eax,edx
jnz return_true
jmp return_false
pop ebx edx eax
or bl,bl
jnz invalid_expression
or eax,edx
jnz return_true
jmp return_false
check_for_defined:
or bl,-1
lods word [esi]
cmp ah,'('
jne invalid_expression
or bl,-1
lods word [esi]
cmp ah,'('
jne invalid_expression
check_expression:
lods byte [esi]
or al,al
jz defined_string
cmp al,'.'
je defined_fp_value
cmp al,')'
je expression_checked
cmp al,0Fh
je check_expression
cmp al,10h
je defined_register
cmp al,11h
je check_if_symbol_defined
cmp al,80h
jae check_expression
movzx eax,al
add esi,eax
jmp check_expression
lods byte [esi]
or al,al
jz defined_string
cmp al,'.'
je defined_fp_value
cmp al,')'
je expression_checked
cmp al,0Fh
je check_expression
cmp al,10h
je defined_register
cmp al,11h
je check_if_symbol_defined
cmp al,80h
jae check_expression
movzx eax,al
add esi,eax
jmp check_expression
defined_register:
inc esi
jmp check_expression
inc esi
jmp check_expression
defined_fp_value:
add esi,12
jmp expression_checked
add esi,12
jmp expression_checked
defined_string:
lods dword [esi]
add esi,eax
inc esi
jmp expression_checked
lods dword [esi]
add esi,eax
inc esi
jmp expression_checked
check_if_symbol_defined:
lods dword [esi]
cmp eax,-1
je invalid_expression
cmp eax,0Fh
jb check_expression
je reserved_word_used_as_symbol
test byte [eax+8],4
jnz no_prediction
test byte [eax+8],1
jz symbol_predicted_undefined
mov cx,[current_pass]
sub cx,[eax+16]
jz check_expression
cmp cx,1
ja symbol_predicted_undefined
or byte [eax+8],40h+80h
jmp check_expression
lods dword [esi]
cmp eax,-1
je invalid_expression
cmp eax,0Fh
jb check_expression
je reserved_word_used_as_symbol
test byte [eax+8],4
jnz no_prediction
test byte [eax+8],1
jz symbol_predicted_undefined
mov cx,[current_pass]
sub cx,[eax+16]
jz check_expression
cmp cx,1
ja symbol_predicted_undefined
or byte [eax+8],40h+80h
jmp check_expression
no_prediction:
test byte [eax+8],1
jz symbol_undefined
mov cx,[current_pass]
sub cx,[eax+16]
jz check_expression
jmp symbol_undefined
test byte [eax+8],1
jz symbol_undefined
mov cx,[current_pass]
sub cx,[eax+16]
jz check_expression
jmp symbol_undefined
symbol_predicted_undefined:
or byte [eax+8],40h
and byte [eax+8],not 80h
or byte [eax+8],40h
and byte [eax+8],not 80h
symbol_undefined:
xor bl,bl
jmp check_expression
xor bl,bl
jmp check_expression
expression_checked:
mov al,bl
jmp logical_value_ok
mov al,bl
jmp logical_value_ok
check_for_used:
lods word [esi]
cmp ah,2
jne invalid_expression
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
test byte [eax+8],8
jz not_used
mov cx,[current_pass]
sub cx,[eax+18]
jz return_true
cmp cx,1
ja not_used
or byte [eax+8],10h+20h
jmp return_true
lods word [esi]
cmp ah,2
jne invalid_expression
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
test byte [eax+8],8
jz not_used
mov cx,[current_pass]
sub cx,[eax+18]
jz return_true
cmp cx,1
ja not_used
or byte [eax+8],10h+20h
jmp return_true
not_used:
or byte [eax+8],10h
and byte [eax+8],not 20h
jmp return_false
or byte [eax+8],10h
and byte [eax+8],not 20h
jmp return_false
given_false:
inc esi
inc esi
return_false:
xor al,al
jmp logical_value_ok
xor al,al
jmp logical_value_ok
given_true:
inc esi
inc esi
return_true:
or al,-1
jmp logical_value_ok
or al,-1
jmp logical_value_ok
logical_expression:
inc esi
call calculate_logical_expression
push eax
lods byte [esi]
cmp al,'}'
jne invalid_expression
pop eax
inc esi
call calculate_logical_expression
push eax
lods byte [esi]
cmp al,'}'
jne invalid_expression
pop eax
logical_value_ok:
pop ebx
xor al,bl
ret
pop ebx
xor al,bl
ret
/programs/develop/fasm/trunk/formats.inc
4,3833 → 4,3833
; All rights reserved.
 
formatter:
cmp [output_file],0
jne output_path_ok
push edi
mov esi,[input_file]
mov edi,[free_additional_memory]
cmp [output_file],0
jne output_path_ok
push edi
mov esi,[input_file]
mov edi,[free_additional_memory]
copy_output_path:
lods byte [esi]
cmp edi,[structures_buffer]
jae out_of_memory
stos byte [edi]
or al,al
jnz copy_output_path
dec edi
mov eax,edi
lods byte [esi]
cmp edi,[structures_buffer]
jae out_of_memory
stos byte [edi]
or al,al
jnz copy_output_path
dec edi
mov eax,edi
find_extension:
dec eax
cmp eax,[free_additional_memory]
jb extension_found
cmp byte [eax],'\'
je extension_found
cmp byte [eax],'/'
je extension_found
cmp byte [eax],'.'
jne find_extension
mov edi,eax
dec eax
cmp eax,[free_additional_memory]
jb extension_found
cmp byte [eax],'\'
je extension_found
cmp byte [eax],'/'
je extension_found
cmp byte [eax],'.'
jne find_extension
mov edi,eax
extension_found:
lea eax,[edi+9]
cmp eax,[structures_buffer]
jae out_of_memory
cmp [output_format],2
je exe_extension
jb bin_extension
cmp [output_format],4
je obj_extension
cmp [output_format],5
je o_extension
cmp [output_format],3
jne no_extension
cmp [subsystem],1
je sys_extension
bt [format_flags],8
jnc exe_extension
mov eax,'.dll'
jmp make_extension
lea eax,[edi+9]
cmp eax,[structures_buffer]
jae out_of_memory
cmp [output_format],2
je exe_extension
jb bin_extension
cmp [output_format],4
je obj_extension
cmp [output_format],5
je o_extension
cmp [output_format],3
jne no_extension
cmp [subsystem],1
je sys_extension
bt [format_flags],8
jnc exe_extension
mov eax,'.dll'
jmp make_extension
sys_extension:
mov eax,'.sys'
jmp make_extension
mov eax,'.sys'
jmp make_extension
bin_extension:
mov eax,'.bin'
bt [format_flags],0
jnc make_extension
mov eax,'.com'
jmp make_extension
mov eax,'.bin'
bt [format_flags],0
jnc make_extension
mov eax,'.com'
jmp make_extension
obj_extension:
mov eax,'.obj'
jmp make_extension
mov eax,'.obj'
jmp make_extension
o_extension:
mov eax,'.o'
bt [format_flags],0
jnc make_extension
mov eax,'.o'
bt [format_flags],0
jnc make_extension
no_extension:
xor eax,eax
jmp make_extension
xor eax,eax
jmp make_extension
exe_extension:
mov eax,'.exe'
mov eax,'.exe'
make_extension:
xchg eax,[edi]
scas dword [edi]
mov byte [edi],0
scas byte [edi]
mov esi,edi
stos dword [edi]
sub edi,9
xor eax,eax
mov ebx,characters
xchg eax,[edi]
scas dword [edi]
mov byte [edi],0
scas byte [edi]
mov esi,edi
stos dword [edi]
sub edi,9
xor eax,eax
mov ebx,characters
adapt_case:
mov al,[esi]
or al,al
jz adapt_next
xlat byte [ebx]
cmp al,[esi]
je adapt_ok
sub byte [edi],20h
mov al,[esi]
or al,al
jz adapt_next
xlat byte [ebx]
cmp al,[esi]
je adapt_ok
sub byte [edi],20h
adapt_ok:
inc esi
inc esi
adapt_next:
inc edi
cmp byte [edi],0
jne adapt_case
mov esi,edi
lea ecx,[esi+1]
sub ecx,[free_additional_memory]
mov edi,[structures_buffer]
dec edi
std
rep movs byte [edi],[esi]
cld
inc edi
mov [structures_buffer],edi
mov [output_file],edi
pop edi
inc edi
cmp byte [edi],0
jne adapt_case
mov esi,edi
lea ecx,[esi+1]
sub ecx,[free_additional_memory]
mov edi,[structures_buffer]
dec edi
std
rep movs byte [edi],[esi]
cld
inc edi
mov [structures_buffer],edi
mov [output_file],edi
pop edi
output_path_ok:
cmp [output_format],4
je coff_formatter
cmp [output_format],5
jne common_formatter
bt [format_flags],0
jnc elf_formatter
cmp [output_format],4
je coff_formatter
cmp [output_format],5
jne common_formatter
bt [format_flags],0
jnc elf_formatter
common_formatter:
mov eax,edi
sub eax,[code_start]
mov [real_code_size],eax
cmp edi,[undefined_data_end]
jne calculate_code_size
mov edi,[undefined_data_start]
mov eax,edi
sub eax,[code_start]
mov [real_code_size],eax
cmp edi,[undefined_data_end]
jne calculate_code_size
mov edi,[undefined_data_start]
calculate_code_size:
sub edi,[code_start]
mov [code_size],edi
mov [written_size],0
mov edx,[output_file]
call create
jc write_failed
cmp [output_format],3
jne stub_written
mov edx,[code_start]
mov ecx,[stub_size]
sub edx,ecx
add [written_size],ecx
call write
sub edi,[code_start]
mov [code_size],edi
mov [written_size],0
mov edx,[output_file]
call create
jc write_failed
cmp [output_format],3
jne stub_written
mov edx,[code_start]
mov ecx,[stub_size]
sub edx,ecx
add [written_size],ecx
call write
stub_written:
cmp [output_format],2
jne write_output
call write_mz_header
cmp [output_format],2
jne write_output
call write_mz_header
write_output:
call write_code
call write_code
output_written:
call close
ret
call close
ret
write_code:
mov eax,[written_size]
mov [headers_size],eax
mov edx,[code_start]
mov ecx,[code_size]
add [written_size],ecx
call write
jc write_failed
ret
mov eax,[written_size]
mov [headers_size],eax
mov edx,[code_start]
mov ecx,[code_size]
add [written_size],ecx
call write
jc write_failed
ret
format_directive:
cmp edi,[code_start]
jne unexpected_instruction
cmp [virtual_data],0
jne unexpected_instruction
cmp [output_format],0
jne unexpected_instruction
lods byte [esi]
cmp al,17h
je format_prefix
cmp al,18h
jne invalid_argument
lods byte [esi]
cmp edi,[code_start]
jne unexpected_instruction
cmp [virtual_data],0
jne unexpected_instruction
cmp [output_format],0
jne unexpected_instruction
lods byte [esi]
cmp al,17h
je format_prefix
cmp al,18h
jne invalid_argument
lods byte [esi]
select_format:
mov dl,al
shr al,4
mov [output_format],al
and edx,0Fh
or [format_flags],edx
cmp al,2
je format_mz
cmp al,3
je format_pe
cmp al,4
je format_coff
cmp al,5
je format_elf
jmp instruction_assembled
mov dl,al
shr al,4
mov [output_format],al
and edx,0Fh
or [format_flags],edx
cmp al,2
je format_mz
cmp al,3
je format_pe
cmp al,4
je format_coff
cmp al,5
je format_elf
jmp instruction_assembled
format_prefix:
lods byte [esi]
mov ah,al
lods byte [esi]
cmp al,18h
jne invalid_argument
lods byte [esi]
mov edx,eax
shr dl,4
shr dh,4
cmp dl,dh
jne invalid_argument
or al,ah
jmp select_format
lods byte [esi]
mov ah,al
lods byte [esi]
cmp al,18h
jne invalid_argument
lods byte [esi]
mov edx,eax
shr dl,4
shr dh,4
cmp dl,dh
jne invalid_argument
or al,ah
jmp select_format
entry_directive:
bts [format_flags],10h
jc setting_already_specified
mov al,[output_format]
cmp al,2
je mz_entry
cmp al,3
je pe_entry
cmp al,5
jne illegal_instruction
bt [format_flags],0
jc elf_entry
jmp illegal_instruction
bts [format_flags],10h
jc setting_already_specified
mov al,[output_format]
cmp al,2
je mz_entry
cmp al,3
je pe_entry
cmp al,5
jne illegal_instruction
bt [format_flags],0
jc elf_entry
jmp illegal_instruction
stack_directive:
bts [format_flags],11h
jc setting_already_specified
mov al,[output_format]
cmp al,2
je mz_stack
cmp al,3
je pe_stack
jmp illegal_instruction
bts [format_flags],11h
jc setting_already_specified
mov al,[output_format]
cmp al,2
je mz_stack
cmp al,3
je pe_stack
jmp illegal_instruction
heap_directive:
bts [format_flags],12h
jc setting_already_specified
mov al,[output_format]
cmp al,2
je mz_heap
cmp al,3
je pe_heap
jmp illegal_instruction
bts [format_flags],12h
jc setting_already_specified
mov al,[output_format]
cmp al,2
je mz_heap
cmp al,3
je pe_heap
jmp illegal_instruction
segment_directive:
cmp [virtual_data],0
jne illegal_instruction
mov al,[output_format]
cmp al,2
je mz_segment
cmp al,5
je elf_segment
jmp illegal_instruction
cmp [virtual_data],0
jne illegal_instruction
mov al,[output_format]
cmp al,2
je mz_segment
cmp al,5
je elf_segment
jmp illegal_instruction
section_directive:
cmp [virtual_data],0
jne illegal_instruction
mov al,[output_format]
cmp al,3
je pe_section
cmp al,4
je coff_section
cmp al,5
je elf_section
jmp illegal_instruction
cmp [virtual_data],0
jne illegal_instruction
mov al,[output_format]
cmp al,3
je pe_section
cmp al,4
je coff_section
cmp al,5
je elf_section
jmp illegal_instruction
public_directive:
mov al,[output_format]
cmp al,4
je public_allowed
cmp al,5
jne illegal_instruction
bt [format_flags],0
jc illegal_instruction
mov al,[output_format]
cmp al,4
je public_allowed
cmp al,5
jne illegal_instruction
bt [format_flags],0
jc illegal_instruction
public_allowed:
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov dx,[current_pass]
mov [eax+18],dx
or byte [eax+8],8
inc esi
mov ebx,[free_additional_memory]
lea edx,[ebx+10h]
cmp edx,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],edx
mov [ebx+8],eax
mov eax,[current_line]
mov [ebx+0Ch],eax
lods byte [esi]
cmp al,86h
jne invalid_argument
lods word [esi]
cmp ax,'('
jne invalid_argument
mov [ebx+4],esi
lods dword [esi]
lea esi,[esi+eax+1]
mov byte [ebx],80h
jmp instruction_assembled
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov dx,[current_pass]
mov [eax+18],dx
or byte [eax+8],8
inc esi
mov ebx,[free_additional_memory]
lea edx,[ebx+10h]
cmp edx,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],edx
mov [ebx+8],eax
mov eax,[current_line]
mov [ebx+0Ch],eax
lods byte [esi]
cmp al,86h
jne invalid_argument
lods word [esi]
cmp ax,'('
jne invalid_argument
mov [ebx+4],esi
lods dword [esi]
lea esi,[esi+eax+1]
mov byte [ebx],80h
jmp instruction_assembled
extrn_directive:
mov al,[output_format]
cmp al,4
je extrn_allowed
cmp al,5
jne illegal_instruction
bt [format_flags],0
jc illegal_instruction
mov al,[output_format]
cmp al,4
je extrn_allowed
cmp al,5
jne illegal_instruction
bt [format_flags],0
jc illegal_instruction
extrn_allowed:
lods word [esi]
cmp ax,'('
jne invalid_argument
mov ebx,esi
lods dword [esi]
lea esi,[esi+eax+1]
mov edx,[free_additional_memory]
lea eax,[edx+0Ch]
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
mov byte [edx],81h
mov [edx+4],ebx
lods byte [esi]
cmp al,86h
jne invalid_argument
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
mov ebx,eax
xor ah,ah
lods byte [esi]
cmp al,':'
je get_extrn_size
dec esi
cmp al,11h
jne extrn_size_ok
lods word [esi]
cmp ax,'('
jne invalid_argument
mov ebx,esi
lods dword [esi]
lea esi,[esi+eax+1]
mov edx,[free_additional_memory]
lea eax,[edx+0Ch]
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
mov byte [edx],81h
mov [edx+4],ebx
lods byte [esi]
cmp al,86h
jne invalid_argument
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
mov ebx,eax
xor ah,ah
lods byte [esi]
cmp al,':'
je get_extrn_size
dec esi
cmp al,11h
jne extrn_size_ok
get_extrn_size:
lods word [esi]
cmp al,11h
jne invalid_argument
lods word [esi]
cmp al,11h
jne invalid_argument
extrn_size_ok:
mov [address_symbol],edx
movzx ecx,ah
mov [edx+8],ecx
xor eax,eax
xor edx,edx
xor ebp,ebp
mov ch,2
test [format_flags],8
jz make_free_label
mov ch,4
jmp make_free_label
mov [address_symbol],edx
movzx ecx,ah
mov [edx+8],ecx
xor eax,eax
xor edx,edx
xor ebp,ebp
mov ch,2
test [format_flags],8
jz make_free_label
mov ch,4
jmp make_free_label
mark_relocation:
cmp [value_type],0
je relocation_ok
cmp [virtual_data],0
jne relocation_ok
cmp [output_format],2
je mark_mz_relocation
cmp [output_format],3
je mark_pe_relocation
cmp [output_format],4
je mark_coff_relocation
cmp [output_format],5
je mark_elf_relocation
cmp [value_type],0
je relocation_ok
cmp [virtual_data],0
jne relocation_ok
cmp [output_format],2
je mark_mz_relocation
cmp [output_format],3
je mark_pe_relocation
cmp [output_format],4
je mark_coff_relocation
cmp [output_format],5
je mark_elf_relocation
relocation_ok:
ret
ret
close_pass:
mov al,[output_format]
cmp al,3
je close_pe
cmp al,4
je close_coff
cmp al,5
je close_elf
ret
mov al,[output_format]
cmp al,3
je close_pe
cmp al,4
je close_coff
cmp al,5
je close_elf
ret
 
format_mz:
mov edx,[additional_memory]
push edi
mov edi,edx
mov ecx,1Ch shr 2
xor eax,eax
rep stos dword [edi]
mov [free_additional_memory],edi
pop edi
mov word [edx+0Ch],0FFFFh
mov word [edx+10h],1000h
mov [code_type],16
jmp instruction_assembled
mov edx,[additional_memory]
push edi
mov edi,edx
mov ecx,1Ch shr 2
xor eax,eax
rep stos dword [edi]
mov [free_additional_memory],edi
pop edi
mov word [edx+0Ch],0FFFFh
mov word [edx+10h],1000h
mov [code_type],16
jmp instruction_assembled
mark_mz_relocation:
push eax ebx
inc [number_of_relocations]
mov ebx,[free_additional_memory]
mov eax,edi
sub eax,[code_start]
mov [ebx],ax
shr eax,16
shl ax,12
mov [ebx+2],ax
cmp word [ebx],0FFFFh
jne mz_relocation_ok
inc word [ebx+2]
sub word [ebx],10h
push eax ebx
inc [number_of_relocations]
mov ebx,[free_additional_memory]
mov eax,edi
sub eax,[code_start]
mov [ebx],ax
shr eax,16
shl ax,12
mov [ebx+2],ax
cmp word [ebx],0FFFFh
jne mz_relocation_ok
inc word [ebx+2]
sub word [ebx],10h
mz_relocation_ok:
add ebx,4
cmp ebx,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],ebx
pop ebx eax
ret
add ebx,4
cmp ebx,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],ebx
pop ebx eax
ret
mz_segment:
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
mov ebx,eax
mov eax,edi
sub eax,[code_start]
mov ecx,0Fh
add eax,0Fh
and eax,1111b
sub ecx,eax
mov edx,edi
xor al,al
rep stos byte [edi]
mov dword [org_origin],edi
mov dword [org_origin+4],0
mov [org_registers],0
mov [org_start],edi
mov eax,edx
call undefined_data
mov eax,edi
sub eax,[code_start]
shr eax,4
cmp eax,10000h
jae value_out_of_range
mov edx,eax
mov al,16
cmp byte [esi],13h
jne segment_type_ok
inc esi
lods byte [esi]
lods byte [esi]
cmp al,2
jne invalid_argument
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
inc esi
mov ebx,eax
mov eax,edi
sub eax,[code_start]
mov ecx,0Fh
add eax,0Fh
and eax,1111b
sub ecx,eax
mov edx,edi
xor al,al
rep stos byte [edi]
mov dword [org_origin],edi
mov dword [org_origin+4],0
mov [org_registers],0
mov [org_start],edi
mov eax,edx
call undefined_data
mov eax,edi
sub eax,[code_start]
shr eax,4
cmp eax,10000h
jae value_out_of_range
mov edx,eax
mov al,16
cmp byte [esi],13h
jne segment_type_ok
inc esi
lods byte [esi]
segment_type_ok:
mov [code_type],al
mov eax,edx
mov cx,0100h
xor edx,edx
xor ebp,ebp
mov [address_symbol],edx
jmp make_free_label
mov [code_type],al
mov eax,edx
mov cx,0100h
xor edx,edx
xor ebp,ebp
mov [address_symbol],edx
jmp make_free_label
mz_entry:
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_word_value
cmp [value_type],1
je initial_cs_ok
cmp [error_line],0
jne initial_cs_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_address
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_word_value
cmp [value_type],1
je initial_cs_ok
cmp [error_line],0
jne initial_cs_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_address
initial_cs_ok:
mov edx,[additional_memory]
mov [edx+16h],ax
lods byte [esi]
cmp al,':'
jne invalid_argument
lods byte [esi]
cmp al,'('
jne invalid_argument
ja invalid_address
call get_word_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[additional_memory]
mov [edx+14h],ax
jmp instruction_assembled
mov edx,[additional_memory]
mov [edx+16h],ax
lods byte [esi]
cmp al,':'
jne invalid_argument
lods byte [esi]
cmp al,'('
jne invalid_argument
ja invalid_address
call get_word_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[additional_memory]
mov [edx+14h],ax
jmp instruction_assembled
mz_stack:
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_word_value
cmp byte [esi],':'
je stack_pointer
cmp ax,10h
jb invalid_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[additional_memory]
mov [edx+10h],ax
jmp instruction_assembled
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_word_value
cmp byte [esi],':'
je stack_pointer
cmp ax,10h
jb invalid_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[additional_memory]
mov [edx+10h],ax
jmp instruction_assembled
stack_pointer:
cmp [value_type],1
je initial_ss_ok
cmp [error_line],0
jne initial_ss_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_address
cmp [value_type],1
je initial_ss_ok
cmp [error_line],0
jne initial_ss_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_address
initial_ss_ok:
mov edx,[additional_memory]
mov [edx+0Eh],ax
lods byte [esi]
cmp al,':'
jne invalid_argument
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_word_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[additional_memory]
mov [edx+10h],ax
bts [format_flags],4
jmp instruction_assembled
mov edx,[additional_memory]
mov [edx+0Eh],ax
lods byte [esi]
cmp al,':'
jne invalid_argument
lods byte [esi]
cmp al,'('
jne invalid_argument
call get_word_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[additional_memory]
mov [edx+10h],ax
bts [format_flags],4
jmp instruction_assembled
mz_heap:
cmp [output_format],2
jne illegal_instruction
lods byte [esi]
call get_size_operator
cmp ah,1
je invalid_value
cmp ah,2
ja invalid_value
cmp al,'('
jne invalid_argument
call get_word_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[additional_memory]
mov [edx+0Ch],ax
jmp instruction_assembled
cmp [output_format],2
jne illegal_instruction
lods byte [esi]
call get_size_operator
cmp ah,1
je invalid_value
cmp ah,2
ja invalid_value
cmp al,'('
jne invalid_argument
call get_word_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[additional_memory]
mov [edx+0Ch],ax
jmp instruction_assembled
write_mz_header:
mov edx,[additional_memory]
bt [format_flags],4
jc mz_stack_ok
mov eax,[real_code_size]
dec eax
shr eax,4
inc eax
mov [edx+0Eh],ax
shl eax,4
movzx ecx,word [edx+10h]
add eax,ecx
mov [real_code_size],eax
mov edx,[additional_memory]
bt [format_flags],4
jc mz_stack_ok
mov eax,[real_code_size]
dec eax
shr eax,4
inc eax
mov [edx+0Eh],ax
shl eax,4
movzx ecx,word [edx+10h]
add eax,ecx
mov [real_code_size],eax
mz_stack_ok:
mov edi,[free_additional_memory]
mov eax,[number_of_relocations]
shl eax,2
add eax,1Ch
sub edi,eax
xchg edi,[free_additional_memory]
mov ecx,0Fh
add eax,0Fh
and eax,1111b
sub ecx,eax
xor al,al
rep stos byte [edi]
sub edi,[free_additional_memory]
mov ecx,edi
shr edi,4
mov word [edx],'MZ' ; signature
mov [edx+8],di ; header size in paragraphs
mov eax,[number_of_relocations]
mov [edx+6],ax ; number of relocation entries
mov eax,[code_size]
add eax,ecx
mov esi,eax
shr esi,9
and eax,1FFh
inc si
or ax,ax
jnz mz_size_ok
mov ax,200h
dec si
mov edi,[free_additional_memory]
mov eax,[number_of_relocations]
shl eax,2
add eax,1Ch
sub edi,eax
xchg edi,[free_additional_memory]
mov ecx,0Fh
add eax,0Fh
and eax,1111b
sub ecx,eax
xor al,al
rep stos byte [edi]
sub edi,[free_additional_memory]
mov ecx,edi
shr edi,4
mov word [edx],'MZ' ; signature
mov [edx+8],di ; header size in paragraphs
mov eax,[number_of_relocations]
mov [edx+6],ax ; number of relocation entries
mov eax,[code_size]
add eax,ecx
mov esi,eax
shr esi,9
and eax,1FFh
inc si
or ax,ax
jnz mz_size_ok
mov ax,200h
dec si
mz_size_ok:
mov [edx+2],ax ; number of bytes in last page
mov [edx+4],si ; number of pages
mov eax,[real_code_size]
dec eax
shr eax,4
inc eax
mov esi,[code_size]
dec esi
shr esi,4
inc esi
sub eax,esi
mov [edx+0Ah],ax ; minimum memory in addition to code
add [edx+0Ch],ax ; maximum memory in addition to code
salc
mov ah,al
or [edx+0Ch],ax
mov word [edx+18h],1Ch ; offset of relocation table
add [written_size],ecx
call write
jc write_failed
ret
mov [edx+2],ax ; number of bytes in last page
mov [edx+4],si ; number of pages
mov eax,[real_code_size]
dec eax
shr eax,4
inc eax
mov esi,[code_size]
dec esi
shr esi,4
inc esi
sub eax,esi
mov [edx+0Ah],ax ; minimum memory in addition to code
add [edx+0Ch],ax ; maximum memory in addition to code
salc
mov ah,al
or [edx+0Ch],ax
mov word [edx+18h],1Ch ; offset of relocation table
add [written_size],ecx
call write
jc write_failed
ret
 
make_stub:
mov [stub_file],edx
or edx,edx
jnz stub_from_file
push esi
mov edx,edi
xor eax,eax
mov ecx,20h
rep stos dword [edi]
mov eax,40h+default_stub_end-default_stub
mov cx,100h+default_stub_end-default_stub
mov word [edx],'MZ'
mov word [edx+4],1
mov word [edx+2],ax
mov word [edx+8],4
mov word [edx+0Ah],10h
mov word [edx+0Ch],0FFFFh
mov word [edx+10h],cx
mov word [edx+3Ch],ax
mov word [edx+18h],40h
lea edi,[edx+40h]
mov esi,default_stub
mov ecx,default_stub_end-default_stub
rep movs byte [edi],[esi]
pop esi
jmp stub_ok
mov [stub_file],edx
or edx,edx
jnz stub_from_file
push esi
mov edx,edi
xor eax,eax
mov ecx,20h
rep stos dword [edi]
mov eax,40h+default_stub_end-default_stub
mov cx,100h+default_stub_end-default_stub
mov word [edx],'MZ'
mov word [edx+4],1
mov word [edx+2],ax
mov word [edx+8],4
mov word [edx+0Ah],10h
mov word [edx+0Ch],0FFFFh
mov word [edx+10h],cx
mov word [edx+3Ch],ax
mov word [edx+18h],40h
lea edi,[edx+40h]
mov esi,default_stub
mov ecx,default_stub_end-default_stub
rep movs byte [edi],[esi]
pop esi
jmp stub_ok
default_stub:
use16
push cs
pop ds
mov dx,stub_message-default_stub
mov ah,9
int 21h
mov ax,4C01h
int 21h
use16
push cs
pop ds
mov dx,stub_message-default_stub
mov ah,9
int 21h
mov ax,4C01h
int 21h
stub_message db 'This program cannot be run in DOS mode.',0Dh,0Ah,24h
rq 1
rq 1
default_stub_end:
use32
use32
stub_from_file:
push esi
mov esi,edx
call open_binary_file
mov edx,edi
mov ecx,1Ch
mov esi,edx
call read
jc binary_stub
cmp word [esi],'MZ'
jne binary_stub
add edi,1Ch
movzx ecx,word [esi+6]
add ecx,11b
and ecx,not 11b
add ecx,(40h-1Ch) shr 2
lea eax,[edi+ecx*4]
cmp edi,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
mov edx,40h
xchg dx,[esi+18h]
xor al,al
call lseek
movzx ecx,word [esi+6]
shl ecx,2
lea edx,[esi+40h]
call read
mov edx,edi
sub edx,esi
shr edx,4
xchg dx,[esi+8]
shl edx,4
xor al,al
call lseek
movzx ecx,word [esi+4]
dec ecx
shl ecx,9
movzx edx,word [esi+2]
add ecx,edx
mov edx,edi
sub ecx,eax
je read_stub_code
jb stub_code_ok
push ecx
dec ecx
shr ecx,3
inc ecx
shl ecx,1
lea eax,[edi+ecx*4]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
pop ecx
push esi
mov esi,edx
call open_binary_file
mov edx,edi
mov ecx,1Ch
mov esi,edx
call read
jc binary_stub
cmp word [esi],'MZ'
jne binary_stub
add edi,1Ch
movzx ecx,word [esi+6]
add ecx,11b
and ecx,not 11b
add ecx,(40h-1Ch) shr 2
lea eax,[edi+ecx*4]
cmp edi,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
mov edx,40h
xchg dx,[esi+18h]
xor al,al
call lseek
movzx ecx,word [esi+6]
shl ecx,2
lea edx,[esi+40h]
call read
mov edx,edi
sub edx,esi
shr edx,4
xchg dx,[esi+8]
shl edx,4
xor al,al
call lseek
movzx ecx,word [esi+4]
dec ecx
shl ecx,9
movzx edx,word [esi+2]
add ecx,edx
mov edx,edi
sub ecx,eax
je read_stub_code
jb stub_code_ok
push ecx
dec ecx
shr ecx,3
inc ecx
shl ecx,1
lea eax,[edi+ecx*4]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
pop ecx
read_stub_code:
call read
call read
stub_code_ok:
call close
mov edx,edi
sub edx,esi
mov ax,dx
and ax,1FFh
mov [esi+2],ax
dec edx
shr edx,9
inc edx
mov [esi+4],dx
mov eax,edi
sub eax,esi
mov [esi+3Ch],eax
pop esi
call close
mov edx,edi
sub edx,esi
mov ax,dx
and ax,1FFh
mov [esi+2],ax
dec edx
shr edx,9
inc edx
mov [esi+4],dx
mov eax,edi
sub eax,esi
mov [esi+3Ch],eax
pop esi
stub_ok:
ret
ret
binary_stub:
mov esi,edi
mov ecx,40h shr 2
xor eax,eax
rep stos dword [edi]
mov al,2
xor edx,edx
call lseek
push eax
xor al,al
xor edx,edx
call lseek
mov ecx,[esp]
add ecx,40h+111b
and ecx,not 111b
mov ax,cx
and ax,1FFh
mov [esi+2],ax
lea eax,[ecx+1FFh]
shr eax,9
mov [esi+4],ax
mov [esi+3Ch],ecx
sub ecx,40h
mov eax,10000h
sub eax,ecx
jbe binary_heap_ok
shr eax,4
mov [esi+0Ah],ax
mov esi,edi
mov ecx,40h shr 2
xor eax,eax
rep stos dword [edi]
mov al,2
xor edx,edx
call lseek
push eax
xor al,al
xor edx,edx
call lseek
mov ecx,[esp]
add ecx,40h+111b
and ecx,not 111b
mov ax,cx
and ax,1FFh
mov [esi+2],ax
lea eax,[ecx+1FFh]
shr eax,9
mov [esi+4],ax
mov [esi+3Ch],ecx
sub ecx,40h
mov eax,10000h
sub eax,ecx
jbe binary_heap_ok
shr eax,4
mov [esi+0Ah],ax
binary_heap_ok:
mov word [esi],'MZ'
mov word [esi+8],4
mov ax,0FFFFh
mov [esi+0Ch],ax
dec ax
mov [esi+10h],ax
sub ax,0Eh
mov [esi+0Eh],ax
mov [esi+16h],ax
mov word [esi+14h],100h
mov word [esi+18h],40h
mov eax,[display_buffer]
sub eax,ecx
cmp edi,eax
jae out_of_memory
mov edx,edi
shr ecx,2
xor eax,eax
rep stos dword [edi]
pop ecx
call read
call close
pop esi
ret
mov word [esi],'MZ'
mov word [esi+8],4
mov ax,0FFFFh
mov [esi+0Ch],ax
dec ax
mov [esi+10h],ax
sub ax,0Eh
mov [esi+0Eh],ax
mov [esi+16h],ax
mov word [esi+14h],100h
mov word [esi+18h],40h
mov eax,[display_buffer]
sub eax,ecx
cmp edi,eax
jae out_of_memory
mov edx,edi
shr ecx,2
xor eax,eax
rep stos dword [edi]
pop ecx
call read
call close
pop esi
ret
 
format_pe:
xor edx,edx
mov [machine],14Ch
mov [subsystem],3
mov [subsystem_version],3 + 10 shl 16
mov [image_base],400000h
test [format_flags],8
jz pe_settings
mov [machine],8664h
mov [subsystem_version],5 + 0 shl 16
mov [image_base_high],0
xor edx,edx
mov [machine],14Ch
mov [subsystem],3
mov [subsystem_version],3 + 10 shl 16
mov [image_base],400000h
test [format_flags],8
jz pe_settings
mov [machine],8664h
mov [subsystem_version],5 + 0 shl 16
mov [image_base_high],0
pe_settings:
cmp byte [esi],84h
je get_stub_name
cmp byte [esi],80h
je get_pe_base
cmp byte [esi],1Bh
jne pe_settings_ok
lods byte [esi]
lods byte [esi]
test al,80h+40h
jz subsystem_setting
cmp al,80h
je dll_flag
cmp al,81h
je wdm_flag
jmp pe_settings
cmp byte [esi],84h
je get_stub_name
cmp byte [esi],80h
je get_pe_base
cmp byte [esi],1Bh
jne pe_settings_ok
lods byte [esi]
lods byte [esi]
test al,80h+40h
jz subsystem_setting
cmp al,80h
je dll_flag
cmp al,81h
je wdm_flag
jmp pe_settings
dll_flag:
bts [format_flags],8
jc setting_already_specified
jmp pe_settings
bts [format_flags],8
jc setting_already_specified
jmp pe_settings
wdm_flag:
bts [format_flags],9
jc setting_already_specified
jmp pe_settings
bts [format_flags],9
jc setting_already_specified
jmp pe_settings
subsystem_setting:
bts [format_flags],7
jc setting_already_specified
and ax,3Fh
mov [subsystem],ax
cmp byte [esi],'('
jne pe_settings
inc esi
cmp byte [esi],'.'
jne invalid_value
inc esi
push edx
cmp byte [esi+11],0
jne invalid_value
cmp byte [esi+10],2
ja invalid_value
mov dx,[esi+8]
cmp dx,8000h
je zero_version
mov eax,[esi+4]
cmp dx,7
jg invalid_value
mov cx,7
sub cx,dx
mov eax,[esi+4]
shr eax,cl
mov ebx,eax
shr ebx,24
cmp bl,100
jae invalid_value
and eax,0FFFFFFh
mov ecx,100
mul ecx
shrd eax,edx,24
jnc version_value_ok
inc eax
bts [format_flags],7
jc setting_already_specified
and ax,3Fh
mov [subsystem],ax
cmp byte [esi],'('
jne pe_settings
inc esi
cmp byte [esi],'.'
jne invalid_value
inc esi
push edx
cmp byte [esi+11],0
jne invalid_value
cmp byte [esi+10],2
ja invalid_value
mov dx,[esi+8]
cmp dx,8000h
je zero_version
mov eax,[esi+4]
cmp dx,7
jg invalid_value
mov cx,7
sub cx,dx
mov eax,[esi+4]
shr eax,cl
mov ebx,eax
shr ebx,24
cmp bl,100
jae invalid_value
and eax,0FFFFFFh
mov ecx,100
mul ecx
shrd eax,edx,24
jnc version_value_ok
inc eax
version_value_ok:
shl eax,16
mov ax,bx
jmp subsystem_version_ok
shl eax,16
mov ax,bx
jmp subsystem_version_ok
zero_version:
xor eax,eax
xor eax,eax
subsystem_version_ok:
pop edx
add esi,13
mov [subsystem_version],eax
jmp pe_settings
pop edx
add esi,13
mov [subsystem_version],eax
jmp pe_settings
get_pe_base:
bts [format_flags],10
jc setting_already_specified
lods word [esi]
cmp ah,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
push edx edi
add edi,[stub_size]
test [format_flags],8
jnz get_pe64_base
call get_dword_value
mov [image_base],eax
jmp pe_base_ok
bts [format_flags],10
jc setting_already_specified
lods word [esi]
cmp ah,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
push edx edi
add edi,[stub_size]
test [format_flags],8
jnz get_pe64_base
call get_dword_value
mov [image_base],eax
jmp pe_base_ok
get_pe64_base:
call get_qword_value
mov [image_base],eax
mov [image_base_high],edx
call get_qword_value
mov [image_base],eax
mov [image_base_high],edx
pe_base_ok:
pop edi edx
cmp [value_type],0
jne invalid_use_of_symbol
cmp byte [esi],84h
jne pe_settings_ok
pop edi edx
cmp [value_type],0
jne invalid_use_of_symbol
cmp byte [esi],84h
jne pe_settings_ok
get_stub_name:
lods byte [esi]
lods word [esi]
cmp ax,'('
jne invalid_argument
lods dword [esi]
mov edx,esi
add esi,eax
inc esi
lods byte [esi]
lods word [esi]
cmp ax,'('
jne invalid_argument
lods dword [esi]
mov edx,esi
add esi,eax
inc esi
pe_settings_ok:
mov ebp,[stub_size]
or ebp,ebp
jz make_pe_stub
cmp edx,[stub_file]
je pe_stub_ok
sub edi,[stub_size]
mov [code_start],edi
mov ebp,[stub_size]
or ebp,ebp
jz make_pe_stub
cmp edx,[stub_file]
je pe_stub_ok
sub edi,[stub_size]
mov [code_start],edi
make_pe_stub:
call make_stub
mov eax,edi
sub eax,[code_start]
mov [stub_size],eax
mov [code_start],edi
mov ebp,eax
call make_stub
mov eax,edi
sub eax,[code_start]
mov [stub_size],eax
mov [code_start],edi
mov ebp,eax
pe_stub_ok:
mov edx,edi
mov ecx,18h+0E0h
test [format_flags],8
jz zero_pe_header
add ecx,10h
mov edx,edi
mov ecx,18h+0E0h
test [format_flags],8
jz zero_pe_header
add ecx,10h
zero_pe_header:
add ebp,ecx
shr ecx,2
xor eax,eax
rep stos dword [edi]
mov word [edx],'PE' ; signature
mov ax,[machine]
mov word [edx+4],ax
mov dword [edx+38h],1000h ; section alignment
mov dword [edx+3Ch],200h ; file alignment
mov word [edx+40h],1 ; OS version
mov eax,[subsystem_version]
mov [edx+48h],eax
mov ax,[subsystem]
mov [edx+5Ch],ax
cmp ax,1
jne pe_alignment_ok
mov eax,20h
mov dword [edx+38h],eax
mov dword [edx+3Ch],eax
add ebp,ecx
shr ecx,2
xor eax,eax
rep stos dword [edi]
mov word [edx],'PE' ; signature
mov ax,[machine]
mov word [edx+4],ax
mov dword [edx+38h],1000h ; section alignment
mov dword [edx+3Ch],200h ; file alignment
mov word [edx+40h],1 ; OS version
mov eax,[subsystem_version]
mov [edx+48h],eax
mov ax,[subsystem]
mov [edx+5Ch],ax
cmp ax,1
jne pe_alignment_ok
mov eax,20h
mov dword [edx+38h],eax
mov dword [edx+3Ch],eax
pe_alignment_ok:
mov word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8
test [format_flags],8
jnz init_pe64_specific
mov dword [edx+14h],0E0h ; size of optional header
mov dword [edx+16h],10B010Eh; flags and magic value
mov eax,[image_base]
mov dword [edx+34h],eax
mov dword [edx+60h],1000h ; stack reserve
mov dword [edx+64h],1000h ; stack commit
mov dword [edx+68h],10000h ; heap reserve
mov dword [edx+6Ch],0 ; heap commit
mov dword [edx+74h],16 ; number of directories
jmp pe_header_ok
mov word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8
test [format_flags],8
jnz init_pe64_specific
mov dword [edx+14h],0E0h ; size of optional header
mov dword [edx+16h],10B010Eh; flags and magic value
mov eax,[image_base]
mov dword [edx+34h],eax
mov dword [edx+60h],1000h ; stack reserve
mov dword [edx+64h],1000h ; stack commit
mov dword [edx+68h],10000h ; heap reserve
mov dword [edx+6Ch],0 ; heap commit
mov dword [edx+74h],16 ; number of directories
jmp pe_header_ok
init_pe64_specific:
mov dword [edx+14h],0F0h ; size of optional header
mov dword [edx+16h],20B002Eh; flags and magic value
mov eax,[image_base]
mov dword [edx+30h],eax
mov eax,[image_base_high]
mov dword [edx+34h],eax
mov dword [edx+60h],1000h ; stack reserve
mov dword [edx+68h],1000h ; stack commit
mov dword [edx+70h],10000h ; heap reserve
mov dword [edx+78h],0 ; heap commit
mov dword [edx+84h],16 ; number of directories
mov dword [edx+14h],0F0h ; size of optional header
mov dword [edx+16h],20B002Eh; flags and magic value
mov eax,[image_base]
mov dword [edx+30h],eax
mov eax,[image_base_high]
mov dword [edx+34h],eax
mov dword [edx+60h],1000h ; stack reserve
mov dword [edx+68h],1000h ; stack commit
mov dword [edx+70h],10000h ; heap reserve
mov dword [edx+78h],0 ; heap commit
mov dword [edx+84h],16 ; number of directories
pe_header_ok:
bsf ecx,[edx+3Ch]
imul ebx,[number_of_sections],28h
or ebx,ebx
jnz reserve_space_for_section_headers
mov ebx,28h
bsf ecx,[edx+3Ch]
imul ebx,[number_of_sections],28h
or ebx,ebx
jnz reserve_space_for_section_headers
mov ebx,28h
reserve_space_for_section_headers:
add ebx,ebp
dec ebx
shr ebx,cl
inc ebx
shl ebx,cl
sub ebx,ebp
mov ecx,ebx
mov eax,[display_buffer]
sub eax,ecx
cmp edi,eax
jae out_of_memory
shr ecx,2
xor eax,eax
rep stos dword [edi]
mov eax,edi
sub eax,[code_start]
add eax,[stub_size]
mov [edx+54h],eax ; size of headers
mov ecx,[edx+38h]
dec ecx
add eax,ecx
not ecx
and eax,ecx
bt [format_flags],8
jc pe_entry_init_ok
mov [edx+28h],eax ; entry point rva
add ebx,ebp
dec ebx
shr ebx,cl
inc ebx
shl ebx,cl
sub ebx,ebp
mov ecx,ebx
mov eax,[display_buffer]
sub eax,ecx
cmp edi,eax
jae out_of_memory
shr ecx,2
xor eax,eax
rep stos dword [edi]
mov eax,edi
sub eax,[code_start]
add eax,[stub_size]
mov [edx+54h],eax ; size of headers
mov ecx,[edx+38h]
dec ecx
add eax,ecx
not ecx
and eax,ecx
bt [format_flags],8
jc pe_entry_init_ok
mov [edx+28h],eax ; entry point rva
pe_entry_init_ok:
mov [number_of_sections],0
movzx ebx,word [edx+14h]
lea ebx,[edx+18h+ebx]
mov [current_section],ebx
mov dword [ebx],'.fla'
mov dword [ebx+4],'t'
mov [ebx+14h],edi
mov [ebx+0Ch],eax
mov dword [ebx+24h],0E0000060h
xor ecx,ecx
not eax
not ecx
add eax,1
adc ecx,0
add eax,edi
adc ecx,0
test [format_flags],8
jnz pe64_org
sub eax,[edx+34h]
sbb ecx,0
mov bl,2
mov [code_type],32
jmp pe_org_ok
mov [number_of_sections],0
movzx ebx,word [edx+14h]
lea ebx,[edx+18h+ebx]
mov [current_section],ebx
mov dword [ebx],'.fla'
mov dword [ebx+4],'t'
mov [ebx+14h],edi
mov [ebx+0Ch],eax
mov dword [ebx+24h],0E0000060h
xor ecx,ecx
not eax
not ecx
add eax,1
adc ecx,0
add eax,edi
adc ecx,0
test [format_flags],8
jnz pe64_org
sub eax,[edx+34h]
sbb ecx,0
mov bl,2
mov [code_type],32
jmp pe_org_ok
pe64_org:
sub eax,[edx+30h]
sbb ecx,[edx+34h]
mov bl,4
mov [code_type],64
sub eax,[edx+30h]
sbb ecx,[edx+34h]
mov bl,4
mov [code_type],64
pe_org_ok:
bt [resolver_flags],0
jc pe_labels_type_ok
xor bl,bl
bt [resolver_flags],0
jc pe_labels_type_ok
xor bl,bl
pe_labels_type_ok:
mov [labels_type],bl
mov dword [org_origin],eax
mov dword [org_origin+4],ecx
mov [org_registers],0
mov [org_start],edi
bt [format_flags],8
jnc dll_flag_ok
or dword [edx+16h],2000h
mov [labels_type],bl
mov dword [org_origin],eax
mov dword [org_origin+4],ecx
mov [org_registers],0
mov [org_start],edi
bt [format_flags],8
jnc dll_flag_ok
or dword [edx+16h],2000h
dll_flag_ok:
bt [format_flags],9
jnc wdm_flag_ok
or word [edx+5Eh],2000h
bt [format_flags],9
jnc wdm_flag_ok
or word [edx+5Eh],2000h
wdm_flag_ok:
jmp instruction_assembled
jmp instruction_assembled
pe_section:
call close_pe_section
bts [format_flags],5
lea ecx,[ebx+28h]
add edx,[edx+54h]
sub edx,[stub_size]
cmp ecx,edx
jbe new_section
lea ebx,[edx-28h]
or [next_pass_needed],-1
push edi
mov edi,ebx
mov ecx,28h shr 4
xor eax,eax
rep stos dword [edi]
pop edi
call close_pe_section
bts [format_flags],5
lea ecx,[ebx+28h]
add edx,[edx+54h]
sub edx,[stub_size]
cmp ecx,edx
jbe new_section
lea ebx,[edx-28h]
or [next_pass_needed],-1
push edi
mov edi,ebx
mov ecx,28h shr 4
xor eax,eax
rep stos dword [edi]
pop edi
new_section:
mov [ebx+0Ch],eax
lods word [esi]
cmp ax,'('
jne invalid_argument
lea edx,[esi+4]
mov ecx,[esi]
lea esi,[esi+4+ecx+1]
cmp ecx,8
ja name_too_long
xor eax,eax
mov [ebx],eax
mov [ebx+4],eax
push esi edi
mov edi,ebx
mov esi,edx
rep movs byte [edi],[esi]
pop edi esi
mov dword [ebx+24h],0
mov [ebx+14h],edi
mov edx,[code_start]
mov eax,edi
xor ecx,ecx
sub eax,[ebx+0Ch]
sbb ecx,0
test [format_flags],8
jnz pe64_section_org
sub eax,[edx+34h]
sbb ecx,0
mov [labels_type],2
mov [code_type],32
bt [resolver_flags],0
jc pe_section_org_ok
mov [labels_type],0
jmp pe_section_org_ok
mov [ebx+0Ch],eax
lods word [esi]
cmp ax,'('
jne invalid_argument
lea edx,[esi+4]
mov ecx,[esi]
lea esi,[esi+4+ecx+1]
cmp ecx,8
ja name_too_long
xor eax,eax
mov [ebx],eax
mov [ebx+4],eax
push esi edi
mov edi,ebx
mov esi,edx
rep movs byte [edi],[esi]
pop edi esi
mov dword [ebx+24h],0
mov [ebx+14h],edi
mov edx,[code_start]
mov eax,edi
xor ecx,ecx
sub eax,[ebx+0Ch]
sbb ecx,0
test [format_flags],8
jnz pe64_section_org
sub eax,[edx+34h]
sbb ecx,0
mov [labels_type],2
mov [code_type],32
bt [resolver_flags],0
jc pe_section_org_ok
mov [labels_type],0
jmp pe_section_org_ok
pe64_section_org:
sub eax,[edx+30h]
sbb ecx,[edx+34h]
mov [labels_type],4
mov [code_type],64
bt [resolver_flags],0
jc pe_section_org_ok
mov [labels_type],0
sub eax,[edx+30h]
sbb ecx,[edx+34h]
mov [labels_type],4
mov [code_type],64
bt [resolver_flags],0
jc pe_section_org_ok
mov [labels_type],0
pe_section_org_ok:
mov dword [org_origin],eax
mov dword [org_origin+4],ecx
mov [org_registers],0
mov [org_start],edi
mov dword [org_origin],eax
mov dword [org_origin+4],ecx
mov [org_registers],0
mov [org_start],edi
get_section_flags:
lods byte [esi]
cmp al,1Ah
je set_directory
cmp al,19h
je section_flag
dec esi
jmp instruction_assembled
lods byte [esi]
cmp al,1Ah
je set_directory
cmp al,19h
je section_flag
dec esi
jmp instruction_assembled
set_directory:
movzx eax,byte [esi]
inc esi
mov ecx,ebx
test [format_flags],8
jnz pe64_directory
xchg ecx,[edx+78h+eax*8]
mov dword [edx+78h+eax*8+4],-1
jmp pe_directory_set
movzx eax,byte [esi]
inc esi
mov ecx,ebx
test [format_flags],8
jnz pe64_directory
xchg ecx,[edx+78h+eax*8]
mov dword [edx+78h+eax*8+4],-1
jmp pe_directory_set
pe64_directory:
xchg ecx,[edx+88h+eax*8]
mov dword [edx+88h+eax*8+4],-1
xchg ecx,[edx+88h+eax*8]
mov dword [edx+88h+eax*8+4],-1
pe_directory_set:
or ecx,ecx
jnz data_already_defined
push ebx edx
call generate_pe_data
pop edx ebx
jmp get_section_flags
or ecx,ecx
jnz data_already_defined
push ebx edx
call generate_pe_data
pop edx ebx
jmp get_section_flags
section_flag:
lods byte [esi]
cmp al,9
je invalid_argument
cmp al,11
je invalid_argument
mov cl,al
mov eax,1
shl eax,cl
test dword [ebx+24h],eax
jnz setting_already_specified
or dword [ebx+24h],eax
jmp get_section_flags
lods byte [esi]
cmp al,9
je invalid_argument
cmp al,11
je invalid_argument
mov cl,al
mov eax,1
shl eax,cl
test dword [ebx+24h],eax
jnz setting_already_specified
or dword [ebx+24h],eax
jmp get_section_flags
close_pe_section:
mov ebx,[current_section]
mov edx,[code_start]
mov eax,edi
sub eax,[ebx+14h]
jnz finish_section
bt [format_flags],5
jc finish_section
mov eax,[ebx+0Ch]
ret
mov ebx,[current_section]
mov edx,[code_start]
mov eax,edi
sub eax,[ebx+14h]
jnz finish_section
bt [format_flags],5
jc finish_section
mov eax,[ebx+0Ch]
ret
finish_section:
mov [ebx+8],eax
cmp edi,[undefined_data_end]
jne align_section
cmp dword [edx+38h],1000h
jb align_section
mov edi,[undefined_data_start]
mov [ebx+8],eax
cmp edi,[undefined_data_end]
jne align_section
cmp dword [edx+38h],1000h
jb align_section
mov edi,[undefined_data_start]
align_section:
mov [undefined_data_end],0
mov ebp,edi
sub ebp,[ebx+14h]
mov ecx,[edx+3Ch]
dec ecx
lea eax,[ebp+ecx]
not ecx
and eax,ecx
mov [ebx+10h],eax
sub eax,ebp
mov ecx,eax
xor al,al
rep stos byte [edi]
mov eax,[code_start]
sub eax,[stub_size]
sub [ebx+14h],eax
mov eax,[ebx+8]
or eax,eax
jz udata_ok
cmp dword [ebx+10h],0
jne udata_ok
or byte [ebx+24h],80h
mov [undefined_data_end],0
mov ebp,edi
sub ebp,[ebx+14h]
mov ecx,[edx+3Ch]
dec ecx
lea eax,[ebp+ecx]
not ecx
and eax,ecx
mov [ebx+10h],eax
sub eax,ebp
mov ecx,eax
xor al,al
rep stos byte [edi]
mov eax,[code_start]
sub eax,[stub_size]
sub [ebx+14h],eax
mov eax,[ebx+8]
or eax,eax
jz udata_ok
cmp dword [ebx+10h],0
jne udata_ok
or byte [ebx+24h],80h
udata_ok:
mov ecx,[edx+38h]
dec ecx
add eax,ecx
not ecx
and eax,ecx
add eax,[ebx+0Ch]
add ebx,28h
mov [current_section],ebx
inc word [number_of_sections]
jz format_limitations_exceeded
ret
mov ecx,[edx+38h]
dec ecx
add eax,ecx
not ecx
and eax,ecx
add eax,[ebx+0Ch]
add ebx,28h
mov [current_section],ebx
inc word [number_of_sections]
jz format_limitations_exceeded
ret
data_directive:
cmp [output_format],3
jne illegal_instruction
lods byte [esi]
cmp al,1Ah
je predefined_data_type
cmp al,'('
jne invalid_argument
call get_byte_value
cmp al,16
jb data_type_ok
jmp invalid_value
cmp [output_format],3
jne illegal_instruction
lods byte [esi]
cmp al,1Ah
je predefined_data_type
cmp al,'('
jne invalid_argument
call get_byte_value
cmp al,16
jb data_type_ok
jmp invalid_value
predefined_data_type:
movzx eax,byte [esi]
inc esi
movzx eax,byte [esi]
inc esi
data_type_ok:
mov ebx,[current_section]
mov ecx,edi
sub ecx,[ebx+14h]
add ecx,[ebx+0Ch]
mov edx,[code_start]
test [format_flags],8
jnz pe64_data
xchg ecx,[edx+78h+eax*8]
jmp init_pe_data
mov ebx,[current_section]
mov ecx,edi
sub ecx,[ebx+14h]
add ecx,[ebx+0Ch]
mov edx,[code_start]
test [format_flags],8
jnz pe64_data
xchg ecx,[edx+78h+eax*8]
jmp init_pe_data
pe64_data:
xchg ecx,[edx+88h+eax*8]
xchg ecx,[edx+88h+eax*8]
init_pe_data:
or ecx,ecx
jnz data_already_defined
call allocate_structure_data
mov word [ebx],data_directive-assembler
mov [ebx+2],al
mov edx,[current_line]
mov [ebx+4],edx
call generate_pe_data
jmp instruction_assembled
or ecx,ecx
jnz data_already_defined
call allocate_structure_data
mov word [ebx],data_directive-assembler
mov [ebx+2],al
mov edx,[current_line]
mov [ebx+4],edx
call generate_pe_data
jmp instruction_assembled
end_data:
cmp [output_format],3
jne illegal_instruction
call find_structure_data
jc unexpected_instruction
movzx eax,byte [ebx+2]
mov edx,[current_section]
mov ecx,edi
sub ecx,[edx+14h]
add ecx,[edx+0Ch]
mov edx,[code_start]
test [format_flags],8
jnz end_pe64_data
sub ecx,[edx+78h+eax*8]
mov [edx+78h+eax*8+4],ecx
jmp remove_structure_data
cmp [output_format],3
jne illegal_instruction
call find_structure_data
jc unexpected_instruction
movzx eax,byte [ebx+2]
mov edx,[current_section]
mov ecx,edi
sub ecx,[edx+14h]
add ecx,[edx+0Ch]
mov edx,[code_start]
test [format_flags],8
jnz end_pe64_data
sub ecx,[edx+78h+eax*8]
mov [edx+78h+eax*8+4],ecx
jmp remove_structure_data
end_pe64_data:
sub ecx,[edx+88h+eax*8]
mov [edx+88h+eax*8+4],ecx
jmp remove_structure_data
sub ecx,[edx+88h+eax*8]
mov [edx+88h+eax*8+4],ecx
jmp remove_structure_data
pe_entry:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
test [format_flags],8
jnz pe64_entry
call get_dword_value
mov bl,2
bt [resolver_flags],0
jc check_pe_entry_label_type
xor bl,bl
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
test [format_flags],8
jnz pe64_entry
call get_dword_value
mov bl,2
bt [resolver_flags],0
jc check_pe_entry_label_type
xor bl,bl
check_pe_entry_label_type:
cmp [value_type],bl
je pe_entry_ok
cmp [error_line],0
jne pe_entry_ok
mov edx,[current_line]
mov [error_line],edx
mov [error],invalid_address
cmp [value_type],bl
je pe_entry_ok
cmp [error_line],0
jne pe_entry_ok
mov edx,[current_line]
mov [error_line],edx
mov [error],invalid_address
pe_entry_ok:
mov edx,[code_start]
sub eax,[edx+34h]
mov [edx+28h],eax
jmp instruction_assembled
mov edx,[code_start]
sub eax,[edx+34h]
mov [edx+28h],eax
jmp instruction_assembled
pe64_entry:
call get_qword_value
mov bl,4
bt [resolver_flags],0
jc check_pe64_entry_label_type
xor bl,bl
call get_qword_value
mov bl,4
bt [resolver_flags],0
jc check_pe64_entry_label_type
xor bl,bl
check_pe64_entry_label_type:
cmp [value_type],bl
je pe64_entry_type_ok
cmp [error_line],0
jne pe64_entry_type_ok
mov edx,[current_line]
mov [error_line],edx
mov [error],invalid_address
cmp [value_type],bl
je pe64_entry_type_ok
cmp [error_line],0
jne pe64_entry_type_ok
mov edx,[current_line]
mov [error_line],edx
mov [error],invalid_address
pe64_entry_type_ok:
mov ecx,[code_start]
sub eax,[ecx+30h]
sbb edx,[ecx+34h]
jz pe64_entry_range_ok
mov edx,[current_line]
mov [error_line],edx
mov [error],value_out_of_range
mov ecx,[code_start]
sub eax,[ecx+30h]
sbb edx,[ecx+34h]
jz pe64_entry_range_ok
mov edx,[current_line]
mov [error_line],edx
mov [error],value_out_of_range
pe64_entry_range_ok:
mov [ecx+28h],eax
jmp instruction_assembled
mov [ecx+28h],eax
jmp instruction_assembled
pe_stack:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
test [format_flags],8
jnz pe64_stack
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[code_start]
mov [edx+60h],eax
cmp byte [esi],','
jne default_stack_commit
lods byte [esi]
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[code_start]
mov [edx+64h],eax
cmp eax,[edx+60h]
ja value_out_of_range
jmp instruction_assembled
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
test [format_flags],8
jnz pe64_stack
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[code_start]
mov [edx+60h],eax
cmp byte [esi],','
jne default_stack_commit
lods byte [esi]
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[code_start]
mov [edx+64h],eax
cmp eax,[edx+60h]
ja value_out_of_range
jmp instruction_assembled
default_stack_commit:
mov dword [edx+64h],1000h
mov eax,[edx+60h]
cmp eax,1000h
ja instruction_assembled
mov dword [edx+64h],eax
jmp instruction_assembled
mov dword [edx+64h],1000h
mov eax,[edx+60h]
cmp eax,1000h
ja instruction_assembled
mov dword [edx+64h],eax
jmp instruction_assembled
pe64_stack:
call get_qword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov ecx,[code_start]
mov [ecx+60h],eax
mov [ecx+64h],edx
cmp byte [esi],','
jne default_pe64_stack_commit
lods byte [esi]
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_qword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov ecx,[code_start]
mov [ecx+68h],eax
mov [ecx+6Ch],edx
cmp edx,[ecx+64h]
ja value_out_of_range
jb instruction_assembled
cmp eax,[edx+60h]
ja value_out_of_range
jmp instruction_assembled
call get_qword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov ecx,[code_start]
mov [ecx+60h],eax
mov [ecx+64h],edx
cmp byte [esi],','
jne default_pe64_stack_commit
lods byte [esi]
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_qword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov ecx,[code_start]
mov [ecx+68h],eax
mov [ecx+6Ch],edx
cmp edx,[ecx+64h]
ja value_out_of_range
jb instruction_assembled
cmp eax,[edx+60h]
ja value_out_of_range
jmp instruction_assembled
default_pe64_stack_commit:
mov dword [edx+68h],1000h
cmp dword [edx+64h],0
jne instruction_assembled
mov eax,[edx+60h]
cmp eax,1000h
ja instruction_assembled
mov dword [edx+68h],eax
jmp instruction_assembled
mov dword [edx+68h],1000h
cmp dword [edx+64h],0
jne instruction_assembled
mov eax,[edx+60h]
cmp eax,1000h
ja instruction_assembled
mov dword [edx+68h],eax
jmp instruction_assembled
pe_heap:
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
test [format_flags],8
jnz pe64_heap
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[code_start]
mov [edx+68h],eax
cmp byte [esi],','
jne instruction_assembled
lods byte [esi]
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[code_start]
mov [edx+6Ch],eax
cmp eax,[edx+68h]
ja value_out_of_range
jmp instruction_assembled
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
test [format_flags],8
jnz pe64_heap
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[code_start]
mov [edx+68h],eax
cmp byte [esi],','
jne instruction_assembled
lods byte [esi]
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_dword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,[code_start]
mov [edx+6Ch],eax
cmp eax,[edx+68h]
ja value_out_of_range
jmp instruction_assembled
pe64_heap:
call get_qword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov ecx,[code_start]
mov [ecx+70h],eax
mov [ecx+74h],edx
cmp byte [esi],','
jne instruction_assembled
lods byte [esi]
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_qword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov ecx,[code_start]
mov [ecx+78h],eax
mov [ecx+7Ch],edx
cmp edx,[ecx+74h]
ja value_out_of_range
jb instruction_assembled
cmp eax,[edx+70h]
ja value_out_of_range
jmp instruction_assembled
call get_qword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov ecx,[code_start]
mov [ecx+70h],eax
mov [ecx+74h],edx
cmp byte [esi],','
jne instruction_assembled
lods byte [esi]
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
call get_qword_value
cmp [value_type],0
jne invalid_use_of_symbol
mov ecx,[code_start]
mov [ecx+78h],eax
mov [ecx+7Ch],edx
cmp edx,[ecx+74h]
ja value_out_of_range
jb instruction_assembled
cmp eax,[edx+70h]
ja value_out_of_range
jmp instruction_assembled
mark_pe_relocation:
push eax ebx
mov al,2
test [format_flags],8
jz check_pe_relocation_type
mov al,4
push eax ebx
mov al,2
test [format_flags],8
jz check_pe_relocation_type
mov al,4
check_pe_relocation_type:
cmp [value_type],al
je pe_relocation_type_ok
cmp [error_line],0
jne pe_relocation_type_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
cmp [value_type],al
je pe_relocation_type_ok
cmp [error_line],0
jne pe_relocation_type_ok
mov eax,[current_line]
mov [error_line],eax
mov [error],invalid_use_of_symbol
pe_relocation_type_ok:
mov ebx,[current_section]
mov eax,edi
sub eax,[ebx+14h]
add eax,[ebx+0Ch]
mov ebx,[free_additional_memory]
inc [number_of_relocations]
jz invalid_use_of_symbol
mov [ebx],eax
add ebx,4
cmp ebx,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],ebx
pop ebx eax
ret
mov ebx,[current_section]
mov eax,edi
sub eax,[ebx+14h]
add eax,[ebx+0Ch]
mov ebx,[free_additional_memory]
inc [number_of_relocations]
jz invalid_use_of_symbol
mov [ebx],eax
add ebx,4
cmp ebx,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],ebx
pop ebx eax
ret
generate_pe_data:
cmp al,2
je make_pe_resource
cmp al,5
je make_pe_fixups
ret
cmp al,2
je make_pe_resource
cmp al,5
je make_pe_fixups
ret
make_pe_resource:
cmp byte [esi],82h
jne resource_done
inc esi
lods word [esi]
cmp ax,'('
jne invalid_argument
lods dword [esi]
mov edx,esi
lea esi,[esi+eax+1]
cmp [next_pass_needed],0
je resource_from_file
cmp [current_pass],0
jne reserve_space_for_resource
mov [resource_size],0
cmp byte [esi],82h
jne resource_done
inc esi
lods word [esi]
cmp ax,'('
jne invalid_argument
lods dword [esi]
mov edx,esi
lea esi,[esi+eax+1]
cmp [next_pass_needed],0
je resource_from_file
cmp [current_pass],0
jne reserve_space_for_resource
mov [resource_size],0
reserve_space_for_resource:
add edi,[resource_size]
cmp edi,[display_buffer]
ja out_of_memory
jmp resource_done
add edi,[resource_size]
cmp edi,[display_buffer]
ja out_of_memory
jmp resource_done
resource_from_file:
push esi
mov esi,edx
call open_binary_file
push ebx
mov esi,[free_additional_memory]
lea eax,[esi+20h]
cmp eax,[structures_buffer]
ja out_of_memory
mov edx,esi
mov ecx,20h
call read
jc invalid_file_format
xor eax,eax
cmp [esi],eax
jne invalid_file_format
mov ax,0FFFFh
cmp [esi+8],eax
jne invalid_file_format
cmp [esi+12],eax
jne invalid_file_format
mov eax,20h
cmp [esi+4],eax
jne invalid_file_format
push esi
mov esi,edx
call open_binary_file
push ebx
mov esi,[free_additional_memory]
lea eax,[esi+20h]
cmp eax,[structures_buffer]
ja out_of_memory
mov edx,esi
mov ecx,20h
call read
jc invalid_file_format
xor eax,eax
cmp [esi],eax
jne invalid_file_format
mov ax,0FFFFh
cmp [esi+8],eax
jne invalid_file_format
cmp [esi+12],eax
jne invalid_file_format
mov eax,20h
cmp [esi+4],eax
jne invalid_file_format
read_resource_headers:
test eax,11b
jz resource_file_alignment_ok
mov edx,4
and eax,11b
sub edx,eax
mov al,1
call lseek
test eax,11b
jz resource_file_alignment_ok
mov edx,4
and eax,11b
sub edx,eax
mov al,1
call lseek
resource_file_alignment_ok:
mov [esi],eax
lea edx,[esi+12]
mov ecx,8
call read
jc resource_headers_ok
mov ecx,[esi+16]
add [esi],ecx
lea edx,[esi+20]
sub ecx,8
mov [esi+16],ecx
lea eax,[edx+ecx]
cmp eax,[structures_buffer]
ja out_of_memory
call read
jc invalid_file_format
mov edx,[esi]
add edx,[esi+12]
mov eax,[esi+16]
lea ecx,[esi+20]
lea esi,[ecx+eax]
add ecx,2
cmp word [ecx-2],0FFFFh
je resource_header_type_ok
mov [esi],eax
lea edx,[esi+12]
mov ecx,8
call read
jc resource_headers_ok
mov ecx,[esi+16]
add [esi],ecx
lea edx,[esi+20]
sub ecx,8
mov [esi+16],ecx
lea eax,[edx+ecx]
cmp eax,[structures_buffer]
ja out_of_memory
call read
jc invalid_file_format
mov edx,[esi]
add edx,[esi+12]
mov eax,[esi+16]
lea ecx,[esi+20]
lea esi,[ecx+eax]
add ecx,2
cmp word [ecx-2],0FFFFh
je resource_header_type_ok
check_resource_header_type:
cmp ecx,esi
jae invalid_file_format
cmp word [ecx],0
je resource_header_type_ok
add ecx,2
jmp check_resource_header_type
cmp ecx,esi
jae invalid_file_format
cmp word [ecx],0
je resource_header_type_ok
add ecx,2
jmp check_resource_header_type
resource_header_type_ok:
add ecx,2
cmp word [ecx],0FFFFh
je resource_header_name_ok
add ecx,2
cmp word [ecx],0FFFFh
je resource_header_name_ok
check_resource_header_name:
cmp ecx,esi
jae invalid_file_format
cmp word [ecx],0
je resource_header_name_ok
add ecx,2
jmp check_resource_header_name
cmp ecx,esi
jae invalid_file_format
cmp word [ecx],0
je resource_header_name_ok
add ecx,2
jmp check_resource_header_name
resource_header_name_ok:
xor al,al
call lseek
jmp read_resource_headers
xor al,al
call lseek
jmp read_resource_headers
resource_headers_ok:
xor eax,eax
mov [esi],eax
mov [resource_data],edi
lea eax,[edi+16]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
call make_timestamp
stos dword [edi]
xor eax,eax
stos dword [edi]
stos dword [edi]
xor ebx,ebx
xor eax,eax
mov [esi],eax
mov [resource_data],edi
lea eax,[edi+16]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
call make_timestamp
stos dword [edi]
xor eax,eax
stos dword [edi]
stos dword [edi]
xor ebx,ebx
make_type_name_directory:
mov esi,[free_additional_memory]
xor edx,edx
mov esi,[free_additional_memory]
xor edx,edx
find_type_name:
cmp dword [esi],0
je type_name_ok
add esi,20
cmp word [esi],0FFFFh
je check_next_type_name
or ebx,ebx
jz check_this_type_name
xor ecx,ecx
cmp dword [esi],0
je type_name_ok
add esi,20
cmp word [esi],0FFFFh
je check_next_type_name
or ebx,ebx
jz check_this_type_name
xor ecx,ecx
compare_with_previous_type_name:
mov ax,[esi+ecx]
cmp ax,[ebx+ecx]
ja check_this_type_name
jb check_next_type_name
add ecx,2
mov ax,[esi+ecx]
or ax,[ebx+ecx]
jnz compare_with_previous_type_name
jmp check_next_type_name
mov ax,[esi+ecx]
cmp ax,[ebx+ecx]
ja check_this_type_name
jb check_next_type_name
add ecx,2
mov ax,[esi+ecx]
or ax,[ebx+ecx]
jnz compare_with_previous_type_name
jmp check_next_type_name
check_this_type_name:
or edx,edx
jz type_name_found
xor ecx,ecx
or edx,edx
jz type_name_found
xor ecx,ecx
compare_with_current_type_name:
mov ax,[esi+ecx]
cmp ax,[edx+ecx]
ja check_next_type_name
jb type_name_found
add ecx,2
mov ax,[esi+ecx]
or ax,[edx+ecx]
jnz compare_with_current_type_name
jmp same_type_name
mov ax,[esi+ecx]
cmp ax,[edx+ecx]
ja check_next_type_name
jb type_name_found
add ecx,2
mov ax,[esi+ecx]
or ax,[edx+ecx]
jnz compare_with_current_type_name
jmp same_type_name
type_name_found:
mov edx,esi
mov edx,esi
same_type_name:
mov [esi-16],edi
mov [esi-16],edi
check_next_type_name:
mov eax,[esi-4]
add esi,eax
jmp find_type_name
mov eax,[esi-4]
add esi,eax
jmp find_type_name
type_name_ok:
or edx,edx
jz type_name_directory_done
mov ebx,edx
or edx,edx
jz type_name_directory_done
mov ebx,edx
make_type_name_entry:
mov eax,[resource_data]
inc word [eax+12]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
xor eax,eax
stos dword [edi]
jmp make_type_name_directory
mov eax,[resource_data]
inc word [eax+12]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
xor eax,eax
stos dword [edi]
jmp make_type_name_directory
type_name_directory_done:
mov ebx,-1
mov ebx,-1
make_type_id_directory:
mov esi,[free_additional_memory]
mov edx,10000h
mov esi,[free_additional_memory]
mov edx,10000h
find_type_id:
cmp dword [esi],0
je type_id_ok
add esi,20
cmp word [esi],0FFFFh
jne check_next_type_id
movzx eax,word [esi+2]
cmp eax,ebx
jle check_next_type_id
cmp eax,edx
jg check_next_type_id
mov edx,eax
mov [esi-16],edi
cmp dword [esi],0
je type_id_ok
add esi,20
cmp word [esi],0FFFFh
jne check_next_type_id
movzx eax,word [esi+2]
cmp eax,ebx
jle check_next_type_id
cmp eax,edx
jg check_next_type_id
mov edx,eax
mov [esi-16],edi
check_next_type_id:
mov eax,[esi-4]
add esi,eax
jmp find_type_id
mov eax,[esi-4]
add esi,eax
jmp find_type_id
type_id_ok:
cmp edx,10000h
je type_id_directory_done
mov ebx,edx
cmp edx,10000h
je type_id_directory_done
mov ebx,edx
make_type_id_entry:
mov eax,[resource_data]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
xor eax,eax
stos dword [edi]
jmp make_type_id_directory
mov eax,[resource_data]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
xor eax,eax
stos dword [edi]
jmp make_type_id_directory
type_id_directory_done:
mov esi,[resource_data]
add esi,10h
mov ecx,[esi-4]
or cx,cx
jz resource_directories_ok
mov esi,[resource_data]
add esi,10h
mov ecx,[esi-4]
or cx,cx
jz resource_directories_ok
make_resource_directories:
push ecx
push edi
mov edx,edi
sub edx,[resource_data]
bts edx,31
mov [esi+4],edx
lea eax,[edi+16]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
call make_timestamp
stos dword [edi]
xor eax,eax
stos dword [edi]
stos dword [edi]
mov ebp,esi
xor ebx,ebx
push ecx
push edi
mov edx,edi
sub edx,[resource_data]
bts edx,31
mov [esi+4],edx
lea eax,[edi+16]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
call make_timestamp
stos dword [edi]
xor eax,eax
stos dword [edi]
stos dword [edi]
mov ebp,esi
xor ebx,ebx
make_resource_name_directory:
mov esi,[free_additional_memory]
xor edx,edx
mov esi,[free_additional_memory]
xor edx,edx
find_resource_name:
cmp dword [esi],0
je resource_name_ok
push esi
cmp [esi+4],ebp
jne check_next_resource_name
add esi,20
call skip_resource_name
cmp word [esi],0FFFFh
je check_next_resource_name
or ebx,ebx
jz check_this_resource_name
xor ecx,ecx
cmp dword [esi],0
je resource_name_ok
push esi
cmp [esi+4],ebp
jne check_next_resource_name
add esi,20
call skip_resource_name
cmp word [esi],0FFFFh
je check_next_resource_name
or ebx,ebx
jz check_this_resource_name
xor ecx,ecx
compare_with_previous_resource_name:
mov ax,[esi+ecx]
cmp ax,[ebx+ecx]
ja check_this_resource_name
jb check_next_resource_name
add ecx,2
mov ax,[esi+ecx]
or ax,[ebx+ecx]
jnz compare_with_previous_resource_name
jmp check_next_resource_name
mov ax,[esi+ecx]
cmp ax,[ebx+ecx]
ja check_this_resource_name
jb check_next_resource_name
add ecx,2
mov ax,[esi+ecx]
or ax,[ebx+ecx]
jnz compare_with_previous_resource_name
jmp check_next_resource_name
skip_resource_name:
cmp word [esi],0FFFFh
jne skip_unicode_string
add esi,4
ret
cmp word [esi],0FFFFh
jne skip_unicode_string
add esi,4
ret
skip_unicode_string:
add esi,2
cmp word [esi-2],0
jne skip_unicode_string
ret
add esi,2
cmp word [esi-2],0
jne skip_unicode_string
ret
check_this_resource_name:
or edx,edx
jz resource_name_found
xor ecx,ecx
or edx,edx
jz resource_name_found
xor ecx,ecx
compare_with_current_resource_name:
mov ax,[esi+ecx]
cmp ax,[edx+ecx]
ja check_next_resource_name
jb resource_name_found
add ecx,2
mov ax,[esi+ecx]
or ax,[edx+ecx]
jnz compare_with_current_resource_name
jmp same_resource_name
mov ax,[esi+ecx]
cmp ax,[edx+ecx]
ja check_next_resource_name
jb resource_name_found
add ecx,2
mov ax,[esi+ecx]
or ax,[edx+ecx]
jnz compare_with_current_resource_name
jmp same_resource_name
resource_name_found:
mov edx,esi
mov edx,esi
same_resource_name:
mov eax,[esp]
mov [eax+8],edi
mov eax,[esp]
mov [eax+8],edi
check_next_resource_name:
pop esi
mov eax,[esi+16]
lea esi,[esi+20+eax]
jmp find_resource_name
pop esi
mov eax,[esi+16]
lea esi,[esi+20+eax]
jmp find_resource_name
resource_name_ok:
or edx,edx
jz resource_name_directory_done
mov ebx,edx
or edx,edx
jz resource_name_directory_done
mov ebx,edx
make_resource_name_entry:
mov eax,[esp]
inc word [eax+12]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
xor eax,eax
stos dword [edi]
jmp make_resource_name_directory
mov eax,[esp]
inc word [eax+12]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
xor eax,eax
stos dword [edi]
jmp make_resource_name_directory
resource_name_directory_done:
mov ebx,-1
mov ebx,-1
make_resource_id_directory:
mov esi,[free_additional_memory]
mov edx,10000h
mov esi,[free_additional_memory]
mov edx,10000h
find_resource_id:
cmp dword [esi],0
je resource_id_ok
push esi
cmp [esi+4],ebp
jne check_next_resource_id
add esi,20
call skip_resource_name
cmp word [esi],0FFFFh
jne check_next_resource_id
movzx eax,word [esi+2]
cmp eax,ebx
jle check_next_resource_id
cmp eax,edx
jg check_next_resource_id
mov edx,eax
mov eax,[esp]
mov [eax+8],edi
cmp dword [esi],0
je resource_id_ok
push esi
cmp [esi+4],ebp
jne check_next_resource_id
add esi,20
call skip_resource_name
cmp word [esi],0FFFFh
jne check_next_resource_id
movzx eax,word [esi+2]
cmp eax,ebx
jle check_next_resource_id
cmp eax,edx
jg check_next_resource_id
mov edx,eax
mov eax,[esp]
mov [eax+8],edi
check_next_resource_id:
pop esi
mov eax,[esi+16]
lea esi,[esi+20+eax]
jmp find_resource_id
pop esi
mov eax,[esi+16]
lea esi,[esi+20+eax]
jmp find_resource_id
resource_id_ok:
cmp edx,10000h
je resource_id_directory_done
mov ebx,edx
cmp edx,10000h
je resource_id_directory_done
mov ebx,edx
make_resource_id_entry:
mov eax,[esp]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
xor eax,eax
stos dword [edi]
jmp make_resource_id_directory
mov eax,[esp]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
xor eax,eax
stos dword [edi]
jmp make_resource_id_directory
resource_id_directory_done:
pop eax
mov esi,ebp
pop ecx
add esi,8
dec cx
jnz make_resource_directories
pop eax
mov esi,ebp
pop ecx
add esi,8
dec cx
jnz make_resource_directories
resource_directories_ok:
shr ecx,16
jnz make_resource_directories
mov esi,[resource_data]
add esi,10h
movzx eax,word [esi-4]
movzx edx,word [esi-2]
add eax,edx
lea esi,[esi+eax*8]
push edi ; address of language directories
shr ecx,16
jnz make_resource_directories
mov esi,[resource_data]
add esi,10h
movzx eax,word [esi-4]
movzx edx,word [esi-2]
add eax,edx
lea esi,[esi+eax*8]
push edi ; address of language directories
update_resource_directories:
cmp esi,[esp]
je resource_directories_updated
add esi,10h
mov ecx,[esi-4]
or cx,cx
jz language_directories_ok
cmp esi,[esp]
je resource_directories_updated
add esi,10h
mov ecx,[esi-4]
or cx,cx
jz language_directories_ok
make_language_directories:
push ecx
push edi
mov edx,edi
sub edx,[resource_data]
bts edx,31
mov [esi+4],edx
lea eax,[edi+16]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
call make_timestamp
stos dword [edi]
xor eax,eax
stos dword [edi]
stos dword [edi]
mov ebp,esi
mov ebx,-1
push ecx
push edi
mov edx,edi
sub edx,[resource_data]
bts edx,31
mov [esi+4],edx
lea eax,[edi+16]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
call make_timestamp
stos dword [edi]
xor eax,eax
stos dword [edi]
stos dword [edi]
mov ebp,esi
mov ebx,-1
make_language_id_directory:
mov esi,[free_additional_memory]
mov edx,10000h
mov esi,[free_additional_memory]
mov edx,10000h
find_language_id:
cmp dword [esi],0
je language_id_ok
push esi
cmp [esi+8],ebp
jne check_next_language_id
add esi,20
mov eax,esi
call skip_resource_name
call skip_resource_name
neg eax
add eax,esi
and eax,11b
add esi,eax
cmp dword [esi],0
je language_id_ok
push esi
cmp [esi+8],ebp
jne check_next_language_id
add esi,20
mov eax,esi
call skip_resource_name
call skip_resource_name
neg eax
add eax,esi
and eax,11b
add esi,eax
get_language_id:
movzx eax,word [esi+6]
cmp eax,ebx
jle check_next_language_id
cmp eax,edx
jge check_next_language_id
mov edx,eax
mov eax,[esp]
mov [current_offset],eax
movzx eax,word [esi+6]
cmp eax,ebx
jle check_next_language_id
cmp eax,edx
jge check_next_language_id
mov edx,eax
mov eax,[esp]
mov [current_offset],eax
check_next_language_id:
pop esi
mov eax,[esi+16]
lea esi,[esi+20+eax]
jmp find_language_id
pop esi
mov eax,[esi+16]
lea esi,[esi+20+eax]
jmp find_language_id
language_id_ok:
cmp edx,10000h
je language_id_directory_done
mov ebx,edx
cmp edx,10000h
je language_id_directory_done
mov ebx,edx
make_language_id_entry:
mov eax,[esp]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
mov eax,[current_offset]
stos dword [edi]
jmp make_language_id_directory
mov eax,[esp]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
mov eax,[current_offset]
stos dword [edi]
jmp make_language_id_directory
language_id_directory_done:
pop eax
mov esi,ebp
pop ecx
add esi,8
dec cx
jnz make_language_directories
pop eax
mov esi,ebp
pop ecx
add esi,8
dec cx
jnz make_language_directories
language_directories_ok:
shr ecx,16
jnz make_language_directories
jmp update_resource_directories
shr ecx,16
jnz make_language_directories
jmp update_resource_directories
resource_directories_updated:
mov esi,[resource_data]
push edi
mov esi,[resource_data]
push edi
make_name_strings:
add esi,10h
movzx eax,word [esi-2]
movzx ecx,word [esi-4]
add eax,ecx
lea eax,[esi+eax*8]
push eax
or ecx,ecx
jz string_entries_processed
add esi,10h
movzx eax,word [esi-2]
movzx ecx,word [esi-4]
add eax,ecx
lea eax,[esi+eax*8]
push eax
or ecx,ecx
jz string_entries_processed
process_string_entries:
push ecx
mov edx,edi
sub edx,[resource_data]
bts edx,31
xchg [esi],edx
mov ebx,edi
xor ax,ax
stos word [edi]
push ecx
mov edx,edi
sub edx,[resource_data]
bts edx,31
xchg [esi],edx
mov ebx,edi
xor ax,ax
stos word [edi]
copy_string_data:
lea eax,[edi+2]
cmp eax,[display_buffer]
jae out_of_memory
mov ax,[edx]
or ax,ax
jz string_data_copied
stos word [edi]
inc word [ebx]
add edx,2
jmp copy_string_data
lea eax,[edi+2]
cmp eax,[display_buffer]
jae out_of_memory
mov ax,[edx]
or ax,ax
jz string_data_copied
stos word [edi]
inc word [ebx]
add edx,2
jmp copy_string_data
string_data_copied:
add esi,8
pop ecx
loop process_string_entries
add esi,8
pop ecx
loop process_string_entries
string_entries_processed:
pop esi
cmp esi,[esp]
jb make_name_strings
mov eax,edi
sub eax,[resource_data]
test al,11b
jz resource_strings_alignment_ok
xor ax,ax
stos word [edi]
pop esi
cmp esi,[esp]
jb make_name_strings
mov eax,edi
sub eax,[resource_data]
test al,11b
jz resource_strings_alignment_ok
xor ax,ax
stos word [edi]
resource_strings_alignment_ok:
pop edx
pop ebx ; address of language directories
mov ebp,edi
pop edx
pop ebx ; address of language directories
mov ebp,edi
update_language_directories:
add ebx,10h
movzx eax,word [ebx-2]
movzx ecx,word [ebx-4]
add ecx,eax
add ebx,10h
movzx eax,word [ebx-2]
movzx ecx,word [ebx-4]
add ecx,eax
make_data_records:
push ecx
mov esi,edi
sub esi,[resource_data]
xchg esi,[ebx+4]
lea eax,[edi+16]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,esi
stos dword [edi]
mov eax,[esi+12]
stos dword [edi]
xor eax,eax
stos dword [edi]
stos dword [edi]
pop ecx
add ebx,8
loop make_data_records
cmp ebx,edx
jb update_language_directories
pop ebx ; file handle
mov esi,ebp
mov ebp,edi
push ecx
mov esi,edi
sub esi,[resource_data]
xchg esi,[ebx+4]
lea eax,[edi+16]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,esi
stos dword [edi]
mov eax,[esi+12]
stos dword [edi]
xor eax,eax
stos dword [edi]
stos dword [edi]
pop ecx
add ebx,8
loop make_data_records
cmp ebx,edx
jb update_language_directories
pop ebx ; file handle
mov esi,ebp
mov ebp,edi
update_data_records:
push ebp
mov ecx,edi
mov eax,[current_section]
sub ecx,[eax+14h]
add ecx,[eax+0Ch]
xchg ecx,[esi]
mov edx,[ecx]
xor al,al
call lseek
mov edx,edi
mov ecx,[esi+4]
add edi,ecx
cmp edi,[display_buffer]
ja out_of_memory
call read
mov eax,edi
sub eax,[resource_data]
and eax,11b
jz resource_data_alignment_ok
mov ecx,4
sub ecx,eax
xor al,al
rep stos byte [edi]
push ebp
mov ecx,edi
mov eax,[current_section]
sub ecx,[eax+14h]
add ecx,[eax+0Ch]
xchg ecx,[esi]
mov edx,[ecx]
xor al,al
call lseek
mov edx,edi
mov ecx,[esi+4]
add edi,ecx
cmp edi,[display_buffer]
ja out_of_memory
call read
mov eax,edi
sub eax,[resource_data]
and eax,11b
jz resource_data_alignment_ok
mov ecx,4
sub ecx,eax
xor al,al
rep stos byte [edi]
resource_data_alignment_ok:
pop ebp
add esi,16
cmp esi,ebp
jb update_data_records
pop esi
call close
mov eax,edi
sub eax,[resource_data]
mov [resource_size],eax
pop ebp
add esi,16
cmp esi,ebp
jb update_data_records
pop esi
call close
mov eax,edi
sub eax,[resource_data]
mov [resource_size],eax
resource_done:
ret
ret
make_pe_fixups:
bts [resolver_flags],0
jc pe_relocatable_ok
or [next_pass_needed],-1
bts [resolver_flags],0
jc pe_relocatable_ok
or [next_pass_needed],-1
pe_relocatable_ok:
push esi
mov ecx,[number_of_relocations]
mov esi,[free_additional_memory]
mov eax,ecx
shl eax,2
sub esi,eax
mov [free_additional_memory],esi
or [number_of_relocations],-1
xor edx,edx
mov ebp,edi
push esi
mov ecx,[number_of_relocations]
mov esi,[free_additional_memory]
mov eax,ecx
shl eax,2
sub esi,eax
mov [free_additional_memory],esi
or [number_of_relocations],-1
xor edx,edx
mov ebp,edi
make_fixups:
cmp [esi],edx
jb store_fixup
mov eax,edi
sub eax,ebp
test eax,11b
jz fixups_block
xor ax,ax
stos word [edi]
add dword [ebx],2
cmp [esi],edx
jb store_fixup
mov eax,edi
sub eax,ebp
test eax,11b
jz fixups_block
xor ax,ax
stos word [edi]
add dword [ebx],2
fixups_block:
mov eax,edx
add edx,1000h
cmp [esi],edx
jae fixups_block
stos dword [edi]
mov ebx,edi
mov eax,8
stos dword [edi]
mov eax,edx
add edx,1000h
cmp [esi],edx
jae fixups_block
stos dword [edi]
mov ebx,edi
mov eax,8
stos dword [edi]
store_fixup:
jecxz fixups_done
add dword [ebx],2
mov eax,[esi]
and ax,0FFFh
test [format_flags],8
jnz fixup_64bit
or ax,3000h
jmp fixup_ok
jecxz fixups_done
add dword [ebx],2
mov eax,[esi]
and ax,0FFFh
test [format_flags],8
jnz fixup_64bit
or ax,3000h
jmp fixup_ok
fixup_64bit:
or ax,0A000h
or ax,0A000h
fixup_ok:
stos word [edi]
add esi,4
loop make_fixups
stos word [edi]
add esi,4
loop make_fixups
fixups_done:
pop esi
ret
pop esi
ret
close_pe:
call close_pe_section
mov edx,[code_start]
mov [edx+50h],eax
call make_timestamp
mov edx,[code_start]
mov [edx+8],eax
mov eax,[number_of_relocations]
cmp eax,-1
je pe_relocations_ok
shl eax,2
sub [free_additional_memory],eax
btr [resolver_flags],0
jnc pe_relocations_ok
or [next_pass_needed],-1
call close_pe_section
mov edx,[code_start]
mov [edx+50h],eax
call make_timestamp
mov edx,[code_start]
mov [edx+8],eax
mov eax,[number_of_relocations]
cmp eax,-1
je pe_relocations_ok
shl eax,2
sub [free_additional_memory],eax
btr [resolver_flags],0
jnc pe_relocations_ok
or [next_pass_needed],-1
pe_relocations_ok:
mov eax,[number_of_sections]
mov [edx+6],ax
imul eax,28h
movzx ecx,word [edx+14h]
lea eax,[eax+18h+ecx]
add eax,[stub_size]
mov ecx,[edx+3Ch]
dec ecx
add eax,ecx
not ecx
and eax,ecx
cmp eax,[edx+54h]
je pe_sections_ok
or [next_pass_needed],-1
mov eax,[number_of_sections]
mov [edx+6],ax
imul eax,28h
movzx ecx,word [edx+14h]
lea eax,[eax+18h+ecx]
add eax,[stub_size]
mov ecx,[edx+3Ch]
dec ecx
add eax,ecx
not ecx
and eax,ecx
cmp eax,[edx+54h]
je pe_sections_ok
or [next_pass_needed],-1
pe_sections_ok:
xor ecx,ecx
add edx,78h
test [format_flags],8
jz process_directories
add edx,10h
xor ecx,ecx
add edx,78h
test [format_flags],8
jz process_directories
add edx,10h
process_directories:
mov eax,[edx+ecx*8]
or eax,eax
jz directory_ok
cmp dword [edx+ecx*8+4],-1
jne directory_ok
mov eax,[edx+ecx*8]
or eax,eax
jz directory_ok
cmp dword [edx+ecx*8+4],-1
jne directory_ok
section_data:
mov ebx,[edx+ecx*8]
mov eax,[ebx+0Ch]
mov [edx+ecx*8],eax ; directory rva
mov eax,[ebx+8]
mov [edx+ecx*8+4],eax ; directory size
mov ebx,[edx+ecx*8]
mov eax,[ebx+0Ch]
mov [edx+ecx*8],eax ; directory rva
mov eax,[ebx+8]
mov [edx+ecx*8+4],eax ; directory size
directory_ok:
inc cl
cmp cl,10h
jb process_directories
mov ebx,[code_start]
sub ebx,[stub_size]
mov ecx,edi
sub ecx,ebx
mov ebp,ecx
shr ecx,1
xor eax,eax
cdq
inc cl
cmp cl,10h
jb process_directories
mov ebx,[code_start]
sub ebx,[stub_size]
mov ecx,edi
sub ecx,ebx
mov ebp,ecx
shr ecx,1
xor eax,eax
cdq
calculate_checksum:
mov dx,[ebx]
add eax,edx
mov dx,ax
shr eax,16
add eax,edx
add ebx,2
loop calculate_checksum
add eax,ebp
mov ebx,[code_start]
mov [ebx+58h],eax
ret
mov dx,[ebx]
add eax,edx
mov dx,ax
shr eax,16
add eax,edx
add ebx,2
loop calculate_checksum
add eax,ebp
mov ebx,[code_start]
mov [ebx+58h],eax
ret
 
format_coff:
mov eax,[additional_memory]
mov [symbols_stream],eax
mov ebx,eax
add eax,20h
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
xor eax,eax
mov [ebx],al
mov [ebx+4],eax
mov [ebx+8],edi
mov al,4
mov [ebx+10h],eax
mov al,60h
bt [format_flags],0
jnc flat_section_flags_ok
or eax,0E0000000h
mov eax,[additional_memory]
mov [symbols_stream],eax
mov ebx,eax
add eax,20h
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
xor eax,eax
mov [ebx],al
mov [ebx+4],eax
mov [ebx+8],edi
mov al,4
mov [ebx+10h],eax
mov al,60h
bt [format_flags],0
jnc flat_section_flags_ok
or eax,0E0000000h
flat_section_flags_ok:
mov dword [ebx+14h],eax
mov [current_section],ebx
mov [number_of_sections],0
mov dword [org_origin],edi
mov dword [org_origin+4],0
mov [org_registers],0
mov [org_start],edi
mov [org_symbol],ebx
mov [labels_type],2
mov [code_type],32
test [format_flags],8
jz instruction_assembled
mov [labels_type],4
mov [code_type],64
jmp instruction_assembled
mov dword [ebx+14h],eax
mov [current_section],ebx
mov [number_of_sections],0
mov dword [org_origin],edi
mov dword [org_origin+4],0
mov [org_registers],0
mov [org_start],edi
mov [org_symbol],ebx
mov [labels_type],2
mov [code_type],32
test [format_flags],8
jz instruction_assembled
mov [labels_type],4
mov [code_type],64
jmp instruction_assembled
coff_section:
call close_coff_section
mov ebx,[free_additional_memory]
lea eax,[ebx+20h]
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
mov [current_section],ebx
inc [number_of_sections]
xor eax,eax
mov [ebx],al
mov [ebx+8],edi
mov dword [org_origin],edi
mov dword [org_origin+4],0
mov [org_registers],0
mov [org_start],edi
mov [org_symbol],ebx
mov [labels_type],2
test [format_flags],8
jz coff_labels_type_ok
mov [labels_type],4
call close_coff_section
mov ebx,[free_additional_memory]
lea eax,[ebx+20h]
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
mov [current_section],ebx
inc [number_of_sections]
xor eax,eax
mov [ebx],al
mov [ebx+8],edi
mov dword [org_origin],edi
mov dword [org_origin+4],0
mov [org_registers],0
mov [org_start],edi
mov [org_symbol],ebx
mov [labels_type],2
test [format_flags],8
jz coff_labels_type_ok
mov [labels_type],4
coff_labels_type_ok:
mov [ebx+10h],eax
mov [ebx+14h],eax
lods word [esi]
cmp ax,'('
jne invalid_argument
mov [ebx+4],esi
mov ecx,[esi]
lea esi,[esi+4+ecx+1]
cmp ecx,8
ja name_too_long
mov [ebx+10h],eax
mov [ebx+14h],eax
lods word [esi]
cmp ax,'('
jne invalid_argument
mov [ebx+4],esi
mov ecx,[esi]
lea esi,[esi+4+ecx+1]
cmp ecx,8
ja name_too_long
coff_section_flags:
cmp byte [esi],1Ch
je coff_section_alignment
cmp byte [esi],19h
jne coff_section_settings_ok
inc esi
lods byte [esi]
bt [format_flags],0
jc coff_section_flag_ok
cmp al,7
ja invalid_argument
cmp byte [esi],1Ch
je coff_section_alignment
cmp byte [esi],19h
jne coff_section_settings_ok
inc esi
lods byte [esi]
bt [format_flags],0
jc coff_section_flag_ok
cmp al,7
ja invalid_argument
coff_section_flag_ok:
mov cl,al
mov eax,1
shl eax,cl
test dword [ebx+14h],eax
jnz setting_already_specified
or dword [ebx+14h],eax
jmp coff_section_flags
mov cl,al
mov eax,1
shl eax,cl
test dword [ebx+14h],eax
jnz setting_already_specified
or dword [ebx+14h],eax
jmp coff_section_flags
coff_section_alignment:
bt [format_flags],0
jnc invalid_argument
inc esi
lods byte [esi]
or al,al
jnz invalid_argument
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
push ebx
call get_dword_value
pop ebx
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,eax
dec edx
test eax,edx
jnz invalid_value
or eax,eax
jz invalid_value
cmp eax,2000h
ja invalid_value
bsf edx,eax
inc edx
shl edx,20
or [ebx+14h],edx
xchg [ebx+10h],eax
or eax,eax
jnz setting_already_specified
jmp coff_section_flags
bt [format_flags],0
jnc invalid_argument
inc esi
lods byte [esi]
or al,al
jnz invalid_argument
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
push ebx
call get_dword_value
pop ebx
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,eax
dec edx
test eax,edx
jnz invalid_value
or eax,eax
jz invalid_value
cmp eax,2000h
ja invalid_value
bsf edx,eax
inc edx
shl edx,20
or [ebx+14h],edx
xchg [ebx+10h],eax
or eax,eax
jnz setting_already_specified
jmp coff_section_flags
coff_section_settings_ok:
cmp dword [ebx+10h],0
jne instruction_assembled
mov dword [ebx+10h],4
bt [format_flags],0
jnc instruction_assembled
or dword [ebx+14h],300000h
jmp instruction_assembled
cmp dword [ebx+10h],0
jne instruction_assembled
mov dword [ebx+10h],4
bt [format_flags],0
jnc instruction_assembled
or dword [ebx+14h],300000h
jmp instruction_assembled
close_coff_section:
mov ebx,[current_section]
mov eax,edi
mov edx,[ebx+8]
sub eax,edx
mov [ebx+0Ch],eax
xor eax,eax
xchg [undefined_data_end],eax
cmp eax,edi
jne coff_section_ok
cmp edx,[undefined_data_start]
jne coff_section_ok
mov edi,edx
or byte [ebx+14h],80h
mov ebx,[current_section]
mov eax,edi
mov edx,[ebx+8]
sub eax,edx
mov [ebx+0Ch],eax
xor eax,eax
xchg [undefined_data_end],eax
cmp eax,edi
jne coff_section_ok
cmp edx,[undefined_data_start]
jne coff_section_ok
mov edi,edx
or byte [ebx+14h],80h
coff_section_ok:
ret
ret
mark_coff_relocation:
cmp [value_type],3
je coff_relocation_relative
push ebx eax
test [format_flags],8
jnz coff_64bit_relocation
mov al,6
jmp coff_relocation
cmp [value_type],3
je coff_relocation_relative
push ebx eax
test [format_flags],8
jnz coff_64bit_relocation
mov al,6
jmp coff_relocation
coff_64bit_relocation:
mov al,1
cmp [value_type],4
je coff_relocation
mov al,2
jmp coff_relocation
mov al,1
cmp [value_type],4
je coff_relocation
mov al,2
jmp coff_relocation
coff_relocation_relative:
push ebx
bt [format_flags],0
jnc relative_ok
mov ebx,[current_section]
mov ebx,[ebx+8]
sub ebx,edi
sub eax,ebx
add eax,4
push ebx
bt [format_flags],0
jnc relative_ok
mov ebx,[current_section]
mov ebx,[ebx+8]
sub ebx,edi
sub eax,ebx
add eax,4
relative_ok:
push eax
mov al,20
test [format_flags],8
jnz relative_coff_64bit_relocation
cmp [labels_type],2
jne invalid_use_of_symbol
jmp coff_relocation
push eax
mov al,20
test [format_flags],8
jnz relative_coff_64bit_relocation
cmp [labels_type],2
jne invalid_use_of_symbol
jmp coff_relocation
relative_coff_64bit_relocation:
mov al,4
cmp [labels_type],4
jne invalid_use_of_symbol
mov al,4
cmp [labels_type],4
jne invalid_use_of_symbol
coff_relocation:
mov ebx,[free_additional_memory]
add ebx,0Ch
cmp ebx,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],ebx
mov byte [ebx-0Ch],al
mov eax,[current_section]
mov eax,[eax+8]
neg eax
add eax,edi
mov [ebx-0Ch+4],eax
mov eax,[symbol_identifier]
mov [ebx-0Ch+8],eax
pop eax ebx
ret
mov ebx,[free_additional_memory]
add ebx,0Ch
cmp ebx,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],ebx
mov byte [ebx-0Ch],al
mov eax,[current_section]
mov eax,[eax+8]
neg eax
add eax,edi
mov [ebx-0Ch+4],eax
mov eax,[symbol_identifier]
mov [ebx-0Ch+8],eax
pop eax ebx
ret
close_coff:
call close_coff_section
cmp [next_pass_needed],0
je coff_closed
mov eax,[symbols_stream]
mov [free_additional_memory],eax
call close_coff_section
cmp [next_pass_needed],0
je coff_closed
mov eax,[symbols_stream]
mov [free_additional_memory],eax
coff_closed:
ret
ret
coff_formatter:
sub edi,[code_start]
mov [code_size],edi
call prepare_default_section
mov edi,[free_additional_memory]
mov ebx,edi
mov ecx,28h shr 2
imul ecx,[number_of_sections]
add ecx,14h shr 2
lea eax,[edi+ecx*4]
cmp eax,[structures_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
mov word [ebx],14Ch
test [format_flags],8
jz coff_magic_ok
mov word [ebx],8664h
sub edi,[code_start]
mov [code_size],edi
call prepare_default_section
mov edi,[free_additional_memory]
mov ebx,edi
mov ecx,28h shr 2
imul ecx,[number_of_sections]
add ecx,14h shr 2
lea eax,[edi+ecx*4]
cmp eax,[structures_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
mov word [ebx],14Ch
test [format_flags],8
jz coff_magic_ok
mov word [ebx],8664h
coff_magic_ok:
mov word [ebx+12h],104h
bt [format_flags],0
jnc coff_flags_ok
or byte [ebx+12h],80h
mov word [ebx+12h],104h
bt [format_flags],0
jnc coff_flags_ok
or byte [ebx+12h],80h
coff_flags_ok:
push ebx
call make_timestamp
pop ebx
mov [ebx+4],eax
mov eax,[number_of_sections]
mov [ebx+2],ax
mov esi,[symbols_stream]
xor eax,eax
xor ecx,ecx
push ebx
call make_timestamp
pop ebx
mov [ebx+4],eax
mov eax,[number_of_sections]
mov [ebx+2],ax
mov esi,[symbols_stream]
xor eax,eax
xor ecx,ecx
enumerate_symbols:
cmp esi,[free_additional_memory]
je symbols_enumerated
mov dl,[esi]
or dl,dl
jz enumerate_section
cmp dl,80h
je enumerate_public
ja enumerate_extrn
add esi,0Ch
jmp enumerate_symbols
cmp esi,[free_additional_memory]
je symbols_enumerated
mov dl,[esi]
or dl,dl
jz enumerate_section
cmp dl,80h
je enumerate_public
ja enumerate_extrn
add esi,0Ch
jmp enumerate_symbols
enumerate_section:
mov edx,eax
shl edx,8
mov [esi],edx
inc eax
inc ecx
mov [esi+1Eh],cx
add esi,20h
jmp enumerate_symbols
mov edx,eax
shl edx,8
mov [esi],edx
inc eax
inc ecx
mov [esi+1Eh],cx
add esi,20h
jmp enumerate_symbols
enumerate_public:
mov edx,eax
shl edx,8
mov dl,80h
mov [esi],edx
mov edx,[esi+8]
add esi,10h
inc eax
cmp byte [edx+11],2
jne enumerate_symbols
mov edx,[edx+20]
cmp byte [edx],81h
jne enumerate_symbols
inc eax
jmp enumerate_symbols
mov edx,eax
shl edx,8
mov dl,80h
mov [esi],edx
mov edx,[esi+8]
add esi,10h
inc eax
cmp byte [edx+11],2
jne enumerate_symbols
mov edx,[edx+20]
cmp byte [edx],81h
jne enumerate_symbols
inc eax
jmp enumerate_symbols
enumerate_extrn:
mov edx,eax
shl edx,8
mov dl,81h
mov [esi],edx
add esi,0Ch
inc eax
jmp enumerate_symbols
mov edx,eax
shl edx,8
mov dl,81h
mov [esi],edx
add esi,0Ch
inc eax
jmp enumerate_symbols
prepare_default_section:
mov ebx,[symbols_stream]
cmp dword [ebx+0Ch],0
jne default_section_ok
cmp [number_of_sections],0
je default_section_ok
mov edx,ebx
mov ebx,[symbols_stream]
cmp dword [ebx+0Ch],0
jne default_section_ok
cmp [number_of_sections],0
je default_section_ok
mov edx,ebx
find_references_to_default_section:
cmp ebx,[free_additional_memory]
jne check_reference
add [symbols_stream],20h
ret
cmp ebx,[free_additional_memory]
jne check_reference
add [symbols_stream],20h
ret
check_reference:
mov al,[ebx]
or al,al
jz skip_other_section
cmp al,80h
je check_public_reference
ja next_reference
cmp edx,[ebx+8]
je default_section_ok
mov al,[ebx]
or al,al
jz skip_other_section
cmp al,80h
je check_public_reference
ja next_reference
cmp edx,[ebx+8]
je default_section_ok
next_reference:
add ebx,0Ch
jmp find_references_to_default_section
add ebx,0Ch
jmp find_references_to_default_section
check_public_reference:
mov eax,[ebx+8]
add ebx,10h
test byte [eax+8],1
jz find_references_to_default_section
mov cx,[current_pass]
cmp cx,[eax+16]
jne find_references_to_default_section
cmp edx,[eax+20]
je default_section_ok
jmp find_references_to_default_section
mov eax,[ebx+8]
add ebx,10h
test byte [eax+8],1
jz find_references_to_default_section
mov cx,[current_pass]
cmp cx,[eax+16]
jne find_references_to_default_section
cmp edx,[eax+20]
je default_section_ok
jmp find_references_to_default_section
skip_other_section:
add ebx,20h
jmp find_references_to_default_section
add ebx,20h
jmp find_references_to_default_section
default_section_ok:
inc [number_of_sections]
ret
inc [number_of_sections]
ret
symbols_enumerated:
mov [ebx+0Ch],eax
mov ebp,edi
sub ebp,ebx
push ebp
lea edi,[ebx+14h]
mov esi,[symbols_stream]
mov [ebx+0Ch],eax
mov ebp,edi
sub ebp,ebx
push ebp
lea edi,[ebx+14h]
mov esi,[symbols_stream]
find_section:
cmp esi,[free_additional_memory]
je sections_finished
mov al,[esi]
or al,al
jz section_found
add esi,0Ch
cmp al,80h
jne find_section
add esi,4
jmp find_section
cmp esi,[free_additional_memory]
je sections_finished
mov al,[esi]
or al,al
jz section_found
add esi,0Ch
cmp al,80h
jne find_section
add esi,4
jmp find_section
section_found:
push esi edi
mov esi,[esi+4]
or esi,esi
jz default_section
mov ecx,[esi]
add esi,4
rep movs byte [edi],[esi]
jmp section_name_ok
push esi edi
mov esi,[esi+4]
or esi,esi
jz default_section
mov ecx,[esi]
add esi,4
rep movs byte [edi],[esi]
jmp section_name_ok
default_section:
mov al,'.'
stos byte [edi]
mov eax,'flat'
stos dword [edi]
mov al,'.'
stos byte [edi]
mov eax,'flat'
stos dword [edi]
section_name_ok:
pop edi esi
mov eax,[esi+0Ch]
mov [edi+10h],eax
mov eax,[esi+14h]
mov [edi+24h],eax
test al,80h
jnz section_ptr_ok
mov eax,[esi+8]
sub eax,[code_start]
add eax,ebp
mov [edi+14h],eax
pop edi esi
mov eax,[esi+0Ch]
mov [edi+10h],eax
mov eax,[esi+14h]
mov [edi+24h],eax
test al,80h
jnz section_ptr_ok
mov eax,[esi+8]
sub eax,[code_start]
add eax,ebp
mov [edi+14h],eax
section_ptr_ok:
mov ebx,[code_start]
mov edx,[code_size]
add ebx,edx
add edx,ebp
xor ecx,ecx
add esi,20h
mov ebx,[code_start]
mov edx,[code_size]
add ebx,edx
add edx,ebp
xor ecx,ecx
add esi,20h
find_relocations:
cmp esi,[free_additional_memory]
je section_relocations_done
mov al,[esi]
or al,al
jz section_relocations_done
cmp al,80h
jb add_relocation
ja next_relocation
add esi,10h
jmp find_relocations
cmp esi,[free_additional_memory]
je section_relocations_done
mov al,[esi]
or al,al
jz section_relocations_done
cmp al,80h
jb add_relocation
ja next_relocation
add esi,10h
jmp find_relocations
add_relocation:
lea eax,[ebx+0Ah]
cmp eax,[display_buffer]
ja out_of_memory
mov eax,[esi+4]
mov [ebx],eax
mov eax,[esi+8]
mov eax,[eax]
shr eax,8
mov [ebx+4],eax
movzx ax,byte [esi]
mov [ebx+8],ax
add ebx,0Ah
inc ecx
lea eax,[ebx+0Ah]
cmp eax,[display_buffer]
ja out_of_memory
mov eax,[esi+4]
mov [ebx],eax
mov eax,[esi+8]
mov eax,[eax]
shr eax,8
mov [ebx+4],eax
movzx ax,byte [esi]
mov [ebx+8],ax
add ebx,0Ah
inc ecx
next_relocation:
add esi,0Ch
jmp find_relocations
add esi,0Ch
jmp find_relocations
section_relocations_done:
cmp ecx,10000h
jb section_relocations_count_16bit
bt [format_flags],0
jnc format_limitations_exceeded
mov word [edi+20h],0FFFFh
or dword [edi+24h],1000000h
mov [edi+18h],edx
push esi edi
push ecx
lea esi,[ebx-1]
add ebx,0Ah
lea edi,[ebx-1]
imul ecx,0Ah
std
rep movs byte [edi],[esi]
cld
pop ecx
inc esi
inc ecx
mov [esi],ecx
xor eax,eax
mov [esi+4],eax
mov [esi+8],ax
pop edi esi
jmp section_relocations_ok
cmp ecx,10000h
jb section_relocations_count_16bit
bt [format_flags],0
jnc format_limitations_exceeded
mov word [edi+20h],0FFFFh
or dword [edi+24h],1000000h
mov [edi+18h],edx
push esi edi
push ecx
lea esi,[ebx-1]
add ebx,0Ah
lea edi,[ebx-1]
imul ecx,0Ah
std
rep movs byte [edi],[esi]
cld
pop ecx
inc esi
inc ecx
mov [esi],ecx
xor eax,eax
mov [esi+4],eax
mov [esi+8],ax
pop edi esi
jmp section_relocations_ok
section_relocations_count_16bit:
mov [edi+20h],cx
jcxz section_relocations_ok
mov [edi+18h],edx
mov [edi+20h],cx
jcxz section_relocations_ok
mov [edi+18h],edx
section_relocations_ok:
sub ebx,[code_start]
mov [code_size],ebx
add edi,28h
jmp find_section
sub ebx,[code_start]
mov [code_size],ebx
add edi,28h
jmp find_section
sections_finished:
mov edx,[free_additional_memory]
mov ebx,[code_size]
add ebp,ebx
mov [edx+8],ebp
add ebx,[code_start]
mov edi,ebx
mov ecx,[edx+0Ch]
imul ecx,12h shr 1
xor eax,eax
shr ecx,1
jnc zero_symbols_table
stos word [edi]
mov edx,[free_additional_memory]
mov ebx,[code_size]
add ebp,ebx
mov [edx+8],ebp
add ebx,[code_start]
mov edi,ebx
mov ecx,[edx+0Ch]
imul ecx,12h shr 1
xor eax,eax
shr ecx,1
jnc zero_symbols_table
stos word [edi]
zero_symbols_table:
rep stos dword [edi]
mov edx,edi
stos dword [edi]
mov esi,[symbols_stream]
rep stos dword [edi]
mov edx,edi
stos dword [edi]
mov esi,[symbols_stream]
make_symbols_table:
cmp esi,[free_additional_memory]
je symbols_table_ok
mov al,[esi]
cmp al,80h
je add_public_symbol
ja add_extrn_symbol
or al,al
jz add_section_symbol
add esi,0Ch
jmp make_symbols_table
cmp esi,[free_additional_memory]
je symbols_table_ok
mov al,[esi]
cmp al,80h
je add_public_symbol
ja add_extrn_symbol
or al,al
jz add_section_symbol
add esi,0Ch
jmp make_symbols_table
add_section_symbol:
call store_symbol_name
movzx eax,word [esi+1Eh]
mov [ebx+0Ch],ax
mov byte [ebx+10h],3
add esi,20h
add ebx,12h
jmp make_symbols_table
call store_symbol_name
movzx eax,word [esi+1Eh]
mov [ebx+0Ch],ax
mov byte [ebx+10h],3
add esi,20h
add ebx,12h
jmp make_symbols_table
add_extrn_symbol:
call store_symbol_name
mov byte [ebx+10h],2
add esi,0Ch
add ebx,12h
jmp make_symbols_table
call store_symbol_name
mov byte [ebx+10h],2
add esi,0Ch
add ebx,12h
jmp make_symbols_table
add_public_symbol:
call store_symbol_name
mov eax,[esi+0Ch]
mov [current_line],eax
mov eax,[esi+8]
test byte [eax+8],1
jz undefined_symbol
mov cx,[current_pass]
cmp cx,[eax+16]
jne undefined_symbol
mov cl,[eax+11]
or cl,cl
jz public_constant
test [format_flags],8
jnz check_64bit_public_symbol
cmp cl,2
je public_symbol_type_ok
jmp invalid_use_of_symbol
call store_symbol_name
mov eax,[esi+0Ch]
mov [current_line],eax
mov eax,[esi+8]
test byte [eax+8],1
jz undefined_symbol
mov cx,[current_pass]
cmp cx,[eax+16]
jne undefined_symbol
mov cl,[eax+11]
or cl,cl
jz public_constant
test [format_flags],8
jnz check_64bit_public_symbol
cmp cl,2
je public_symbol_type_ok
jmp invalid_use_of_symbol
check_64bit_public_symbol:
cmp cl,4
jne invalid_use_of_symbol
cmp cl,4
jne invalid_use_of_symbol
public_symbol_type_ok:
mov ecx,[eax+20]
cmp byte [ecx],81h
je alias_symbol
cmp byte [ecx],0
jne invalid_use_of_symbol
mov cx,[ecx+1Eh]
mov [ebx+0Ch],cx
mov ecx,[eax+20]
cmp byte [ecx],81h
je alias_symbol
cmp byte [ecx],0
jne invalid_use_of_symbol
mov cx,[ecx+1Eh]
mov [ebx+0Ch],cx
public_symbol_section_ok:
cmp dword [eax+4],0
je store_public_symbol
cmp dword [eax+4],-1
jne value_out_of_range
bt dword [eax],31
jnc value_out_of_range
cmp dword [eax+4],0
je store_public_symbol
cmp dword [eax+4],-1
jne value_out_of_range
bt dword [eax],31
jnc value_out_of_range
store_public_symbol:
mov eax,[eax]
mov [ebx+8],eax
mov byte [ebx+10h],2
add esi,10h
add ebx,12h
jmp make_symbols_table
mov eax,[eax]
mov [ebx+8],eax
mov byte [ebx+10h],2
add esi,10h
add ebx,12h
jmp make_symbols_table
alias_symbol:
bt [format_flags],0
jnc invalid_use_of_symbol
mov ecx,[eax]
or ecx,[eax+4]
jnz invalid_use_of_symbol
mov byte [ebx+10h],69h
mov byte [ebx+11h],1
add ebx,12h
mov ecx,[eax+20]
mov ecx,[ecx]
shr ecx,8
mov [ebx],ecx
mov byte [ebx+4],3
add esi,10h
add ebx,12h
jmp make_symbols_table
bt [format_flags],0
jnc invalid_use_of_symbol
mov ecx,[eax]
or ecx,[eax+4]
jnz invalid_use_of_symbol
mov byte [ebx+10h],69h
mov byte [ebx+11h],1
add ebx,12h
mov ecx,[eax+20]
mov ecx,[ecx]
shr ecx,8
mov [ebx],ecx
mov byte [ebx+4],3
add esi,10h
add ebx,12h
jmp make_symbols_table
public_constant:
mov word [ebx+0Ch],0FFFFh
jmp public_symbol_section_ok
mov word [ebx+0Ch],0FFFFh
jmp public_symbol_section_ok
symbols_table_ok:
mov eax,edi
sub eax,edx
mov [edx],eax
sub edi,[code_start]
mov [code_size],edi
mov [written_size],0
mov edx,[output_file]
call create
jc write_failed
mov edx,[free_additional_memory]
pop ecx
add [written_size],ecx
call write
jc write_failed
jmp write_output
mov eax,edi
sub eax,edx
mov [edx],eax
sub edi,[code_start]
mov [code_size],edi
mov [written_size],0
mov edx,[output_file]
call create
jc write_failed
mov edx,[free_additional_memory]
pop ecx
add [written_size],ecx
call write
jc write_failed
jmp write_output
store_symbol_name:
push esi
mov esi,[esi+4]
or esi,esi
jz default_name
lods dword [esi]
mov ecx,eax
cmp ecx,8
ja add_string
push edi
mov edi,ebx
rep movs byte [edi],[esi]
pop edi esi
ret
push esi
mov esi,[esi+4]
or esi,esi
jz default_name
lods dword [esi]
mov ecx,eax
cmp ecx,8
ja add_string
push edi
mov edi,ebx
rep movs byte [edi],[esi]
pop edi esi
ret
default_name:
mov dword [ebx],'.fla'
mov dword [ebx+4],'t'
pop esi
ret
mov dword [ebx],'.fla'
mov dword [ebx+4],'t'
pop esi
ret
add_string:
mov eax,edi
sub eax,edx
mov [ebx+4],eax
inc ecx
rep movs byte [edi],[esi]
pop esi
ret
mov eax,edi
sub eax,edx
mov [ebx+4],eax
inc ecx
rep movs byte [edi],[esi]
pop esi
ret
 
format_elf:
test [format_flags],8
jnz format_elf64
mov edx,edi
mov ecx,34h shr 2
lea eax,[edi+ecx*4]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
mov dword [edx],7Fh + 'ELF' shl 8
mov al,1
mov [edx+4],al
mov [edx+5],al
mov [edx+6],al
mov [edx+14h],al
mov byte [edx+12h],3
mov byte [edx+28h],34h
mov byte [edx+2Eh],28h
mov [code_type],32
cmp word [esi],1D19h
je format_elf_exe
mov [labels_type],2
test [format_flags],8
jnz format_elf64
mov edx,edi
mov ecx,34h shr 2
lea eax,[edi+ecx*4]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
mov dword [edx],7Fh + 'ELF' shl 8
mov al,1
mov [edx+4],al
mov [edx+5],al
mov [edx+6],al
mov [edx+14h],al
mov byte [edx+12h],3
mov byte [edx+28h],34h
mov byte [edx+2Eh],28h
mov [code_type],32
cmp word [esi],1D19h
je format_elf_exe
mov [labels_type],2
elf_header_ok:
mov byte [edx+10h],1
mov eax,[additional_memory]
mov [symbols_stream],eax
mov ebx,eax
add eax,20h
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
xor eax,eax
mov [current_section],ebx
mov [number_of_sections],eax
mov dword [org_origin],edi
mov dword [org_origin+4],eax
mov [org_registers],eax
mov [org_start],edi
mov [org_symbol],ebx
mov [ebx],al
mov [ebx+4],eax
mov [ebx+8],edi
mov al,111b
mov [ebx+14h],eax
mov al,4
mov [ebx+10h],eax
test [format_flags],8
jz instruction_assembled
mov byte [ebx+10h],8
jmp instruction_assembled
mov byte [edx+10h],1
mov eax,[additional_memory]
mov [symbols_stream],eax
mov ebx,eax
add eax,20h
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
xor eax,eax
mov [current_section],ebx
mov [number_of_sections],eax
mov dword [org_origin],edi
mov dword [org_origin+4],eax
mov [org_registers],eax
mov [org_start],edi
mov [org_symbol],ebx
mov [ebx],al
mov [ebx+4],eax
mov [ebx+8],edi
mov al,111b
mov [ebx+14h],eax
mov al,4
mov [ebx+10h],eax
test [format_flags],8
jz instruction_assembled
mov byte [ebx+10h],8
jmp instruction_assembled
format_elf64:
mov edx,edi
mov ecx,40h shr 2
lea eax,[edi+ecx*4]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
mov dword [edx],7Fh + 'ELF' shl 8
mov al,1
mov [edx+5],al
mov [edx+6],al
mov [edx+14h],al
mov byte [edx+4],2
mov byte [edx+12h],62
mov byte [edx+34h],40h
mov byte [edx+3Ah],40h
mov [code_type],64
cmp word [esi],1D19h
je format_elf64_exe
mov [labels_type],4
jmp elf_header_ok
mov edx,edi
mov ecx,40h shr 2
lea eax,[edi+ecx*4]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
mov dword [edx],7Fh + 'ELF' shl 8
mov al,1
mov [edx+5],al
mov [edx+6],al
mov [edx+14h],al
mov byte [edx+4],2
mov byte [edx+12h],62
mov byte [edx+34h],40h
mov byte [edx+3Ah],40h
mov [code_type],64
cmp word [esi],1D19h
je format_elf64_exe
mov [labels_type],4
jmp elf_header_ok
elf_section:
bt [format_flags],0
jc illegal_instruction
call close_coff_section
mov ebx,[free_additional_memory]
lea eax,[ebx+20h]
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
mov [current_section],ebx
inc word [number_of_sections]
jz format_limitations_exceeded
xor eax,eax
mov [ebx],al
mov [ebx+8],edi
mov dword [org_origin],edi
mov dword [org_origin+4],0
mov [org_registers],0
mov [org_start],edi
mov [org_symbol],ebx
test [format_flags],8
jnz elf64_labels_type
mov [labels_type],2
jmp elf_labels_type_ok
bt [format_flags],0
jc illegal_instruction
call close_coff_section
mov ebx,[free_additional_memory]
lea eax,[ebx+20h]
cmp eax,[structures_buffer]
jae out_of_memory
mov [free_additional_memory],eax
mov [current_section],ebx
inc word [number_of_sections]
jz format_limitations_exceeded
xor eax,eax
mov [ebx],al
mov [ebx+8],edi
mov dword [org_origin],edi
mov dword [org_origin+4],0
mov [org_registers],0
mov [org_start],edi
mov [org_symbol],ebx
test [format_flags],8
jnz elf64_labels_type
mov [labels_type],2
jmp elf_labels_type_ok
elf64_labels_type:
mov [labels_type],4
mov [labels_type],4
elf_labels_type_ok:
mov [ebx+10h],eax
mov al,10b
mov [ebx+14h],eax
lods word [esi]
cmp ax,'('
jne invalid_argument
mov [ebx+4],esi
mov ecx,[esi]
lea esi,[esi+4+ecx+1]
mov [ebx+10h],eax
mov al,10b
mov [ebx+14h],eax
lods word [esi]
cmp ax,'('
jne invalid_argument
mov [ebx+4],esi
mov ecx,[esi]
lea esi,[esi+4+ecx+1]
elf_section_flags:
cmp byte [esi],1Ch
je elf_section_alignment
cmp byte [esi],19h
jne elf_section_settings_ok
inc esi
lods byte [esi]
sub al,28
xor al,11b
test al,not 10b
jnz invalid_argument
mov cl,al
mov al,1
shl al,cl
test byte [ebx+14h],al
jnz setting_already_specified
or byte [ebx+14h],al
jmp elf_section_flags
cmp byte [esi],1Ch
je elf_section_alignment
cmp byte [esi],19h
jne elf_section_settings_ok
inc esi
lods byte [esi]
sub al,28
xor al,11b
test al,not 10b
jnz invalid_argument
mov cl,al
mov al,1
shl al,cl
test byte [ebx+14h],al
jnz setting_already_specified
or byte [ebx+14h],al
jmp elf_section_flags
elf_section_alignment:
inc esi
lods byte [esi]
or al,al
jnz invalid_argument
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
push ebx
call get_dword_value
pop ebx
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,eax
dec edx
test eax,edx
jnz invalid_value
or eax,eax
jz invalid_value
xchg [ebx+10h],eax
or eax,eax
jnz setting_already_specified
jmp elf_section_flags
inc esi
lods byte [esi]
or al,al
jnz invalid_argument
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
push ebx
call get_dword_value
pop ebx
cmp [value_type],0
jne invalid_use_of_symbol
mov edx,eax
dec edx
test eax,edx
jnz invalid_value
or eax,eax
jz invalid_value
xchg [ebx+10h],eax
or eax,eax
jnz setting_already_specified
jmp elf_section_flags
elf_section_settings_ok:
cmp dword [ebx+10h],0
jne instruction_assembled
mov dword [ebx+10h],4
test [format_flags],8
jz instruction_assembled
mov byte [ebx+10h],8
jmp instruction_assembled
cmp dword [ebx+10h],0
jne instruction_assembled
mov dword [ebx+10h],4
test [format_flags],8
jz instruction_assembled
mov byte [ebx+10h],8
jmp instruction_assembled
mark_elf_relocation:
cmp [value_type],3
je elf_relocation_relative
push ebx eax
cmp [value_type],3
je elf_gotoff_relocation
mov al,1
test [format_flags],8
jz coff_relocation
cmp [value_type],4
je coff_relocation
mov al,11
jmp coff_relocation
cmp [value_type],3
je elf_relocation_relative
push ebx eax
cmp [value_type],3
je elf_gotoff_relocation
mov al,1
test [format_flags],8
jz coff_relocation
cmp [value_type],4
je coff_relocation
mov al,11
jmp coff_relocation
elf_gotoff_relocation:
mov al,9
jmp coff_relocation
mov al,9
jmp coff_relocation
elf_relocation_relative:
cmp [labels_type],0
je invalid_use_of_symbol
push ebx
mov ebx,[current_section]
mov ebx,[ebx+8]
sub ebx,edi
sub eax,ebx
push eax
mov al,2
jmp coff_relocation
cmp [labels_type],0
je invalid_use_of_symbol
push ebx
mov ebx,[current_section]
mov ebx,[ebx+8]
sub ebx,edi
sub eax,ebx
push eax
mov al,2
jmp coff_relocation
close_elf:
bt [format_flags],0
jc close_elf_exe
call close_coff_section
cmp [next_pass_needed],0
je elf_closed
mov eax,[symbols_stream]
mov [free_additional_memory],eax
bt [format_flags],0
jc close_elf_exe
call close_coff_section
cmp [next_pass_needed],0
je elf_closed
mov eax,[symbols_stream]
mov [free_additional_memory],eax
elf_closed:
ret
ret
elf_formatter:
push edi
call prepare_default_section
mov esi,[symbols_stream]
mov edi,[free_additional_memory]
xor eax,eax
mov ecx,4
rep stos dword [edi]
test [format_flags],8
jz find_first_section
mov ecx,2
rep stos dword [edi]
push edi
call prepare_default_section
mov esi,[symbols_stream]
mov edi,[free_additional_memory]
xor eax,eax
mov ecx,4
rep stos dword [edi]
test [format_flags],8
jz find_first_section
mov ecx,2
rep stos dword [edi]
find_first_section:
mov al,[esi]
or al,al
jz first_section_found
cmp al,80h
jne skip_other_symbol
add esi,4
mov al,[esi]
or al,al
jz first_section_found
cmp al,80h
jne skip_other_symbol
add esi,4
skip_other_symbol:
add esi,0Ch
jmp find_first_section
add esi,0Ch
jmp find_first_section
first_section_found:
mov ebx,esi
mov ebp,esi
add esi,20h
xor ecx,ecx
xor edx,edx
mov ebx,esi
mov ebp,esi
add esi,20h
xor ecx,ecx
xor edx,edx
find_next_section:
cmp esi,[free_additional_memory]
je make_section_symbol
mov al,[esi]
or al,al
jz make_section_symbol
cmp al,80h
je skip_public
ja skip_extrn
or byte [ebx+14h],40h
cmp esi,[free_additional_memory]
je make_section_symbol
mov al,[esi]
or al,al
jz make_section_symbol
cmp al,80h
je skip_public
ja skip_extrn
or byte [ebx+14h],40h
skip_extrn:
add esi,0Ch
jmp find_next_section
add esi,0Ch
jmp find_next_section
skip_public:
add esi,10h
jmp find_next_section
add esi,10h
jmp find_next_section
make_section_symbol:
mov eax,edi
xchg eax,[ebx+4]
stos dword [edi]
test [format_flags],8
jnz elf64_section_symbol
xor eax,eax
stos dword [edi]
stos dword [edi]
call store_section_index
jmp section_symbol_ok
mov eax,edi
xchg eax,[ebx+4]
stos dword [edi]
test [format_flags],8
jnz elf64_section_symbol
xor eax,eax
stos dword [edi]
stos dword [edi]
call store_section_index
jmp section_symbol_ok
store_section_index:
inc ecx
mov eax,ecx
shl eax,8
mov [ebx],eax
inc dx
jz format_limitations_exceeded
mov eax,edx
shl eax,16
mov al,3
test byte [ebx+14h],40h
jz section_index_ok
or ah,-1
inc dx
jz format_limitations_exceeded
inc ecx
mov eax,ecx
shl eax,8
mov [ebx],eax
inc dx
jz format_limitations_exceeded
mov eax,edx
shl eax,16
mov al,3
test byte [ebx+14h],40h
jz section_index_ok
or ah,-1
inc dx
jz format_limitations_exceeded
section_index_ok:
stos dword [edi]
ret
stos dword [edi]
ret
elf64_section_symbol:
call store_section_index
xor eax,eax
stos dword [edi]
stos dword [edi]
stos dword [edi]
stos dword [edi]
call store_section_index
xor eax,eax
stos dword [edi]
stos dword [edi]
stos dword [edi]
stos dword [edi]
section_symbol_ok:
mov ebx,esi
add esi,20h
cmp ebx,[free_additional_memory]
jne find_next_section
inc dx
jz format_limitations_exceeded
mov [current_section],edx
mov esi,[symbols_stream]
mov ebx,esi
add esi,20h
cmp ebx,[free_additional_memory]
jne find_next_section
inc dx
jz format_limitations_exceeded
mov [current_section],edx
mov esi,[symbols_stream]
find_other_symbols:
cmp esi,[free_additional_memory]
je elf_symbol_table_ok
mov al,[esi]
or al,al
jz skip_section
cmp al,80h
je make_public_symbol
ja make_extrn_symbol
add esi,0Ch
jmp find_other_symbols
cmp esi,[free_additional_memory]
je elf_symbol_table_ok
mov al,[esi]
or al,al
jz skip_section
cmp al,80h
je make_public_symbol
ja make_extrn_symbol
add esi,0Ch
jmp find_other_symbols
skip_section:
add esi,20h
jmp find_other_symbols
add esi,20h
jmp find_other_symbols
make_public_symbol:
mov eax,[esi+0Ch]
mov [current_line],eax
mov ebx,[esi+8]
test byte [ebx+8],1
jz undefined_symbol
mov ax,[current_pass]
cmp ax,[ebx+16]
jne undefined_symbol
mov dl,[ebx+11]
or dl,dl
jz public_absolute
mov eax,[ebx+20]
cmp byte [eax],0
jne invalid_use_of_symbol
mov eax,[eax+4]
test [format_flags],8
jnz elf64_public
cmp dl,2
jne invalid_use_of_symbol
mov dx,[eax+0Eh]
jmp section_for_public_ok
mov eax,[esi+0Ch]
mov [current_line],eax
mov ebx,[esi+8]
test byte [ebx+8],1
jz undefined_symbol
mov ax,[current_pass]
cmp ax,[ebx+16]
jne undefined_symbol
mov dl,[ebx+11]
or dl,dl
jz public_absolute
mov eax,[ebx+20]
cmp byte [eax],0
jne invalid_use_of_symbol
mov eax,[eax+4]