2006-07-28 15:39:16 +02:00
|
|
|
|
|
|
|
; flat assembler core
|
2012-05-20 13:47:06 +02:00
|
|
|
; Copyright (c) 1999-2012, Tomasz Grysztar.
|
2006-07-28 15:39:16 +02:00
|
|
|
; All rights reserved.
|
|
|
|
|
|
|
|
assembler:
|
2006-09-22 17:55:59 +02:00
|
|
|
xor eax,eax
|
|
|
|
mov [stub_size],eax
|
|
|
|
mov [current_pass],ax
|
|
|
|
mov [resolver_flags],eax
|
2011-10-13 21:06:08 +02:00
|
|
|
mov [number_of_sections],eax
|
|
|
|
mov [actual_fixups_size],eax
|
2006-07-28 15:39:16 +02:00
|
|
|
assembler_loop:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2007-08-10 06:45:04 +02:00
|
|
|
mov [file_extension],eax
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [next_pass_needed],al
|
|
|
|
mov [output_format],al
|
2012-05-20 16:43:49 +02:00
|
|
|
mov [org_origin_sign],al
|
|
|
|
mov [adjustment_sign],al
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [labels_type],al
|
|
|
|
mov [virtual_data],al
|
|
|
|
mov [code_type],16
|
2006-07-28 15:39:16 +02:00
|
|
|
pass_loop:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
pass_done:
|
2006-09-22 17:55:59 +02:00
|
|
|
call close_pass
|
|
|
|
mov eax,[labels_list]
|
2006-07-28 15:39:16 +02:00
|
|
|
check_symbols:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
symbol_defined_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
check_use_prediction:
|
2006-09-22 17:55:59 +02:00
|
|
|
test byte [eax+8],8
|
|
|
|
jz use_misprediction
|
|
|
|
cmp cx,[eax+18]
|
|
|
|
je use_prediction_ok
|
2006-07-28 15:39:16 +02:00
|
|
|
use_misprediction:
|
2006-09-22 17:55:59 +02:00
|
|
|
or [next_pass_needed],-1
|
2006-07-28 15:39:16 +02:00
|
|
|
use_prediction_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
check_define_prediction:
|
2006-09-22 17:55:59 +02:00
|
|
|
test byte [eax+8],1
|
|
|
|
jz define_misprediction
|
|
|
|
cmp cx,[eax+16]
|
|
|
|
je check_next_symbol
|
2006-07-28 15:39:16 +02:00
|
|
|
define_misprediction:
|
2006-09-22 17:55:59 +02:00
|
|
|
or [next_pass_needed],-1
|
2006-07-28 15:39:16 +02:00
|
|
|
check_next_symbol:
|
2006-09-22 17:55:59 +02:00
|
|
|
add eax,LABEL_STRUCTURE_SIZE
|
|
|
|
jmp check_symbols
|
2006-07-28 15:39:16 +02:00
|
|
|
symbols_checked:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [next_pass_needed],0
|
|
|
|
jne next_pass
|
|
|
|
mov eax,[error_line]
|
|
|
|
or eax,eax
|
|
|
|
jz assemble_ok
|
|
|
|
mov [current_line],eax
|
2011-10-13 21:06:08 +02:00
|
|
|
cmp [error],undefined_symbol
|
|
|
|
jne error_confirmed
|
|
|
|
mov eax,[error_info]
|
|
|
|
or eax,eax
|
|
|
|
jz error_confirmed
|
|
|
|
test byte [eax+8],1
|
|
|
|
jnz next_pass
|
|
|
|
error_confirmed:
|
2009-10-01 02:41:45 +02:00
|
|
|
call error_handler
|
|
|
|
error_handler:
|
|
|
|
mov eax,[error]
|
|
|
|
sub eax,error_handler
|
|
|
|
add [esp],eax
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
next_pass:
|
2006-09-22 17:55:59 +02:00
|
|
|
inc [current_pass]
|
|
|
|
mov ax,[current_pass]
|
|
|
|
cmp ax,[passes_limit]
|
|
|
|
je code_cannot_be_generated
|
|
|
|
jmp assembler_loop
|
2006-07-28 15:39:16 +02:00
|
|
|
assemble_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
|
|
|
|
assemble_line:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
code_type_setting:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
mov [code_type],al
|
|
|
|
jmp line_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
new_line:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods dword [esi]
|
|
|
|
mov [current_line],eax
|
|
|
|
mov [prefixed_instruction],0
|
2008-12-30 21:21:32 +01:00
|
|
|
cmp [symbols_file],0
|
|
|
|
je continue_line
|
2012-05-20 16:43:49 +02:00
|
|
|
cmp [next_pass_needed],0
|
|
|
|
jne continue_line
|
2008-12-30 21:21:32 +01:00
|
|
|
mov ebx,[display_buffer]
|
|
|
|
mov dword [ebx-4],1
|
|
|
|
mov dword [ebx-8],1Ch
|
|
|
|
sub ebx,8+1Ch
|
|
|
|
cmp ebx,edi
|
|
|
|
jbe out_of_memory
|
|
|
|
mov [display_buffer],ebx
|
|
|
|
mov [ebx],eax
|
|
|
|
mov [ebx+4],edi
|
|
|
|
mov eax,dword [org_origin]
|
|
|
|
mov edx,dword [org_origin+4]
|
|
|
|
mov ecx,[org_registers]
|
|
|
|
mov [ebx+8],eax
|
|
|
|
mov [ebx+8+4],edx
|
|
|
|
mov [ebx+10h],ecx
|
|
|
|
mov edx,[org_symbol]
|
2012-05-20 16:43:49 +02:00
|
|
|
; mov al,[virtual_data]
|
|
|
|
; mov ah,[org_origin_sign]
|
|
|
|
; shl eax,16
|
|
|
|
; mov al,[labels_type]
|
|
|
|
; mov ah,[code_type]
|
2008-12-30 21:21:32 +01:00
|
|
|
mov eax,dword [labels_type]
|
|
|
|
mov [ebx+14h],edx
|
|
|
|
mov [ebx+18h],eax
|
2006-07-28 15:39:16 +02:00
|
|
|
continue_line:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp byte [esi],0Fh
|
|
|
|
je line_assembled
|
|
|
|
jmp assemble_line
|
2006-07-28 15:39:16 +02:00
|
|
|
define_label:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods dword [esi]
|
|
|
|
cmp eax,0Fh
|
|
|
|
jb invalid_use_of_symbol
|
|
|
|
je reserved_word_used_as_symbol
|
|
|
|
mov ebx,eax
|
|
|
|
lods byte [esi]
|
2012-05-20 16:43:49 +02:00
|
|
|
mov [label_size],al
|
|
|
|
call make_label
|
|
|
|
jmp continue_line
|
|
|
|
make_label:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov eax,edi
|
|
|
|
xor edx,edx
|
2012-05-20 16:43:49 +02:00
|
|
|
xor cl,cl
|
2006-09-22 17:55:59 +02:00
|
|
|
sub eax,dword [org_origin]
|
|
|
|
sbb edx,dword [org_origin+4]
|
2012-05-20 16:43:49 +02:00
|
|
|
sbb cl,[org_origin_sign]
|
|
|
|
jp label_value_ok
|
|
|
|
call recoverable_overflow
|
|
|
|
label_value_ok:
|
|
|
|
mov [address_sign],cl
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [virtual_data],0
|
|
|
|
jne make_virtual_label
|
|
|
|
or byte [ebx+9],1
|
|
|
|
xchg eax,[ebx]
|
|
|
|
xchg edx,[ebx+4]
|
2012-05-20 16:43:49 +02:00
|
|
|
mov ch,[ebx+9]
|
|
|
|
shr ch,1
|
|
|
|
and ch,1
|
|
|
|
neg ch
|
2006-09-22 17:55:59 +02:00
|
|
|
sub eax,[ebx]
|
|
|
|
sbb edx,[ebx+4]
|
2012-05-20 16:43:49 +02:00
|
|
|
sbb ch,cl
|
2006-09-22 17:55:59 +02:00
|
|
|
mov dword [adjustment],eax
|
|
|
|
mov dword [adjustment+4],edx
|
2012-05-20 16:43:49 +02:00
|
|
|
mov [adjustment_sign],ch
|
|
|
|
or al,ch
|
2006-09-22 17:55:59 +02:00
|
|
|
or eax,edx
|
|
|
|
setnz ah
|
2012-05-20 16:43:49 +02:00
|
|
|
jmp finish_label
|
2006-07-28 15:39:16 +02:00
|
|
|
make_virtual_label:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2012-05-20 16:43:49 +02:00
|
|
|
finish_label:
|
|
|
|
mov ch,[labels_type]
|
|
|
|
mov cl,[label_size]
|
|
|
|
mov ebp,[org_registers]
|
|
|
|
mov edx,[org_symbol]
|
2006-07-28 15:39:16 +02:00
|
|
|
finish_label_symbol:
|
2012-05-20 16:43:49 +02:00
|
|
|
mov al,[address_sign]
|
|
|
|
xor al,[ebx+9]
|
|
|
|
and al,10b
|
|
|
|
or ah,al
|
|
|
|
xor [ebx+9],al
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2012-05-20 16:43:49 +02:00
|
|
|
cmp ebp,[ebx+12]
|
|
|
|
mov [ebx+12],ebp
|
2006-09-22 17:55:59 +02:00
|
|
|
setne al
|
|
|
|
or ah,al
|
|
|
|
or ch,ch
|
|
|
|
jz label_symbol_ok
|
|
|
|
cmp edx,[ebx+20]
|
|
|
|
mov [ebx+20],edx
|
|
|
|
setne al
|
|
|
|
or ah,al
|
2006-07-28 15:39:16 +02:00
|
|
|
label_symbol_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2012-05-20 16:43:49 +02:00
|
|
|
jz label_made
|
2006-09-22 17:55:59 +02:00
|
|
|
test byte [ebx+8],8
|
2012-05-20 16:43:49 +02:00
|
|
|
jz label_made
|
2006-09-22 17:55:59 +02:00
|
|
|
mov cx,[current_pass]
|
|
|
|
cmp cx,[ebx+18]
|
2012-05-20 16:43:49 +02:00
|
|
|
jne label_made
|
2006-09-22 17:55:59 +02:00
|
|
|
or [next_pass_needed],-1
|
2012-05-20 16:43:49 +02:00
|
|
|
label_made:
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
new_label:
|
2006-09-22 17:55:59 +02:00
|
|
|
or byte [ebx+8],1
|
2012-05-20 16:43:49 +02:00
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
define_constant:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
get_constant_value:
|
2006-09-22 17:55:59 +02:00
|
|
|
push eax
|
|
|
|
mov al,byte [esi-1]
|
|
|
|
push eax
|
2012-05-20 16:43:49 +02:00
|
|
|
or [size_override],-1
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
make_constant:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2012-05-20 16:43:49 +02:00
|
|
|
mov al,[value_sign]
|
|
|
|
xor al,[ebx+9]
|
|
|
|
and al,10b
|
|
|
|
or ah,al
|
|
|
|
xor [ebx+9],al
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
constant_symbol_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
redeclare_constant:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
new_constant:
|
2006-09-22 17:55:59 +02:00
|
|
|
or byte [ebx+8],1+2
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
assemble_instruction:
|
2008-01-31 22:32:32 +01:00
|
|
|
; mov [operand_size],0
|
|
|
|
; mov [size_override],0
|
|
|
|
; mov [operand_prefix],0
|
2011-10-13 21:06:08 +02:00
|
|
|
; mov [opcode_prefix],0
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [operand_size],0
|
2011-10-13 21:06:08 +02:00
|
|
|
; mov [rex_prefix],0
|
|
|
|
; mov [vex_required],0
|
|
|
|
; mov [vex_register],0
|
|
|
|
; mov [immediate_size],0
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [rex_prefix],0
|
2009-10-01 02:41:45 +02:00
|
|
|
call instruction_handler
|
|
|
|
instruction_handler:
|
2006-09-22 17:55:59 +02:00
|
|
|
movzx ebx,word [esi]
|
|
|
|
mov al,[esi+2]
|
|
|
|
add esi,3
|
2009-10-01 02:41:45 +02:00
|
|
|
add [esp],ebx
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
instruction_assembled:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov al,[esi]
|
|
|
|
cmp al,0Fh
|
|
|
|
je line_assembled
|
|
|
|
or al,al
|
|
|
|
jnz extra_characters_on_line
|
2006-07-28 15:39:16 +02:00
|
|
|
line_assembled:
|
2006-09-22 17:55:59 +02:00
|
|
|
clc
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
source_end:
|
2006-09-22 17:55:59 +02:00
|
|
|
dec esi
|
|
|
|
stc
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
|
|
|
|
org_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2012-05-20 16:43:49 +02:00
|
|
|
mov dword [org_origin],edi
|
|
|
|
xor ecx,ecx
|
|
|
|
mov dword [org_origin+4],ecx
|
|
|
|
mov [org_origin_sign],cl
|
|
|
|
mov [org_registers],ecx
|
|
|
|
mov cl,[value_sign]
|
|
|
|
sub dword [org_origin],eax
|
|
|
|
sbb dword [org_origin+4],edx
|
|
|
|
sbb [org_origin_sign],cl
|
|
|
|
jp org_value_ok
|
|
|
|
call recoverable_overflow
|
|
|
|
org_value_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
label_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2012-05-20 16:43:49 +02:00
|
|
|
mov [label_size],0
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,':'
|
|
|
|
je get_label_size
|
|
|
|
dec esi
|
|
|
|
cmp al,11h
|
|
|
|
jne label_size_ok
|
2006-07-28 15:39:16 +02:00
|
|
|
get_label_size:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods word [esi]
|
|
|
|
cmp al,11h
|
|
|
|
jne invalid_argument
|
2012-05-20 16:43:49 +02:00
|
|
|
mov [label_size],ah
|
2006-07-28 15:39:16 +02:00
|
|
|
label_size_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp byte [esi],80h
|
|
|
|
je get_free_label_value
|
2012-05-20 16:43:49 +02:00
|
|
|
call make_label
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
get_free_label_value:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
make_free_label:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
|
|
|
mov edx,[address_symbol]
|
2012-05-20 16:43:49 +02:00
|
|
|
mov cl,[label_size]
|
|
|
|
call finish_label_symbol
|
2006-09-22 17:55:59 +02:00
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
load_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
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]
|
2006-07-28 15:39:16 +02:00
|
|
|
load_size_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp al,8
|
|
|
|
ja invalid_value
|
|
|
|
mov [operand_size],al
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [value],0
|
|
|
|
and dword [value+4],0
|
2006-09-22 17:55:59 +02:00
|
|
|
lods word [esi]
|
|
|
|
cmp ax,82h+'(' shl 8
|
|
|
|
jne invalid_argument
|
2006-07-28 15:39:16 +02:00
|
|
|
load_from_code:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2006-12-21 07:34:09 +01:00
|
|
|
or [size_override],-1
|
2006-11-26 02:43:33 +01:00
|
|
|
call get_address_value
|
2006-10-11 00:15:57 +02:00
|
|
|
call calculate_relative_offset
|
|
|
|
push esi edi
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [next_pass_needed],0
|
2006-10-11 00:15:57 +02:00
|
|
|
jne load_address_type_ok
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [value_type],0
|
|
|
|
jne invalid_use_of_symbol
|
2006-10-11 00:15:57 +02:00
|
|
|
load_address_type_ok:
|
|
|
|
cmp edx,-1
|
|
|
|
jne bad_load_address
|
|
|
|
neg eax
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
bad_load_address:
|
2012-05-20 16:43:49 +02:00
|
|
|
call recoverable_overflow
|
2006-07-28 15:39:16 +02:00
|
|
|
value_loaded:
|
2006-09-22 17:55:59 +02:00
|
|
|
pop edi esi
|
2012-05-20 16:43:49 +02:00
|
|
|
mov [value_sign],0
|
2006-09-22 17:55:59 +02:00
|
|
|
mov eax,dword [value]
|
|
|
|
mov edx,dword [value+4]
|
|
|
|
pop ebx
|
|
|
|
xor cx,cx
|
|
|
|
jmp make_constant
|
2006-07-28 15:39:16 +02:00
|
|
|
store_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
sized_store:
|
2012-05-20 16:43:49 +02:00
|
|
|
or [size_override],-1
|
2006-09-22 17:55:59 +02:00
|
|
|
call get_value
|
2006-07-28 15:39:16 +02:00
|
|
|
store_value_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-12-21 07:34:09 +01:00
|
|
|
or [size_override],-1
|
2006-11-26 02:43:33 +01:00
|
|
|
call get_address_value
|
2006-10-11 00:15:57 +02:00
|
|
|
call calculate_relative_offset
|
|
|
|
push esi edi
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [next_pass_needed],0
|
2006-10-11 00:15:57 +02:00
|
|
|
jne store_address_type_ok
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [value_type],0
|
|
|
|
jne invalid_use_of_symbol
|
2006-10-11 00:15:57 +02:00
|
|
|
store_address_type_ok:
|
|
|
|
cmp edx,-1
|
|
|
|
jne bad_store_address
|
|
|
|
neg eax
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
bad_store_address:
|
2006-09-22 17:55:59 +02:00
|
|
|
pop edi esi
|
2012-05-20 16:43:49 +02:00
|
|
|
call recoverable_overflow
|
2006-09-22 17:55:59 +02:00
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
|
|
|
|
display_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
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]
|
2008-12-30 21:21:32 +01:00
|
|
|
sub edi,8
|
2006-09-22 17:55:59 +02:00
|
|
|
sub edi,eax
|
2008-12-30 21:21:32 +01:00
|
|
|
cmp edi,[esp]
|
|
|
|
jbe out_of_memory
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [display_buffer],edi
|
|
|
|
rep movs byte [edi],[esi]
|
|
|
|
stos dword [edi]
|
2008-12-30 21:21:32 +01:00
|
|
|
xor eax,eax
|
|
|
|
stos dword [edi]
|
2006-09-22 17:55:59 +02:00
|
|
|
pop edi
|
|
|
|
inc esi
|
|
|
|
jmp display_next
|
2006-07-28 15:39:16 +02:00
|
|
|
display_byte:
|
2006-09-22 17:55:59 +02:00
|
|
|
call get_byte_value
|
|
|
|
push edi
|
|
|
|
mov edi,[display_buffer]
|
2008-12-30 21:21:32 +01:00
|
|
|
sub edi,8+1
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [display_buffer],edi
|
|
|
|
stos byte [edi]
|
|
|
|
mov eax,1
|
|
|
|
stos dword [edi]
|
2008-12-30 21:21:32 +01:00
|
|
|
dec eax
|
|
|
|
stos dword [edi]
|
2006-09-22 17:55:59 +02:00
|
|
|
pop edi
|
2006-07-28 15:39:16 +02:00
|
|
|
display_next:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp edi,[display_buffer]
|
|
|
|
ja out_of_memory
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,','
|
|
|
|
je display_directive
|
|
|
|
dec esi
|
|
|
|
jmp instruction_assembled
|
2008-12-30 21:21:32 +01:00
|
|
|
show_display_buffer:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov eax,[display_buffer]
|
|
|
|
or eax,eax
|
|
|
|
jz display_done
|
|
|
|
mov esi,[labels_list]
|
|
|
|
cmp esi,eax
|
|
|
|
je display_done
|
2006-07-28 15:39:16 +02:00
|
|
|
display_messages:
|
2008-12-30 21:21:32 +01:00
|
|
|
sub esi,8
|
|
|
|
mov eax,[esi+4]
|
2006-09-22 17:55:59 +02:00
|
|
|
mov ecx,[esi]
|
|
|
|
sub esi,ecx
|
2008-12-30 21:21:32 +01:00
|
|
|
test eax,eax
|
|
|
|
jnz skip_internal_message
|
2006-09-22 17:55:59 +02:00
|
|
|
push esi
|
|
|
|
call display_block
|
|
|
|
pop esi
|
2008-12-30 21:21:32 +01:00
|
|
|
skip_internal_message:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp esi,[display_buffer]
|
|
|
|
jne display_messages
|
2006-07-28 15:39:16 +02:00
|
|
|
display_done:
|
2006-09-22 17:55:59 +02:00
|
|
|
ret
|
2008-12-30 21:21:32 +01:00
|
|
|
|
2006-07-28 15:39:16 +02:00
|
|
|
times_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp eax,0
|
|
|
|
je zero_times
|
|
|
|
cmp byte [esi],':'
|
|
|
|
jne times_argument_ok
|
|
|
|
inc esi
|
2006-07-28 15:39:16 +02:00
|
|
|
times_argument_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
push [counter]
|
|
|
|
push [counter_limit]
|
|
|
|
mov [counter_limit],eax
|
|
|
|
mov [counter],1
|
2006-07-28 15:39:16 +02:00
|
|
|
times_loop:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
times_done:
|
2006-09-22 17:55:59 +02:00
|
|
|
pop eax
|
|
|
|
pop [counter_limit]
|
|
|
|
pop [counter]
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
zero_times:
|
2011-10-13 21:06:08 +02:00
|
|
|
call skip_symbol
|
|
|
|
jnc zero_times
|
2006-09-22 17:55:59 +02:00
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
|
|
|
|
virtual_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
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]
|
|
|
|
or bh,bh
|
2012-05-20 16:43:49 +02:00
|
|
|
setnz ch
|
2006-09-22 17:55:59 +02:00
|
|
|
jmp set_virtual
|
2006-07-28 15:39:16 +02:00
|
|
|
virtual_at_current:
|
2006-09-22 17:55:59 +02:00
|
|
|
dec esi
|
|
|
|
mov al,[labels_type]
|
|
|
|
mov [value_type],al
|
|
|
|
mov ebp,[org_symbol]
|
|
|
|
mov eax,edi
|
|
|
|
xor edx,edx
|
2012-05-20 16:43:49 +02:00
|
|
|
xor cl,cl
|
2006-09-22 17:55:59 +02:00
|
|
|
sub eax,dword [org_origin]
|
|
|
|
sbb edx,dword [org_origin+4]
|
2012-05-20 16:43:49 +02:00
|
|
|
sbb cl,[org_origin_sign]
|
|
|
|
mov [address_sign],cl
|
2006-09-22 17:55:59 +02:00
|
|
|
mov bx,word [org_registers]
|
|
|
|
mov cx,word [org_registers+2]
|
|
|
|
xchg bh,bl
|
|
|
|
xchg ch,cl
|
2006-07-28 15:39:16 +02:00
|
|
|
set_virtual:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2009-10-01 02:41:45 +02:00
|
|
|
mov word [ebx],virtual_directive-instruction_handler
|
2012-05-20 16:43:49 +02:00
|
|
|
mov cl,[address_sign]
|
2006-09-22 17:55:59 +02:00
|
|
|
not eax
|
|
|
|
not edx
|
2012-05-20 16:43:49 +02:00
|
|
|
not cl
|
2006-09-22 17:55:59 +02:00
|
|
|
add eax,1
|
|
|
|
adc edx,0
|
2012-05-20 16:43:49 +02:00
|
|
|
adc cl,0
|
2006-09-22 17:55:59 +02:00
|
|
|
add eax,edi
|
|
|
|
adc edx,0
|
2012-05-20 16:43:49 +02:00
|
|
|
adc cl,0
|
2006-09-22 17:55:59 +02:00
|
|
|
xchg dword [org_origin],eax
|
|
|
|
xchg dword [org_origin+4],edx
|
2012-05-20 16:43:49 +02:00
|
|
|
xchg [org_origin_sign],cl
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [ebx+10h],eax
|
|
|
|
mov [ebx+14h],edx
|
|
|
|
pop eax
|
|
|
|
mov [ebx+18h],eax
|
|
|
|
mov al,[virtual_data]
|
2012-05-20 16:43:49 +02:00
|
|
|
and al,0Fh
|
|
|
|
shl cl,4
|
|
|
|
or al,cl
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
allocate_structure_data:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov ebx,[structures_buffer]
|
|
|
|
sub ebx,20h
|
|
|
|
cmp ebx,[free_additional_memory]
|
|
|
|
jb out_of_memory
|
|
|
|
mov [structures_buffer],ebx
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
find_structure_data:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov ebx,[structures_buffer]
|
2006-07-28 15:39:16 +02:00
|
|
|
scan_structures:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp ebx,[additional_memory_end]
|
|
|
|
je no_such_structure
|
|
|
|
cmp ax,[ebx]
|
|
|
|
je structure_data_found
|
|
|
|
add ebx,20h
|
|
|
|
jmp scan_structures
|
2006-07-28 15:39:16 +02:00
|
|
|
structure_data_found:
|
2006-09-22 17:55:59 +02:00
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
no_such_structure:
|
2006-09-22 17:55:59 +02:00
|
|
|
stc
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
end_virtual:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_structure_data
|
|
|
|
jc unexpected_instruction
|
|
|
|
mov al,[ebx+2]
|
2012-05-20 16:43:49 +02:00
|
|
|
mov ah,al
|
|
|
|
shr ah,4
|
|
|
|
and al,1
|
|
|
|
neg al
|
|
|
|
and ah,1
|
|
|
|
neg ah
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [virtual_data],al
|
2012-05-20 16:43:49 +02:00
|
|
|
mov [org_origin_sign],ah
|
2006-09-22 17:55:59 +02:00
|
|
|
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]
|
2006-07-28 15:39:16 +02:00
|
|
|
remove_structure_data:
|
2006-09-22 17:55:59 +02:00
|
|
|
push esi edi
|
|
|
|
mov ecx,ebx
|
2011-10-13 21:06:08 +02:00
|
|
|
sub ecx,[structures_buffer]
|
2006-09-22 17:55:59 +02:00
|
|
|
shr ecx,2
|
2011-10-13 21:06:08 +02:00
|
|
|
lea esi,[ebx-4]
|
|
|
|
lea edi,[esi+20h]
|
|
|
|
std
|
2006-09-22 17:55:59 +02:00
|
|
|
rep movs dword [edi],[esi]
|
2011-10-13 21:06:08 +02:00
|
|
|
cld
|
|
|
|
add [structures_buffer],20h
|
2006-09-22 17:55:59 +02:00
|
|
|
pop edi esi
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
repeat_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [prefixed_instruction],0
|
|
|
|
jne unexpected_instruction
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp eax,0
|
|
|
|
je zero_repeat
|
|
|
|
call allocate_structure_data
|
2009-10-01 02:41:45 +02:00
|
|
|
mov word [ebx],repeat_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
end_repeat:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
stop_repeat:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov eax,[ebx+10h]
|
|
|
|
mov [counter_limit],eax
|
|
|
|
mov eax,[ebx+14h]
|
|
|
|
mov [counter],eax
|
|
|
|
call remove_structure_data
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
continue_repeating:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov esi,[ebx+8]
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
zero_repeat:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
find_end_repeat:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_structure_end
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,repeat_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne unexpected_instruction
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
while_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [prefixed_instruction],0
|
|
|
|
jne unexpected_instruction
|
|
|
|
call allocate_structure_data
|
2009-10-01 02:41:45 +02:00
|
|
|
mov word [ebx],while_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
mov eax,1
|
|
|
|
xchg eax,[counter]
|
|
|
|
mov [ebx+10h],eax
|
|
|
|
mov [ebx+8],esi
|
|
|
|
mov eax,[current_line]
|
|
|
|
mov [ebx+4],eax
|
2006-07-28 15:39:16 +02:00
|
|
|
do_while:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
stop_while:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_end_while
|
|
|
|
pop ebx
|
|
|
|
mov eax,[ebx+10h]
|
|
|
|
mov [counter],eax
|
|
|
|
call remove_structure_data
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
while_true:
|
2006-09-22 17:55:59 +02:00
|
|
|
pop ebx
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
end_while:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
find_end_while:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_structure_end
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,while_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne unexpected_instruction
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
if_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp word [esi+1],if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne else_true
|
|
|
|
add esi,4
|
|
|
|
jmp if_directive
|
2006-07-28 15:39:16 +02:00
|
|
|
if_true:
|
2006-09-22 17:55:59 +02:00
|
|
|
xor al,al
|
2006-07-28 15:39:16 +02:00
|
|
|
make_if_structure:
|
2006-09-22 17:55:59 +02:00
|
|
|
call allocate_structure_data
|
2009-10-01 02:41:45 +02:00
|
|
|
mov word [ebx],if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
mov byte [ebx+2],al
|
|
|
|
mov eax,[current_line]
|
|
|
|
mov [ebx+4],eax
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
else_true:
|
2006-09-22 17:55:59 +02:00
|
|
|
or al,al
|
|
|
|
jz missing_end_directive
|
|
|
|
cmp al,0Fh
|
|
|
|
jne extra_characters_on_line
|
|
|
|
or al,-1
|
|
|
|
jmp make_if_structure
|
2006-07-28 15:39:16 +02:00
|
|
|
else_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [prefixed_instruction],0
|
|
|
|
jne unexpected_instruction
|
2009-10-01 02:41:45 +02:00
|
|
|
mov ax,if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_structure_data
|
|
|
|
jc unexpected_instruction
|
|
|
|
cmp byte [ebx+2],0
|
|
|
|
jne unexpected_instruction
|
2006-07-28 15:39:16 +02:00
|
|
|
found_else:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov al,[esi]
|
|
|
|
cmp al,1
|
|
|
|
jne skip_else
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp word [esi+1],if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne skip_else
|
|
|
|
add esi,4
|
|
|
|
call find_else
|
|
|
|
jnc found_else
|
|
|
|
call remove_structure_data
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
skip_else:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
end_if:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [prefixed_instruction],0
|
|
|
|
jne unexpected_instruction
|
|
|
|
call find_structure_data
|
|
|
|
jc unexpected_instruction
|
|
|
|
call remove_structure_data
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
find_else:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_structure_end
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,else_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je else_found
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne unexpected_instruction
|
|
|
|
stc
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
else_found:
|
2006-09-22 17:55:59 +02:00
|
|
|
clc
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
find_end_if:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_structure_end
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne unexpected_instruction
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
find_structure_end:
|
2006-09-22 17:55:59 +02:00
|
|
|
push [error_line]
|
|
|
|
mov eax,[current_line]
|
|
|
|
mov [error_line],eax
|
2006-07-28 15:39:16 +02:00
|
|
|
find_end_directive:
|
2011-10-13 21:06:08 +02:00
|
|
|
call skip_symbol
|
|
|
|
jnc find_end_directive
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,0Fh
|
|
|
|
jne no_end_directive
|
|
|
|
lods dword [esi]
|
|
|
|
mov [current_line],eax
|
2006-07-28 15:39:16 +02:00
|
|
|
skip_labels:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp byte [esi],2
|
|
|
|
jne labels_ok
|
|
|
|
add esi,6
|
|
|
|
jmp skip_labels
|
2006-07-28 15:39:16 +02:00
|
|
|
labels_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp byte [esi],1
|
|
|
|
jne find_end_directive
|
|
|
|
mov ax,[esi+1]
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,prefix_instruction-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je find_end_directive
|
|
|
|
add esi,4
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,repeat_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je skip_repeat
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,while_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je skip_while
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je skip_if
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,else_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je structure_end
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,end_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne find_end_directive
|
|
|
|
cmp byte [esi],1
|
|
|
|
jne find_end_directive
|
|
|
|
mov ax,[esi+1]
|
|
|
|
add esi,4
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,repeat_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je structure_end
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,while_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je structure_end
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne find_end_directive
|
2006-07-28 15:39:16 +02:00
|
|
|
structure_end:
|
2006-09-22 17:55:59 +02:00
|
|
|
pop [error_line]
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
no_end_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov eax,[error_line]
|
|
|
|
mov [current_line],eax
|
|
|
|
jmp missing_end_directive
|
2006-07-28 15:39:16 +02:00
|
|
|
skip_repeat:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_end_repeat
|
|
|
|
jmp find_end_directive
|
2006-07-28 15:39:16 +02:00
|
|
|
skip_while:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_end_while
|
|
|
|
jmp find_end_directive
|
2006-07-28 15:39:16 +02:00
|
|
|
skip_if:
|
2006-09-22 17:55:59 +02:00
|
|
|
call skip_if_block
|
|
|
|
jmp find_end_directive
|
2006-07-28 15:39:16 +02:00
|
|
|
skip_if_block:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_else
|
|
|
|
jc if_block_skipped
|
|
|
|
cmp byte [esi],1
|
|
|
|
jne skip_after_else
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp word [esi+1],if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
jne skip_after_else
|
|
|
|
add esi,4
|
|
|
|
jmp skip_if_block
|
2006-07-28 15:39:16 +02:00
|
|
|
skip_after_else:
|
2006-09-22 17:55:59 +02:00
|
|
|
call find_end_if
|
2006-07-28 15:39:16 +02:00
|
|
|
if_block_skipped:
|
2006-09-22 17:55:59 +02:00
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
end_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,1
|
|
|
|
jne invalid_argument
|
|
|
|
lods word [esi]
|
|
|
|
inc esi
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,virtual_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je end_virtual
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,repeat_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je end_repeat
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,while_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je end_while
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je end_if
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,data_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je end_data
|
|
|
|
jmp invalid_argument
|
2006-07-28 15:39:16 +02:00
|
|
|
break_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov ebx,[structures_buffer]
|
|
|
|
mov al,[esi]
|
|
|
|
or al,al
|
|
|
|
jz find_breakable_structure
|
|
|
|
cmp al,0Fh
|
|
|
|
jne extra_characters_on_line
|
2006-07-28 15:39:16 +02:00
|
|
|
find_breakable_structure:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp ebx,[additional_memory_end]
|
|
|
|
je unexpected_instruction
|
|
|
|
mov ax,[ebx]
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,repeat_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je break_repeat
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,while_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je break_while
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp ax,if_directive-instruction_handler
|
2006-09-22 17:55:59 +02:00
|
|
|
je break_if
|
|
|
|
add ebx,20h
|
|
|
|
jmp find_breakable_structure
|
2006-07-28 15:39:16 +02:00
|
|
|
break_if:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
break_repeat:
|
2006-09-22 17:55:59 +02:00
|
|
|
push ebx
|
|
|
|
call find_end_repeat
|
|
|
|
pop ebx
|
|
|
|
jmp stop_repeat
|
2006-07-28 15:39:16 +02:00
|
|
|
break_while:
|
2006-09-22 17:55:59 +02:00
|
|
|
push ebx
|
|
|
|
jmp stop_while
|
2006-07-28 15:39:16 +02:00
|
|
|
|
|
|
|
data_bytes:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
get_byte:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp byte [esi],0
|
|
|
|
je get_string
|
|
|
|
call get_byte_value
|
|
|
|
stos byte [edi]
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
get_string:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
undefined_data:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [virtual_data],0
|
|
|
|
je mark_undefined_data
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
mark_undefined_data:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp eax,[undefined_data_end]
|
|
|
|
je undefined_data_ok
|
|
|
|
mov [undefined_data_start],eax
|
2006-07-28 15:39:16 +02:00
|
|
|
undefined_data_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [undefined_data_end],edi
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
define_data:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
inc esi
|
2011-10-13 21:06:08 +02:00
|
|
|
or eax,eax
|
|
|
|
jz duplicate_zero_times
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp byte [esi],'{'
|
|
|
|
jne duplicate_single_data_value
|
|
|
|
inc esi
|
2006-07-28 15:39:16 +02:00
|
|
|
duplicate_data:
|
2006-09-22 17:55:59 +02:00
|
|
|
push eax esi
|
2006-07-28 15:39:16 +02:00
|
|
|
duplicated_values:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
duplicate_single_data_value:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2011-10-13 21:06:08 +02:00
|
|
|
duplicate_zero_times:
|
|
|
|
cmp byte [esi],'{'
|
|
|
|
jne skip_single_data_value
|
|
|
|
inc esi
|
|
|
|
skip_data_value:
|
|
|
|
call skip_symbol
|
|
|
|
jc invalid_argument
|
|
|
|
cmp byte [esi],'}'
|
|
|
|
jne skip_data_value
|
|
|
|
inc esi
|
|
|
|
jmp data_defined
|
|
|
|
skip_single_data_value:
|
|
|
|
call skip_symbol
|
|
|
|
jmp data_defined
|
2006-07-28 15:39:16 +02:00
|
|
|
simple_data_value:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp edi,[display_buffer]
|
|
|
|
jae out_of_memory
|
|
|
|
call near dword [esp]
|
2006-07-28 15:39:16 +02:00
|
|
|
data_defined:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,','
|
|
|
|
je define_data
|
|
|
|
dec esi
|
|
|
|
add esp,4
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
data_unicode:
|
2006-09-22 17:55:59 +02:00
|
|
|
or [base_code],-1
|
|
|
|
jmp define_words
|
2006-07-28 15:39:16 +02:00
|
|
|
data_words:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [base_code],0
|
2006-07-28 15:39:16 +02:00
|
|
|
define_words:
|
2006-09-22 17:55:59 +02:00
|
|
|
call define_data
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
je get_word
|
|
|
|
cmp al,'?'
|
|
|
|
jne invalid_argument
|
|
|
|
mov eax,edi
|
2012-05-20 16:43:49 +02:00
|
|
|
and word [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas word [edi]
|
|
|
|
jmp undefined_data
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
get_word:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp [base_code],0
|
|
|
|
je word_data_value
|
|
|
|
cmp byte [esi],0
|
|
|
|
je word_string
|
2006-07-28 15:39:16 +02:00
|
|
|
word_data_value:
|
2006-09-22 17:55:59 +02:00
|
|
|
call get_word_value
|
|
|
|
call mark_relocation
|
|
|
|
stos word [edi]
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
word_string:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
copy_word_string:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
stos word [edi]
|
|
|
|
loop copy_word_string
|
2006-07-28 15:39:16 +02:00
|
|
|
word_string_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
inc esi
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
data_dwords:
|
2006-09-22 17:55:59 +02:00
|
|
|
call define_data
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
je get_dword
|
|
|
|
cmp al,'?'
|
|
|
|
jne invalid_argument
|
|
|
|
mov eax,edi
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas dword [edi]
|
|
|
|
jmp undefined_data
|
2006-07-28 15:39:16 +02:00
|
|
|
get_dword:
|
2006-09-22 17:55:59 +02:00
|
|
|
push esi
|
|
|
|
call get_dword_value
|
|
|
|
pop ebx
|
|
|
|
cmp byte [esi],':'
|
|
|
|
je complex_dword
|
|
|
|
call mark_relocation
|
|
|
|
stos dword [edi]
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
complex_dword:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
data_pwords:
|
2006-09-22 17:55:59 +02:00
|
|
|
call define_data
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
je get_pword
|
|
|
|
cmp al,'?'
|
|
|
|
jne invalid_argument
|
|
|
|
mov eax,edi
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas dword [edi]
|
2012-05-20 16:43:49 +02:00
|
|
|
and word [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas word [edi]
|
|
|
|
jmp undefined_data
|
2006-07-28 15:39:16 +02:00
|
|
|
get_pword:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
complex_pword:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
data_qwords:
|
2006-09-22 17:55:59 +02:00
|
|
|
call define_data
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
je get_qword
|
|
|
|
cmp al,'?'
|
|
|
|
jne invalid_argument
|
|
|
|
mov eax,edi
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas dword [edi]
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas dword [edi]
|
|
|
|
jmp undefined_data
|
2006-07-28 15:39:16 +02:00
|
|
|
get_qword:
|
2006-09-22 17:55:59 +02:00
|
|
|
call get_qword_value
|
|
|
|
call mark_relocation
|
|
|
|
stos dword [edi]
|
|
|
|
mov eax,edx
|
|
|
|
stos dword [edi]
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
data_twords:
|
2006-09-22 17:55:59 +02:00
|
|
|
call define_data
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
je get_tword
|
|
|
|
cmp al,'?'
|
|
|
|
jne invalid_argument
|
|
|
|
mov eax,edi
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas dword [edi]
|
2012-05-20 16:43:49 +02:00
|
|
|
and dword [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas dword [edi]
|
2012-05-20 16:43:49 +02:00
|
|
|
and word [edi],0
|
2006-09-22 17:55:59 +02:00
|
|
|
scas word [edi]
|
|
|
|
jmp undefined_data
|
2006-07-28 15:39:16 +02:00
|
|
|
get_tword:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2009-02-20 14:05:49 +01:00
|
|
|
jo value_out_of_range
|
|
|
|
cmp ax,7FFFh
|
|
|
|
jge value_out_of_range
|
|
|
|
cmp ax,0
|
|
|
|
jg tword_exp_ok
|
|
|
|
mov cx,ax
|
|
|
|
neg cx
|
|
|
|
inc cx
|
|
|
|
cmp cx,64
|
2006-09-22 17:55:59 +02:00
|
|
|
jae value_out_of_range
|
2009-02-20 14:05:49 +01:00
|
|
|
cmp cx,32
|
|
|
|
ja large_shift
|
|
|
|
mov eax,[esi]
|
|
|
|
mov edx,[esi+4]
|
|
|
|
mov ebx,edx
|
|
|
|
shr edx,cl
|
|
|
|
shrd eax,ebx,cl
|
|
|
|
jmp tword_mantissa_shift_done
|
|
|
|
large_shift:
|
|
|
|
sub cx,32
|
|
|
|
xor edx,edx
|
|
|
|
mov eax,[esi+4]
|
|
|
|
shr eax,cl
|
|
|
|
tword_mantissa_shift_done:
|
|
|
|
jnc store_shifted_mantissa
|
|
|
|
add eax,1
|
|
|
|
adc edx,0
|
|
|
|
store_shifted_mantissa:
|
|
|
|
mov [edi-8],eax
|
|
|
|
mov [edi-4],edx
|
|
|
|
xor ax,ax
|
|
|
|
test edx,1 shl 31
|
|
|
|
jz tword_exp_ok
|
|
|
|
inc ax
|
|
|
|
tword_exp_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov bl,[esi+11]
|
|
|
|
shl bx,15
|
|
|
|
or ax,bx
|
|
|
|
stos word [edi]
|
|
|
|
add esi,13
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
fp_zero_tword:
|
2006-09-22 17:55:59 +02:00
|
|
|
xor eax,eax
|
|
|
|
stos dword [edi]
|
|
|
|
stos dword [edi]
|
|
|
|
mov al,[esi+11]
|
|
|
|
shl ax,15
|
|
|
|
stos word [edi]
|
|
|
|
add esi,13
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
complex_tword:
|
2006-09-22 17:55:59 +02:00
|
|
|
call get_word_value
|
|
|
|
push eax
|
2009-03-05 01:32:57 +01:00
|
|
|
cmp byte [esi],':'
|
|
|
|
jne invalid_operand
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
data_file:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
pop ebx
|
|
|
|
mov edx,eax
|
|
|
|
sub [esp],edx
|
2009-10-01 02:41:45 +02:00
|
|
|
jc value_out_of_range
|
2006-07-28 15:39:16 +02:00
|
|
|
position_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
pop edx ebx
|
2009-10-01 02:41:45 +02:00
|
|
|
cmp eax,[esp]
|
|
|
|
ja value_out_of_range
|
2006-09-22 17:55:59 +02:00
|
|
|
mov [esp],eax
|
2006-07-28 15:39:16 +02:00
|
|
|
size_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
open_binary_file:
|
2006-09-22 17:55:59 +02:00
|
|
|
push esi
|
|
|
|
push edi
|
2011-10-13 21:06:08 +02:00
|
|
|
mov eax,[current_line]
|
|
|
|
find_current_source_path:
|
|
|
|
mov esi,[eax]
|
|
|
|
test byte [eax+7],80h
|
|
|
|
jz get_current_path
|
2012-05-20 16:43:49 +02:00
|
|
|
mov eax,[eax+8]
|
2011-10-13 21:06:08 +02:00
|
|
|
jmp find_current_source_path
|
2006-07-28 15:39:16 +02:00
|
|
|
get_current_path:
|
2006-09-22 17:55:59 +02:00
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
or al,al
|
|
|
|
jnz get_current_path
|
2006-07-28 15:39:16 +02:00
|
|
|
cut_current_path:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
current_path_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov esi,[esp+4]
|
2012-05-20 16:43:49 +02:00
|
|
|
call expand_path
|
|
|
|
pop edx
|
|
|
|
mov esi,edx
|
|
|
|
call open
|
|
|
|
jnc file_opened
|
|
|
|
mov edx,[include_paths]
|
|
|
|
search_in_include_paths:
|
|
|
|
push edx esi
|
|
|
|
mov edi,esi
|
|
|
|
mov esi,[esp+4]
|
|
|
|
call get_include_directory
|
|
|
|
mov [esp+4],esi
|
|
|
|
mov esi,[esp+8]
|
|
|
|
call expand_path
|
2006-09-22 17:55:59 +02:00
|
|
|
pop edx
|
|
|
|
mov esi,edx
|
|
|
|
call open
|
2012-05-20 16:43:49 +02:00
|
|
|
pop edx
|
2006-09-22 17:55:59 +02:00
|
|
|
jnc file_opened
|
2012-05-20 16:43:49 +02:00
|
|
|
cmp byte [edx],0
|
|
|
|
jne search_in_include_paths
|
2006-09-22 17:55:59 +02:00
|
|
|
mov edi,esi
|
|
|
|
mov esi,[esp]
|
|
|
|
push edi
|
2012-05-20 16:43:49 +02:00
|
|
|
call expand_path
|
2006-09-22 17:55:59 +02:00
|
|
|
pop edx
|
|
|
|
mov esi,edx
|
|
|
|
call open
|
|
|
|
jc file_not_found
|
2006-07-28 15:39:16 +02:00
|
|
|
file_opened:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov edi,esi
|
|
|
|
pop esi
|
|
|
|
ret
|
2006-07-28 15:39:16 +02:00
|
|
|
reserve_bytes:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
zero_bytes:
|
2006-09-22 17:55:59 +02:00
|
|
|
xor eax,eax
|
|
|
|
shr ecx,1
|
|
|
|
jnc bytes_stosb_ok
|
|
|
|
stos byte [edi]
|
2006-07-28 15:39:16 +02:00
|
|
|
bytes_stosb_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
shr ecx,1
|
|
|
|
jnc bytes_stosw_ok
|
|
|
|
stos word [edi]
|
2006-07-28 15:39:16 +02:00
|
|
|
bytes_stosw_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
rep stos dword [edi]
|
2006-07-28 15:39:16 +02:00
|
|
|
reserved_data:
|
2006-09-22 17:55:59 +02:00
|
|
|
pop eax
|
|
|
|
call undefined_data
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
reserve_words:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
zero_words:
|
2006-09-22 17:55:59 +02:00
|
|
|
xor eax,eax
|
|
|
|
shr ecx,1
|
|
|
|
jnc words_stosw_ok
|
|
|
|
stos word [edi]
|
2006-07-28 15:39:16 +02:00
|
|
|
words_stosw_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
rep stos dword [edi]
|
|
|
|
jmp reserved_data
|
2006-07-28 15:39:16 +02:00
|
|
|
reserve_dwords:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
zero_dwords:
|
2006-09-22 17:55:59 +02:00
|
|
|
xor eax,eax
|
|
|
|
rep stos dword [edi]
|
|
|
|
jmp reserved_data
|
2006-07-28 15:39:16 +02:00
|
|
|
reserve_pwords:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
reserve_qwords:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
reserve_twords:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
align_directive:
|
2006-09-22 17:55:59 +02:00
|
|
|
lods byte [esi]
|
|
|
|
cmp al,'('
|
|
|
|
jne invalid_argument
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
je invalid_value
|
2011-10-13 21:06:08 +02:00
|
|
|
call get_count_value
|
2006-09-22 17:55:59 +02:00
|
|
|
mov edx,eax
|
|
|
|
dec edx
|
|
|
|
test eax,edx
|
2011-10-13 21:06:08 +02:00
|
|
|
jnz invalid_align_value
|
2006-09-22 17:55:59 +02:00
|
|
|
or eax,eax
|
2011-10-13 21:06:08 +02:00
|
|
|
jz invalid_align_value
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2006-07-28 15:39:16 +02:00
|
|
|
pe_alignment:
|
2006-09-22 17:55:59 +02:00
|
|
|
cmp eax,1000h
|
|
|
|
ja section_not_aligned_enough
|
2006-07-28 15:39:16 +02:00
|
|
|
make_alignment:
|
2006-09-22 17:55:59 +02:00
|
|
|
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
|
2011-10-13 21:06:08 +02:00
|
|
|
invalid_align_value:
|
|
|
|
cmp [error_line],0
|
|
|
|
jne instruction_assembled
|
|
|
|
mov eax,[current_line]
|
|
|
|
mov [error_line],eax
|
|
|
|
mov [error],invalid_value
|
|
|
|
jmp instruction_assembled
|
2006-07-28 15:39:16 +02:00
|
|
|
nops:
|
2006-09-22 17:55:59 +02:00
|
|
|
mov eax,90909090h
|
|
|
|
shr ecx,1
|
|
|
|
jnc nops_stosb_ok
|
|
|
|
stos byte [edi]
|
2006-07-28 15:39:16 +02:00
|
|
|
nops_stosb_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
shr ecx,1
|
|
|
|
jnc nops_stosw_ok
|
|
|
|
stos word [edi]
|
2006-07-28 15:39:16 +02:00
|
|
|
nops_stosw_ok:
|
2006-09-22 17:55:59 +02:00
|
|
|
rep stos dword [edi]
|
|
|
|
jmp reserved_data
|
2009-02-20 14:05:49 +01:00
|
|
|
err_directive:
|
|
|
|
mov al,[esi]
|
|
|
|
cmp al,0Fh
|
|
|
|
je invoked_error
|
|
|
|
or al,al
|
|
|
|
jz invoked_error
|
|
|
|
jmp extra_characters_on_line
|
2012-05-20 13:47:06 +02:00
|
|
|
assert_directive:
|
|
|
|
call calculate_logical_expression
|
|
|
|
or al,al
|
|
|
|
jnz instruction_assembled
|
|
|
|
cmp [error_line],0
|
|
|
|
jne instruction_assembled
|
|
|
|
mov eax,[current_line]
|
|
|
|
mov [error_line],eax
|
|
|
|
mov [error],assertion_failed
|
|
|
|
jmp instruction_assembled
|