mirror of
https://github.com/tgrysztar/fasm
synced 2026-08-26 00:23:06 -04:00
release 1.49
This commit is contained in:
parent
8432a51de1
commit
ed701003c6
17 changed files with 1822 additions and 1226 deletions
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
flat assembler version 1.48
|
||||
flat assembler version 1.49
|
||||
Copyright (c) 1999-2003, Tomasz Grysztar.
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -26,22 +26,22 @@ assembler:
|
|||
mov [free_additional_memory],eax
|
||||
mov eax,[additional_memory_end]
|
||||
mov [structures_buffer],eax
|
||||
mov [next_pass_needed],0
|
||||
mov [code_type],16
|
||||
mov [reloc_labels],0
|
||||
mov [virtual_data],0
|
||||
mov esi,[source_start]
|
||||
mov edi,[code_start]
|
||||
xor eax,eax
|
||||
mov [output_format],al
|
||||
mov [org_origin],edi
|
||||
mov [org_start],edi
|
||||
mov [org_sib],eax
|
||||
mov [org_registers],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 [reloc_labels],al
|
||||
mov [virtual_data],al
|
||||
mov [code_type],16
|
||||
pass_loop:
|
||||
call assemble_line
|
||||
jnc pass_loop
|
||||
|
|
@ -104,7 +104,6 @@ assembler:
|
|||
mov eax,[error_line]
|
||||
or eax,eax
|
||||
jnz pass_error
|
||||
call flush_display_buffer
|
||||
assemble_ok:
|
||||
ret
|
||||
|
||||
|
|
@ -137,9 +136,6 @@ assemble_line:
|
|||
new_line:
|
||||
lods dword [esi]
|
||||
mov [current_line],eax
|
||||
test byte [eax+7],80h
|
||||
jnz continue_line
|
||||
mov [eax+12],edi
|
||||
continue_line:
|
||||
cmp byte [esi],0Fh
|
||||
je line_assembled
|
||||
|
|
@ -175,7 +171,7 @@ assemble_line:
|
|||
mov [ebx+11],ch
|
||||
setne al
|
||||
or ah,al
|
||||
mov edx,[org_sib]
|
||||
mov edx,[org_registers]
|
||||
cmp edx,[ebx+12]
|
||||
mov [ebx+12],edx
|
||||
setne al
|
||||
|
|
@ -434,7 +430,7 @@ org_directive:
|
|||
mov ecx,edi
|
||||
sub ecx,eax
|
||||
mov [org_origin],ecx
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
jmp instruction_assembled
|
||||
label_directive:
|
||||
|
|
@ -463,7 +459,7 @@ label_directive:
|
|||
mov eax,edi
|
||||
sub eax,[org_origin]
|
||||
cdq
|
||||
mov ebp,[org_sib]
|
||||
mov ebp,[org_registers]
|
||||
cmp byte [esi],80h
|
||||
jne define_free_label
|
||||
inc esi
|
||||
|
|
@ -772,11 +768,11 @@ virtual_directive:
|
|||
je set_virtual
|
||||
mov [value_type],2
|
||||
set_virtual:
|
||||
mov edx,[org_sib]
|
||||
mov byte [org_sib],bh
|
||||
mov byte [org_sib+1],bl
|
||||
mov byte [org_sib+2],ch
|
||||
mov byte [org_sib+3],cl
|
||||
mov edx,[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
|
||||
neg eax
|
||||
|
|
@ -842,7 +838,7 @@ virtual_directive:
|
|||
mov eax,[ebx+4]
|
||||
mov [org_origin],eax
|
||||
mov eax,[ebx+8]
|
||||
mov [org_sib],eax
|
||||
mov [org_registers],eax
|
||||
mov eax,[ebx+0Ch]
|
||||
mov [org_start],eax
|
||||
mov edi,[ebx+10h]
|
||||
|
|
|
|||
|
|
@ -3,22 +3,31 @@
|
|||
; Copyright (c) 1999-2003, Tomasz Grysztar.
|
||||
; All rights reserved.
|
||||
|
||||
org 100h
|
||||
format MZ
|
||||
heap 0
|
||||
entry main:start
|
||||
|
||||
macro align value { rb (value-1) - ($ + value-1) mod value }
|
||||
macro align value { rb (value-1) - ($ + value-1) mod value }
|
||||
|
||||
include 'modes.inc'
|
||||
|
||||
segment main use16
|
||||
|
||||
start:
|
||||
|
||||
mov ah,4Ah
|
||||
mov bx,1010h
|
||||
int 21h
|
||||
mov ax,ds
|
||||
push cs cs
|
||||
pop ds es
|
||||
mov [psp_segment],ax
|
||||
|
||||
mov dx,_logo
|
||||
mov ah,9
|
||||
int 21h
|
||||
|
||||
cld
|
||||
|
||||
call init_flatrm
|
||||
call go32
|
||||
use32
|
||||
call init_memory
|
||||
|
||||
call get_params
|
||||
|
|
@ -37,31 +46,33 @@ start:
|
|||
cmp byte [eax],0
|
||||
jne information
|
||||
|
||||
mov di,characters
|
||||
mov cx,100h
|
||||
mov edi,characters
|
||||
mov ecx,100h
|
||||
xor al,al
|
||||
make_characters_table:
|
||||
stosb
|
||||
inc al
|
||||
loop make_characters_table
|
||||
mov si,characters+'a'
|
||||
mov di,characters+'A'
|
||||
mov cx,26
|
||||
mov esi,characters+'a'
|
||||
mov edi,characters+'A'
|
||||
mov ecx,26
|
||||
rep movsb
|
||||
mov di,characters
|
||||
mov si,symbol_characters+1
|
||||
movzx cx,byte [si-1]
|
||||
xor bx,bx
|
||||
mov edi,characters
|
||||
mov esi,symbol_characters+1
|
||||
movzx ecx,byte [esi-1]
|
||||
xor ebx,ebx
|
||||
convert_table:
|
||||
lodsb
|
||||
mov bl,al
|
||||
mov byte [di+bx],0
|
||||
mov byte [edi+ebx],0
|
||||
loop convert_table
|
||||
mov [display_buffer],0
|
||||
|
||||
mov ebx,46Ch
|
||||
sub ebx,[program_base]
|
||||
mov eax,[ebx]
|
||||
xor ah,ah
|
||||
int 1Ah
|
||||
mov ax,cx
|
||||
shl eax,16
|
||||
mov ax,dx
|
||||
mov [start_time],eax
|
||||
|
||||
call preprocessor
|
||||
|
|
@ -69,15 +80,18 @@ start:
|
|||
call assembler
|
||||
call formatter
|
||||
|
||||
call display_user_messages
|
||||
movzx eax,[current_pass]
|
||||
inc eax
|
||||
call display_number
|
||||
mov ah,9
|
||||
mov dx,_passes_suffix
|
||||
int 21h
|
||||
mov ebx,46Ch
|
||||
sub ebx,[program_base]
|
||||
mov eax,[ebx]
|
||||
call dos_int
|
||||
xor ah,ah
|
||||
int 1Ah
|
||||
mov ax,cx
|
||||
shl eax,16
|
||||
mov ax,dx
|
||||
sub eax,[start_time]
|
||||
mov ebx,100
|
||||
mul ebx
|
||||
|
|
@ -97,20 +111,20 @@ start:
|
|||
call display_number
|
||||
mov ah,9
|
||||
mov dx,_seconds_suffix
|
||||
int 21h
|
||||
call dos_int
|
||||
display_bytes_count:
|
||||
mov eax,[written_size]
|
||||
call display_number
|
||||
mov ah,9
|
||||
mov dx,_bytes_suffix
|
||||
int 21h
|
||||
call dos_int
|
||||
xor al,al
|
||||
jmp exit_program
|
||||
|
||||
information:
|
||||
mov dx,_usage
|
||||
mov ah,9
|
||||
int 21h
|
||||
call dos_int
|
||||
mov al,1
|
||||
jmp exit_program
|
||||
|
||||
|
|
@ -139,6 +153,7 @@ _counter db 8,'00000000'
|
|||
align 4
|
||||
|
||||
program_base dd ?
|
||||
buffer_address dd ?
|
||||
memory_start dd ?
|
||||
memory_end dd ?
|
||||
additional_memory dd ?
|
||||
|
|
@ -170,7 +185,7 @@ anonymous_forward dd ?
|
|||
labels_list dd ?
|
||||
label_hash dd ?
|
||||
org_origin dd ?
|
||||
org_sib dd ?
|
||||
org_registers dd ?
|
||||
org_start dd ?
|
||||
undefined_data_start dd ?
|
||||
undefined_data_end dd ?
|
||||
|
|
@ -229,9 +244,7 @@ nextbyte db ?
|
|||
characters rb 100h
|
||||
params rb 100h
|
||||
converted rb 100h
|
||||
buffer rb 1000h
|
||||
|
||||
rb 400h
|
||||
if $ > 10000h
|
||||
display 'warning: 64k limit exceeded.'
|
||||
end if
|
||||
segment buffer
|
||||
|
||||
rb 1000h
|
||||
|
|
|
|||
260
SOURCE/DOS/MODES.INC
Normal file
260
SOURCE/DOS/MODES.INC
Normal file
|
|
@ -0,0 +1,260 @@
|
|||
|
||||
; flat assembler interface for DOS
|
||||
; Copyright (c) 1999-2003, Tomasz Grysztar.
|
||||
; All rights reserved.
|
||||
|
||||
segment modes use16
|
||||
|
||||
real32:
|
||||
mov ax,7202h
|
||||
push ax
|
||||
popf
|
||||
pushf
|
||||
pop bx
|
||||
cmp ax,bx
|
||||
je processor_ok
|
||||
call init_error
|
||||
db 'required 80386 or better',24h
|
||||
processor_ok:
|
||||
mov eax,ds
|
||||
shl eax,4
|
||||
mov [program_base],eax
|
||||
mov eax,buffer
|
||||
shl eax,4
|
||||
sub eax,[program_base]
|
||||
mov [buffer_address],eax
|
||||
smsw ax
|
||||
test al,1
|
||||
jnz dpmi
|
||||
mov bx,(400h+(100h*interrupt.size)) shr 4
|
||||
mov ah,48h
|
||||
int 21h
|
||||
jnc mem_ok
|
||||
not_enough_memory:
|
||||
call init_error
|
||||
db 'not enough conventional memory',24h
|
||||
mem_ok:
|
||||
push ds es
|
||||
mov es,ax
|
||||
push cs
|
||||
pop ds
|
||||
movzx eax,ax
|
||||
shl eax,4
|
||||
mov [real32_IDT_base],eax
|
||||
mov dx,100h
|
||||
xor bx,bx
|
||||
mov di,400h
|
||||
init_interrupts:
|
||||
mov si,interrupt
|
||||
mov [si+interrupt.vector],bx
|
||||
mov word [es:bx],di
|
||||
mov word [es:bx+2],es
|
||||
mov cx,interrupt.size
|
||||
rep movsb
|
||||
add bx,4
|
||||
dec dx
|
||||
jnz init_interrupts
|
||||
mov eax,cs ; calculate linear address of GDT
|
||||
shl eax,4
|
||||
or dword [real32_GDT+10],eax
|
||||
or dword [real16_GDT+10],eax
|
||||
add [real32_GDT_address],eax
|
||||
add [real16_GDT_address],eax
|
||||
pop es ds
|
||||
mov [mode],real32
|
||||
call modes:switch_real32
|
||||
use32
|
||||
retfw
|
||||
use16
|
||||
init_error:
|
||||
push cs
|
||||
pop ds
|
||||
mov dx,init_error_prefix
|
||||
mov ah,9
|
||||
int 21h
|
||||
pop dx
|
||||
int 21h
|
||||
mov dx,init_error_suffix
|
||||
int 21h
|
||||
mov ax,04CFFh
|
||||
int 21h
|
||||
|
||||
switch_real32:
|
||||
pushfw
|
||||
push eax
|
||||
push word ds
|
||||
push word es
|
||||
push word fs
|
||||
push word gs
|
||||
cli
|
||||
mov eax,ss
|
||||
mov cr3,eax
|
||||
lgdt [cs:real32_GDTR] ; load GDT register
|
||||
mov eax,cr0 ; switch to protected modes
|
||||
or al,1
|
||||
mov cr0,eax
|
||||
jmp 1 shl 3:pm32_start
|
||||
pm32_start:
|
||||
use32
|
||||
mov ax,2 shl 3 ; load 32-bit data descriptor
|
||||
mov ds,ax ; to all data segment registers
|
||||
mov es,ax
|
||||
mov fs,ax
|
||||
mov gs,ax
|
||||
mov ss,ax
|
||||
mov eax,cr0 ; switch back to real modes
|
||||
and al,not 1
|
||||
mov cr0,eax
|
||||
jmp modes:pm32_end
|
||||
pm32_end:
|
||||
mov eax,cr3
|
||||
mov ss,eax
|
||||
lidt [cs:real32_IDTR]
|
||||
pop word gs
|
||||
pop word fs
|
||||
pop word es
|
||||
pop word ds
|
||||
pop eax
|
||||
popfw
|
||||
retfw
|
||||
|
||||
switch_real16:
|
||||
pushfw
|
||||
push eax
|
||||
cli
|
||||
lgdt [cs:real16_GDTR] ; load GDT register
|
||||
mov eax,cr0 ; switch to protected modes
|
||||
or al,1
|
||||
mov cr0,eax
|
||||
jmp 1 shl 3:pm16_start
|
||||
pm16_start:
|
||||
use16
|
||||
mov eax,cr0 ; switch back to real modes
|
||||
and al,not 1
|
||||
mov cr0,eax
|
||||
jmp modes:pm16_end
|
||||
pm16_end:
|
||||
lidt [cs:real16_IDTR]
|
||||
pop eax
|
||||
popfw
|
||||
retfd
|
||||
use32
|
||||
|
||||
interrupt:
|
||||
call modes:switch_real16
|
||||
use16
|
||||
movzx esp,sp
|
||||
push word [esp+4]
|
||||
push cs
|
||||
call .real16
|
||||
pushfw
|
||||
pop word [esp+4]
|
||||
call modes:switch_real32
|
||||
use32
|
||||
iretw
|
||||
.real16:
|
||||
use16
|
||||
push eax
|
||||
push ds
|
||||
xor ax,ax
|
||||
mov ds,ax
|
||||
mov eax,[word 0]
|
||||
label .vector word at $-2-interrupt
|
||||
pop ds
|
||||
xchg eax,[esp]
|
||||
retfw
|
||||
.size = $-interrupt
|
||||
|
||||
label real32_GDTR pword
|
||||
real32_GDT_limit dw 3*8-1 ; limit of GDT
|
||||
real32_GDT_address dd real32_GDT ; linear address of GDT
|
||||
real32_GDT rw 4 ; null descriptor
|
||||
dw 0FFFFh,0,9A00h,0CFh ; 32-bit code descriptor
|
||||
dw 0FFFFh,0,9200h,08Fh ; 4 GB data descriptor
|
||||
label real16_GDTR pword
|
||||
real16_GDT_limit dw 2*8-1 ; limit of GDT
|
||||
real16_GDT_address dd real16_GDT ; linear address of GDT
|
||||
real16_GDT rw 4 ; null descriptor
|
||||
dw 0FFFFh,0,9A00h,0 ; 16-bit code descriptor
|
||||
|
||||
label real32_IDTR pword
|
||||
real32_IDT_limit dw 3FFh
|
||||
real32_IDT_base dd ?
|
||||
label real16_IDTR pword
|
||||
real16_IDT_limit dw 3FFh
|
||||
real16_IDT_base dd 0
|
||||
|
||||
init_error_prefix db 'error: ',24h
|
||||
init_error_suffix db '.',0Dh,0Ah,24h
|
||||
|
||||
dpmi:
|
||||
mov ax,1687h
|
||||
int 2Fh
|
||||
or ax,ax ; DPMI installed?
|
||||
jnz no_dpmi
|
||||
test bl,1 ; 32-bit programs supported?
|
||||
jz no_dpmi
|
||||
mov word [cs:mode_switch],di
|
||||
mov word [cs:mode_switch+2],es
|
||||
mov bx,si ; allocate memory for DPMI data
|
||||
mov ah,48h
|
||||
int 21h
|
||||
jc not_enough_memory
|
||||
mov ds,[psp_segment]
|
||||
mov es,ax
|
||||
mov ax,1
|
||||
call far [cs:mode_switch] ; switch to protected mode
|
||||
jc error
|
||||
mov cx,1
|
||||
xor ax,ax
|
||||
int 31h ; allocate descriptor for code
|
||||
mov si,ax
|
||||
xor ax,ax
|
||||
int 31h ; allocate descriptor for data
|
||||
mov di,ax
|
||||
mov dx,cs
|
||||
lar cx,dx
|
||||
shr cx,8
|
||||
or cx,0C000h
|
||||
mov bx,si
|
||||
mov ax,9
|
||||
int 31h ; set code descriptor access rights
|
||||
mov dx,ds
|
||||
lar cx,dx
|
||||
shr cx,8
|
||||
or cx,0C000h
|
||||
mov bx,di
|
||||
int 31h ; set data descriptor access rights
|
||||
mov ecx,main
|
||||
shl ecx,4
|
||||
mov dx,cx
|
||||
shr ecx,16
|
||||
mov ax,7
|
||||
int 31h ; set data descriptor base address
|
||||
movzx ecx,word [esp+2]
|
||||
shl ecx,4
|
||||
mov dx,cx
|
||||
shr ecx,16
|
||||
mov bx,si
|
||||
int 31h ; set code descriptor base address
|
||||
mov cx,0FFFFh
|
||||
mov dx,0FFFFh
|
||||
mov ax,8 ; set segment limit to 4 GB
|
||||
int 31h
|
||||
mov bx,di
|
||||
int 31h
|
||||
mov es,di
|
||||
mov [es:psp_segment],ds
|
||||
mov ds,di
|
||||
mov [mode],dpmi
|
||||
pop ebx
|
||||
movzx ebx,bx
|
||||
push esi
|
||||
push ebx
|
||||
retfd
|
||||
|
||||
no_dpmi:
|
||||
call init_error
|
||||
db 'system is in protected mode without DPMI services',24h
|
||||
|
||||
mode_switch dd ?
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -974,7 +974,7 @@ calculate_expression:
|
|||
stos dword [edi]
|
||||
mov eax,edx
|
||||
stos dword [edi]
|
||||
mov eax,[org_sib]
|
||||
mov eax,[org_registers]
|
||||
stos dword [edi]
|
||||
add edi,8
|
||||
jmp calculation_loop
|
||||
|
|
@ -2066,7 +2066,6 @@ get_logical_value:
|
|||
call check_character
|
||||
jc return_true
|
||||
jmp symbols_different
|
||||
|
||||
compare_symbol_types:
|
||||
inc esi
|
||||
pop ebx
|
||||
|
|
|
|||
|
|
@ -11,11 +11,6 @@ formatter:
|
|||
bt [format_flags],0
|
||||
jnc elf_formatter
|
||||
common_formatter:
|
||||
cmp [output_format],3
|
||||
jne prepare_code
|
||||
mov eax,[stub_size]
|
||||
sub [code_start],eax
|
||||
prepare_code:
|
||||
mov eax,edi
|
||||
sub eax,[code_start]
|
||||
mov [real_code_size],eax
|
||||
|
|
@ -29,16 +24,28 @@ formatter:
|
|||
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_code
|
||||
jne write_output
|
||||
call write_mz_header
|
||||
write_output:
|
||||
call write_code
|
||||
output_written:
|
||||
call close
|
||||
ret
|
||||
write_code:
|
||||
mov edx,[code_start]
|
||||
mov ecx,[code_size]
|
||||
add [written_size],ecx
|
||||
call write
|
||||
jc write_failed
|
||||
call close
|
||||
ret
|
||||
format_directive:
|
||||
cmp edi,[code_start]
|
||||
|
|
@ -289,7 +296,7 @@ segment_directive:
|
|||
xor al,al
|
||||
rep stos byte [edi]
|
||||
mov [org_origin],edi
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
mov eax,edx
|
||||
call undefined_data
|
||||
|
|
@ -317,10 +324,13 @@ mz_entry:
|
|||
cmp al,'('
|
||||
jne invalid_argument
|
||||
call get_word_value
|
||||
cmp [next_pass_needed],0
|
||||
jne initial_cs_ok
|
||||
cmp [value_type],1
|
||||
jne invalid_address
|
||||
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
|
||||
|
|
@ -352,10 +362,13 @@ mz_stack:
|
|||
mov [edx+10h],ax
|
||||
jmp instruction_assembled
|
||||
stack_pointer:
|
||||
cmp [next_pass_needed],0
|
||||
jne initial_ss_ok
|
||||
cmp [value_type],1
|
||||
jne invalid_address
|
||||
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
|
||||
|
|
@ -692,8 +705,8 @@ format_pe:
|
|||
add esi,eax
|
||||
inc esi
|
||||
pe_settings_ok:
|
||||
mov eax,[stub_size]
|
||||
or eax,eax
|
||||
mov ebp,[stub_size]
|
||||
or ebp,ebp
|
||||
jz make_pe_stub
|
||||
cmp edx,[stub_file]
|
||||
je pe_stub_ok
|
||||
|
|
@ -705,20 +718,11 @@ format_pe:
|
|||
sub eax,[code_start]
|
||||
mov [stub_size],eax
|
||||
mov [code_start],edi
|
||||
mov ebp,eax
|
||||
pe_stub_ok:
|
||||
mov edx,edi
|
||||
imul ecx,[number_of_sections],28h
|
||||
add ecx,18h+0E0h
|
||||
add ecx,eax
|
||||
dec ecx
|
||||
shr ecx,9
|
||||
inc ecx
|
||||
shl ecx,9
|
||||
sub ecx,eax
|
||||
mov eax,[display_buffer]
|
||||
sub eax,ecx
|
||||
cmp edi,eax
|
||||
jae out_of_memory
|
||||
mov ecx,18h+0E0h
|
||||
add ebp,ecx
|
||||
shr ecx,2
|
||||
xor eax,eax
|
||||
rep stos dword [edi]
|
||||
|
|
@ -732,24 +736,47 @@ format_pe:
|
|||
mov word [edx+40h],1 ; OS version
|
||||
mov eax,[image_base]
|
||||
mov dword [edx+34h],eax
|
||||
mov ax,[subsystem]
|
||||
mov [edx+5Ch],ax
|
||||
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
|
||||
mov eax,edi
|
||||
sub eax,[code_start]
|
||||
add eax,[stub_size]
|
||||
mov [edx+54h],eax ; size of headers
|
||||
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
|
||||
bsf ecx,[edx+3Ch]
|
||||
imul ebx,[number_of_sections],28h
|
||||
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
|
||||
bsf ecx,[edx+38h]
|
||||
dec eax
|
||||
shr eax,12
|
||||
shr eax,cl
|
||||
inc eax
|
||||
shl eax,12
|
||||
shl eax,cl
|
||||
mov [edx+28h],eax ; entry point rva
|
||||
mov [code_type],32
|
||||
or [reloc_labels],-1
|
||||
|
|
@ -765,7 +792,7 @@ format_pe:
|
|||
add eax,edi
|
||||
sub eax,[edx+34h]
|
||||
mov [org_origin],eax
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
bt [format_flags],8
|
||||
jnc instruction_assembled
|
||||
|
|
@ -807,7 +834,6 @@ pe_section:
|
|||
call close_pe_section
|
||||
bts [format_flags],5
|
||||
lea ecx,[ebx+28h]
|
||||
mov edx,[code_start]
|
||||
add edx,[edx+54h]
|
||||
sub edx,[stub_size]
|
||||
cmp ecx,edx
|
||||
|
|
@ -840,7 +866,7 @@ pe_section:
|
|||
sub eax,[ebx+0Ch]
|
||||
sub eax,[edx+34h]
|
||||
mov [org_origin],eax
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
or [reloc_labels],-1
|
||||
get_section_flags:
|
||||
|
|
@ -874,6 +900,7 @@ pe_section:
|
|||
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
|
||||
|
|
@ -885,18 +912,22 @@ pe_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]
|
||||
align_section:
|
||||
mov [undefined_data_end],0
|
||||
mov edx,edi
|
||||
sub edx,[ebx+14h]
|
||||
mov ecx,edx
|
||||
dec ecx
|
||||
shr ecx,9
|
||||
inc ecx
|
||||
shl ecx,9
|
||||
mov [ebx+10h],ecx
|
||||
sub ecx,edx
|
||||
bsf ecx,[edx+3Ch]
|
||||
mov ebp,edi
|
||||
sub ebp,[ebx+14h]
|
||||
mov eax,ebp
|
||||
dec eax
|
||||
shr eax,cl
|
||||
inc eax
|
||||
shl eax,cl
|
||||
mov [ebx+10h],eax
|
||||
sub eax,ebp
|
||||
mov ecx,eax
|
||||
xor al,al
|
||||
rep stos byte [edi]
|
||||
mov eax,[code_start]
|
||||
|
|
@ -909,10 +940,11 @@ pe_section:
|
|||
jne udata_ok
|
||||
or byte [ebx+24h],80h
|
||||
udata_ok:
|
||||
bsf ecx,[edx+38h]
|
||||
dec eax
|
||||
shr eax,12
|
||||
shr eax,cl
|
||||
inc eax
|
||||
shl eax,12
|
||||
shl eax,cl
|
||||
add eax,[ebx+0Ch]
|
||||
add ebx,28h
|
||||
mov [current_section],ebx
|
||||
|
|
@ -969,10 +1001,13 @@ pe_entry:
|
|||
cmp byte [esi],'.'
|
||||
je invalid_value
|
||||
call get_dword_value
|
||||
cmp [next_pass_needed],0
|
||||
jne pe_entry_ok
|
||||
cmp [value_type],2
|
||||
jne invalid_address
|
||||
je pe_entry_ok
|
||||
cmp [error_line],0
|
||||
jne pe_entry_ok
|
||||
mov eax,[current_line]
|
||||
mov [error_line],eax
|
||||
mov [error],invalid_address
|
||||
pe_entry_ok:
|
||||
mov edx,[code_start]
|
||||
sub eax,[edx+34h]
|
||||
|
|
@ -1072,7 +1107,7 @@ make_pe_fixups:
|
|||
sub esi,eax
|
||||
mov [free_additional_memory],esi
|
||||
or [number_of_relocations],-1
|
||||
mov edx,1000h
|
||||
xor edx,edx
|
||||
mov ebp,edi
|
||||
make_fixups:
|
||||
cmp [esi],edx
|
||||
|
|
@ -1118,16 +1153,17 @@ close_pe:
|
|||
shl eax,2
|
||||
sub [free_additional_memory],eax
|
||||
pe_flags_ok:
|
||||
xor ecx,ecx
|
||||
mov eax,[number_of_sections]
|
||||
mov [edx+6],ax
|
||||
bsf ecx,[edx+3Ch]
|
||||
imul eax,28h
|
||||
add eax,18h+0E0h
|
||||
add eax,[stub_size]
|
||||
dec eax
|
||||
shr eax,9
|
||||
shr eax,cl
|
||||
inc eax
|
||||
shl eax,9
|
||||
shl eax,cl
|
||||
xor ecx,ecx
|
||||
cmp eax,[edx+54h]
|
||||
je process_directories
|
||||
or [next_pass_needed],-1
|
||||
|
|
@ -1147,6 +1183,25 @@ close_pe:
|
|||
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
|
||||
|
||||
format_coff:
|
||||
|
|
@ -1170,7 +1225,7 @@ format_coff:
|
|||
mov [current_section],ebx
|
||||
mov [number_of_sections],0
|
||||
mov [org_origin],edi
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
mov [code_type],32
|
||||
or [reloc_labels],-1
|
||||
|
|
@ -1188,7 +1243,7 @@ coff_section:
|
|||
mov [ebx],al
|
||||
mov [ebx+8],edi
|
||||
mov [org_origin],edi
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
or [reloc_labels],-1
|
||||
mov [ebx+10h],eax
|
||||
|
|
@ -1581,13 +1636,7 @@ coff_formatter:
|
|||
add [written_size],ecx
|
||||
call write
|
||||
jc write_failed
|
||||
mov edx,[code_start]
|
||||
mov ecx,[code_size]
|
||||
add [written_size],ecx
|
||||
call write
|
||||
jc write_failed
|
||||
call close
|
||||
ret
|
||||
jmp write_output
|
||||
store_symbol_name:
|
||||
push esi
|
||||
mov esi,[esi+4]
|
||||
|
|
@ -1652,7 +1701,7 @@ format_elf:
|
|||
mov [current_section],ebx
|
||||
mov [number_of_sections],0
|
||||
mov [org_origin],edi
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
mov [code_type],32
|
||||
or [reloc_labels],-1
|
||||
|
|
@ -1673,7 +1722,7 @@ elf_section:
|
|||
mov [ebx],al
|
||||
mov [ebx+8],edi
|
||||
mov [org_origin],edi
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
or [reloc_labels],-1
|
||||
mov al,10b
|
||||
|
|
@ -2072,19 +2121,14 @@ elf_formatter:
|
|||
mov edx,[output_file]
|
||||
call create
|
||||
jc write_failed
|
||||
mov edx,[code_start]
|
||||
mov ecx,[code_size]
|
||||
add [written_size],ecx
|
||||
call write
|
||||
jc write_failed
|
||||
call write_code
|
||||
mov ecx,edi
|
||||
mov edx,[free_additional_memory]
|
||||
sub ecx,edx
|
||||
add [written_size],ecx
|
||||
call write
|
||||
jc write_failed
|
||||
call close
|
||||
ret
|
||||
jmp output_written
|
||||
|
||||
format_elf_exe:
|
||||
add esi,2
|
||||
|
|
@ -2115,7 +2159,7 @@ format_elf_exe:
|
|||
neg eax
|
||||
add eax,edi
|
||||
mov [org_origin],eax
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
jmp instruction_assembled
|
||||
elf_entry:
|
||||
|
|
@ -2180,7 +2224,7 @@ elf_exe_section:
|
|||
neg eax
|
||||
add eax,edi
|
||||
mov [org_origin],eax
|
||||
mov [org_sib],0
|
||||
mov [org_registers],0
|
||||
mov [org_start],edi
|
||||
jmp instruction_assembled
|
||||
close_elf_exe_section:
|
||||
|
|
@ -2239,6 +2283,7 @@ formatter_symbols:
|
|||
db 2,'ms',18h,41h
|
||||
db 2,'mz',18h,2
|
||||
db 6,'native',1Bh,1
|
||||
db 11,'notpageable',19h,27
|
||||
db 2,'pe',18h,3
|
||||
db 8,'readable',19h,30
|
||||
db 8,'resource',1Ah,2
|
||||
|
|
|
|||
|
|
@ -3,115 +3,116 @@
|
|||
; Copyright (c) 1999-2003, Tomasz Grysztar.
|
||||
; All rights reserved.
|
||||
|
||||
format ELF executable
|
||||
entry start
|
||||
format ELF executable
|
||||
entry start
|
||||
|
||||
macro align value { rb (value-1) - ($ + value-1) mod value }
|
||||
macro align value { rb (value-1) - ($ + value-1) mod value }
|
||||
|
||||
start:
|
||||
|
||||
mov esi,_logo
|
||||
call display_string
|
||||
mov esi,_logo
|
||||
call display_string
|
||||
|
||||
pop eax
|
||||
cmp eax,3
|
||||
jne information
|
||||
pop eax
|
||||
pop [input_file]
|
||||
pop [output_file]
|
||||
pop eax
|
||||
pop [environment]
|
||||
pop eax
|
||||
cmp eax,3
|
||||
jne information
|
||||
pop eax
|
||||
pop [input_file]
|
||||
pop [output_file]
|
||||
pop eax
|
||||
pop [environment]
|
||||
|
||||
call init_memory
|
||||
call init_memory
|
||||
|
||||
mov edi,characters
|
||||
mov ecx,100h
|
||||
xor al,al
|
||||
mov edi,characters
|
||||
mov ecx,100h
|
||||
xor al,al
|
||||
make_characters_table:
|
||||
stosb
|
||||
inc al
|
||||
loop make_characters_table
|
||||
mov esi,characters+'a'
|
||||
mov edi,characters+'A'
|
||||
mov ecx,26
|
||||
rep movsb
|
||||
mov edi,characters
|
||||
mov esi,symbol_characters+1
|
||||
movzx ecx,byte [esi-1]
|
||||
xor eax,eax
|
||||
stosb
|
||||
inc al
|
||||
loop make_characters_table
|
||||
mov esi,characters+'a'
|
||||
mov edi,characters+'A'
|
||||
mov ecx,26
|
||||
rep movsb
|
||||
mov edi,characters
|
||||
mov esi,symbol_characters+1
|
||||
movzx ecx,byte [esi-1]
|
||||
xor eax,eax
|
||||
convert_table:
|
||||
lodsb
|
||||
mov byte [edi+eax],0
|
||||
loop convert_table
|
||||
mov [display_buffer],0
|
||||
lodsb
|
||||
mov byte [edi+eax],0
|
||||
loop convert_table
|
||||
mov [display_buffer],0
|
||||
|
||||
mov eax,78
|
||||
mov ebx,buffer
|
||||
xor ecx,ecx
|
||||
int 0x80
|
||||
mov eax,dword [buffer]
|
||||
mov ecx,1000
|
||||
mul ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword [buffer+4]
|
||||
div ecx
|
||||
add eax,ebx
|
||||
mov [start_time],eax
|
||||
mov eax,78
|
||||
mov ebx,buffer
|
||||
xor ecx,ecx
|
||||
int 0x80
|
||||
mov eax,dword [buffer]
|
||||
mov ecx,1000
|
||||
mul ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword [buffer+4]
|
||||
div ecx
|
||||
add eax,ebx
|
||||
mov [start_time],eax
|
||||
|
||||
call preprocessor
|
||||
call parser
|
||||
call assembler
|
||||
call formatter
|
||||
call preprocessor
|
||||
call parser
|
||||
call assembler
|
||||
call formatter
|
||||
|
||||
movzx eax,[current_pass]
|
||||
inc eax
|
||||
call display_number
|
||||
mov esi,_passes_suffix
|
||||
call display_string
|
||||
mov eax,78
|
||||
mov ebx,buffer
|
||||
xor ecx,ecx
|
||||
int 0x80
|
||||
mov eax,dword [buffer]
|
||||
mov ecx,1000
|
||||
mul ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword [buffer+4]
|
||||
div ecx
|
||||
add eax,ebx
|
||||
sub eax,[start_time]
|
||||
jnc time_ok
|
||||
add eax,3600000
|
||||
call display_user_messages
|
||||
movzx eax,[current_pass]
|
||||
inc eax
|
||||
call display_number
|
||||
mov esi,_passes_suffix
|
||||
call display_string
|
||||
mov eax,78
|
||||
mov ebx,buffer
|
||||
xor ecx,ecx
|
||||
int 0x80
|
||||
mov eax,dword [buffer]
|
||||
mov ecx,1000
|
||||
mul ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword [buffer+4]
|
||||
div ecx
|
||||
add eax,ebx
|
||||
sub eax,[start_time]
|
||||
jnc time_ok
|
||||
add eax,3600000
|
||||
time_ok:
|
||||
xor edx,edx
|
||||
mov ebx,100
|
||||
div ebx
|
||||
or eax,eax
|
||||
jz display_bytes_count
|
||||
xor edx,edx
|
||||
mov ebx,10
|
||||
div ebx
|
||||
push edx
|
||||
call display_number
|
||||
mov dl,'.'
|
||||
call display_character
|
||||
pop eax
|
||||
call display_number
|
||||
mov esi,_seconds_suffix
|
||||
call display_string
|
||||
xor edx,edx
|
||||
mov ebx,100
|
||||
div ebx
|
||||
or eax,eax
|
||||
jz display_bytes_count
|
||||
xor edx,edx
|
||||
mov ebx,10
|
||||
div ebx
|
||||
push edx
|
||||
call display_number
|
||||
mov dl,'.'
|
||||
call display_character
|
||||
pop eax
|
||||
call display_number
|
||||
mov esi,_seconds_suffix
|
||||
call display_string
|
||||
display_bytes_count:
|
||||
mov eax,[written_size]
|
||||
call display_number
|
||||
mov esi,_bytes_suffix
|
||||
call display_string
|
||||
xor al,al
|
||||
jmp exit_program
|
||||
mov eax,[written_size]
|
||||
call display_number
|
||||
mov esi,_bytes_suffix
|
||||
call display_string
|
||||
xor al,al
|
||||
jmp exit_program
|
||||
|
||||
information:
|
||||
mov esi,_usage
|
||||
call display_string
|
||||
mov al,1
|
||||
jmp exit_program
|
||||
mov esi,_usage
|
||||
call display_string
|
||||
mov al,1
|
||||
jmp exit_program
|
||||
|
||||
include 'system.inc'
|
||||
|
||||
|
|
@ -169,7 +170,7 @@ anonymous_forward dd ?
|
|||
labels_list dd ?
|
||||
label_hash dd ?
|
||||
org_origin dd ?
|
||||
org_sib dd ?
|
||||
org_registers dd ?
|
||||
org_start dd ?
|
||||
undefined_data_start dd ?
|
||||
undefined_data_end dd ?
|
||||
|
|
|
|||
|
|
@ -216,15 +216,6 @@ display_string:
|
|||
int 0x80
|
||||
pop ebx
|
||||
ret
|
||||
display_block:
|
||||
push ebx
|
||||
mov eax,4
|
||||
mov ebx,1
|
||||
mov edx,ecx
|
||||
mov ecx,esi
|
||||
int 0x80
|
||||
pop ebx
|
||||
ret
|
||||
display_character:
|
||||
push ebx
|
||||
mov [character],dl
|
||||
|
|
@ -268,6 +259,32 @@ display_number:
|
|||
pop ebx
|
||||
ret
|
||||
|
||||
display_user_messages:
|
||||
mov [displayed_count],0
|
||||
call flush_display_buffer
|
||||
cmp [displayed_count],0
|
||||
je line_break_ok
|
||||
cmp [last_displayed],0Ah
|
||||
je line_break_ok
|
||||
mov dl,0Ah
|
||||
call display_character
|
||||
line_break_ok:
|
||||
ret
|
||||
display_block:
|
||||
jecxz block_displayed
|
||||
add [displayed_count],ecx
|
||||
mov al,[esi+ecx-1]
|
||||
mov [last_displayed],al
|
||||
push ebx
|
||||
mov eax,4
|
||||
mov ebx,1
|
||||
mov edx,ecx
|
||||
mov ecx,esi
|
||||
int 0x80
|
||||
pop ebx
|
||||
block_displayed:
|
||||
ret
|
||||
|
||||
fatal_error:
|
||||
mov esi,error_prefix
|
||||
call display_string
|
||||
|
|
@ -278,34 +295,44 @@ fatal_error:
|
|||
mov al,0FFh
|
||||
jmp exit_program
|
||||
assembler_error:
|
||||
call flush_display_buffer
|
||||
call display_user_messages
|
||||
push dword 0
|
||||
mov ebx,[current_line]
|
||||
find_error_home:
|
||||
get_error_lines:
|
||||
push ebx
|
||||
test byte [ebx+7],80h
|
||||
jz error_home_ok
|
||||
jz display_error_line
|
||||
mov edx,ebx
|
||||
find_definition_origin:
|
||||
mov edx,[edx+12]
|
||||
test byte [edx+7],80h
|
||||
jnz find_definition_origin
|
||||
push edx
|
||||
mov ebx,[ebx+8]
|
||||
jmp find_error_home
|
||||
error_home_ok:
|
||||
jmp get_error_lines
|
||||
display_error_line:
|
||||
mov esi,[ebx]
|
||||
call display_string
|
||||
mov esi,line_number_start
|
||||
call display_string
|
||||
mov eax,[ebx+4]
|
||||
and eax,7FFFFFFFh
|
||||
call display_number
|
||||
mov dl,']'
|
||||
call display_character
|
||||
cmp ebx,[current_line]
|
||||
pop esi
|
||||
cmp ebx,esi
|
||||
je line_number_ok
|
||||
mov dl,20h
|
||||
call display_character
|
||||
mov esi,[current_line]
|
||||
push esi
|
||||
mov esi,[esi]
|
||||
movzx ecx,byte [esi]
|
||||
inc esi
|
||||
call display_block
|
||||
mov esi,line_number_start
|
||||
call display_string
|
||||
mov esi,[current_line]
|
||||
pop esi
|
||||
mov eax,[esi+4]
|
||||
and eax,7FFFFFFFh
|
||||
call display_number
|
||||
|
|
@ -326,11 +353,14 @@ assembler_error:
|
|||
xor al,al
|
||||
call lseek
|
||||
mov ecx,[esp]
|
||||
mov edx,[memory_start]
|
||||
mov edx,[additional_memory]
|
||||
lea eax,[edx+ecx]
|
||||
cmp eax,[additional_memory_end]
|
||||
ja out_of_memory
|
||||
call read
|
||||
call close
|
||||
pop ecx
|
||||
mov esi,[memory_start]
|
||||
mov esi,[additional_memory]
|
||||
get_line_data:
|
||||
mov al,[esi]
|
||||
cmp al,0Ah
|
||||
|
|
@ -345,11 +375,14 @@ assembler_error:
|
|||
loop get_line_data
|
||||
display_line_data:
|
||||
mov ecx,esi
|
||||
mov esi,[memory_start]
|
||||
mov esi,[additional_memory]
|
||||
sub ecx,esi
|
||||
call display_block
|
||||
mov esi,lf
|
||||
call display_string
|
||||
pop ebx
|
||||
or ebx,ebx
|
||||
jnz display_error_line
|
||||
mov esi,error_prefix
|
||||
call display_string
|
||||
pop esi
|
||||
|
|
@ -366,6 +399,8 @@ make_timestamp:
|
|||
ret
|
||||
|
||||
character db ?,0
|
||||
displayed_count dd ?
|
||||
last_displayed db ?
|
||||
|
||||
error_prefix db 'error: ',0
|
||||
error_suffix db '.'
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ parser:
|
|||
mov [current_locals_prefix],eax
|
||||
mov [anonymous_reverse],eax
|
||||
mov [anonymous_forward],eax
|
||||
mov esi,[source_start]
|
||||
mov edi,[code_start]
|
||||
mov esi,[memory_start]
|
||||
mov edi,[source_start]
|
||||
parser_loop:
|
||||
mov [current_line],esi
|
||||
cmp edi,[labels_list]
|
||||
|
|
@ -24,14 +24,12 @@ parser:
|
|||
stos dword [edi]
|
||||
add esi,16
|
||||
call parse_line
|
||||
cmp esi,[code_start]
|
||||
cmp esi,[source_start]
|
||||
jb parser_loop
|
||||
xor al,al
|
||||
stos byte [edi]
|
||||
cmp [anonymous_forward],0
|
||||
jne unexpected_end_of_file
|
||||
mov eax,[code_start]
|
||||
mov [source_start],eax
|
||||
mov [code_start],edi
|
||||
ret
|
||||
|
||||
|
|
@ -216,8 +214,6 @@ parse_line:
|
|||
je unallowed_character
|
||||
cmp al,'#'
|
||||
je unallowed_character
|
||||
cmp al,'`'
|
||||
je unallowed_character
|
||||
dec esi
|
||||
cmp al,1Ah
|
||||
jne expression_argument
|
||||
|
|
@ -498,7 +494,7 @@ parse_line:
|
|||
mov al,0F2h
|
||||
jmp separator
|
||||
less:
|
||||
cmp byte [edi-1],83h
|
||||
cmp byte [edi-1],0F6h
|
||||
je separator
|
||||
cmp byte [esi],'>'
|
||||
je not_equal
|
||||
|
|
@ -726,8 +722,8 @@ get_label_id:
|
|||
push edi
|
||||
push ecx esi
|
||||
mov edi,[free_additional_memory]
|
||||
xor al,al
|
||||
stos byte [edi]
|
||||
xor ax,ax
|
||||
stos word [edi]
|
||||
mov esi,[current_locals_prefix]
|
||||
mov ebx,edi
|
||||
lods byte [esi]
|
||||
|
|
@ -747,6 +743,7 @@ get_label_id:
|
|||
pop edi
|
||||
push esi
|
||||
movzx ecx,al
|
||||
mov byte [ebx-1],al
|
||||
mov esi,ebx
|
||||
call get_label_id
|
||||
pop esi
|
||||
|
|
@ -844,7 +841,7 @@ get_label_id:
|
|||
add_label:
|
||||
mov ecx,edx
|
||||
pop esi
|
||||
cmp byte [esi-1],0
|
||||
cmp byte [esi-2],0
|
||||
je label_name_ok
|
||||
mov al,[esi]
|
||||
cmp al,30h
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
; All rights reserved.
|
||||
|
||||
preprocessor:
|
||||
mov eax,[memory_start]
|
||||
mov [source_start],eax
|
||||
mov eax,[additional_memory]
|
||||
mov [free_additional_memory],eax
|
||||
mov [macros_list],eax
|
||||
|
|
@ -21,7 +19,7 @@ preprocessor:
|
|||
jc main_file_not_found
|
||||
cmp [macro_status],0
|
||||
jne unexpected_end_of_file
|
||||
mov [code_start],edi
|
||||
mov [source_start],edi
|
||||
ret
|
||||
|
||||
preprocess_file:
|
||||
|
|
@ -556,47 +554,69 @@ process_equ_constants:
|
|||
jmp process_after_replaced
|
||||
process_concatenations:
|
||||
xor dl,dl
|
||||
mov ebp,edi
|
||||
cmp word [esi],3Bh
|
||||
jne before_concatenations
|
||||
add esi,2
|
||||
before_concatenations:
|
||||
mov edi,esi
|
||||
lods byte [esi]
|
||||
cmp al,'#'
|
||||
je first_concatenation
|
||||
je concatenation
|
||||
cmp al,1Ah
|
||||
je symbol_before_concatenations
|
||||
cmp al,3Bh
|
||||
je symbol_before_concatenations
|
||||
xor dl,dl
|
||||
je no_more_concatenations
|
||||
cmp al,22h
|
||||
je string_before_concatenations
|
||||
xor dl,dl
|
||||
or al,al
|
||||
jnz before_concatenations
|
||||
mov edi,esi
|
||||
ret
|
||||
no_more_concatenations:
|
||||
mov edi,ebp
|
||||
ret
|
||||
symbol_before_concatenations:
|
||||
or dl,-1
|
||||
mov dl,1Ah
|
||||
mov ebx,esi
|
||||
lods byte [esi]
|
||||
movzx ecx,al
|
||||
add esi,ecx
|
||||
mov edi,esi
|
||||
jmp before_concatenations
|
||||
string_before_concatenations:
|
||||
mov dl,22h
|
||||
mov ebx,esi
|
||||
lods dword [esi]
|
||||
add esi,eax
|
||||
mov edi,esi
|
||||
jmp before_concatenations
|
||||
first_concatenation:
|
||||
or dl,dl
|
||||
jz before_concatenations
|
||||
concatenation:
|
||||
cmp dl,1Ah
|
||||
je symbol_concatenation
|
||||
cmp dl,22h
|
||||
je string_concatenation
|
||||
no_concatenation:
|
||||
cmp esi,edi
|
||||
je before_concatenations
|
||||
jmp after_concatenation
|
||||
symbol_concatenation:
|
||||
cmp byte [esi],1Ah
|
||||
jne before_concatenations
|
||||
do_concatenation:
|
||||
jne no_concatenation
|
||||
inc esi
|
||||
lods byte [esi]
|
||||
movzx ecx,al
|
||||
add [ebx],al
|
||||
jc name_too_long
|
||||
rep movs byte [edi],[esi]
|
||||
jmp after_concatenation
|
||||
string_concatenation:
|
||||
cmp byte [esi],22h
|
||||
jne no_concatenation
|
||||
inc esi
|
||||
lods dword [esi]
|
||||
mov ecx,eax
|
||||
add [ebx],eax
|
||||
rep movs byte [edi],[esi]
|
||||
after_concatenation:
|
||||
lods byte [esi]
|
||||
cmp al,'#'
|
||||
|
|
@ -604,14 +624,16 @@ process_concatenations:
|
|||
stos byte [edi]
|
||||
cmp al,1Ah
|
||||
je symbol_after_concatenation
|
||||
xor dl,dl
|
||||
cmp al,3Bh
|
||||
je no_more_concatenations
|
||||
cmp al,22h
|
||||
je string_after_concatenation
|
||||
xor dl,dl
|
||||
or al,al
|
||||
jnz after_concatenation
|
||||
ret
|
||||
symbol_after_concatenation:
|
||||
or dl,-1
|
||||
mov dl,1Ah
|
||||
mov ebx,edi
|
||||
lods byte [esi]
|
||||
stos byte [edi]
|
||||
|
|
@ -619,18 +641,13 @@ process_concatenations:
|
|||
rep movs byte [edi],[esi]
|
||||
jmp after_concatenation
|
||||
string_after_concatenation:
|
||||
mov dl,22h
|
||||
mov ebx,edi
|
||||
lods dword [esi]
|
||||
stos dword [edi]
|
||||
mov ecx,eax
|
||||
rep movs byte [edi],[esi]
|
||||
jmp after_concatenation
|
||||
concatenation:
|
||||
or dl,dl
|
||||
jz after_concatenation
|
||||
cmp byte [esi],1Ah
|
||||
jne after_concatenation
|
||||
jmp do_concatenation
|
||||
include_file:
|
||||
lods byte [esi]
|
||||
cmp al,22h
|
||||
|
|
@ -647,12 +664,21 @@ define_fix_constant:
|
|||
add esi,3
|
||||
push ebp esi
|
||||
call process_fix_constants
|
||||
pop ebx
|
||||
mov esi,[esp+4]
|
||||
movzx ecx,byte [esi-1]
|
||||
mov [value_type],1
|
||||
call find_symbolic_constant
|
||||
jc allocate_new_fix_constant
|
||||
mov ebx,edx
|
||||
jmp make_fix_constant
|
||||
allocate_new_fix_constant:
|
||||
mov edx,[labels_list]
|
||||
sub edx,16
|
||||
cmp edx,[free_additional_memory]
|
||||
jb out_of_memory
|
||||
mov [labels_list],edx
|
||||
make_fix_constant:
|
||||
pop ebx
|
||||
mov ecx,edi
|
||||
dec ecx
|
||||
sub ecx,ebx
|
||||
|
|
@ -695,8 +721,7 @@ restore_equ_constant:
|
|||
jne invalid_name
|
||||
movzx ecx,byte [esi]
|
||||
inc esi
|
||||
and [value_type],0F0h
|
||||
or [value_type],1
|
||||
mov [value_type],2
|
||||
call find_symbolic_constant
|
||||
jc no_symbolic_constant
|
||||
mov ecx,edx
|
||||
|
|
@ -707,7 +732,7 @@ restore_equ_constant:
|
|||
mov ebx,esi
|
||||
mov esi,edx
|
||||
xchg edi,edx
|
||||
add edi,16
|
||||
add edi,16-4
|
||||
sub esi,4
|
||||
std
|
||||
rep movs dword [edi],[esi]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
; flat assembler version 1.48
|
||||
; flat assembler version 1.49
|
||||
; Copyright (c) 1999-2003, Tomasz Grysztar.
|
||||
; All rights reserved.
|
||||
;
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
; cannot simply be copied and put under another distribution licence
|
||||
; (including the GNU Public Licence).
|
||||
|
||||
VERSION_STRING equ "1.48"
|
||||
VERSION_STRING equ "1.49"
|
||||
|
||||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 48
|
||||
VERSION_MINOR = 49
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
; Copyright (c) 1999-2003, Tomasz Grysztar.
|
||||
; All rights reserved.
|
||||
|
||||
format PE console on '..\DOS\fasm.com'
|
||||
format PE console
|
||||
|
||||
macro align value { rb (value-1) - (RVA $ + value-1) mod value }
|
||||
|
||||
|
|
@ -59,6 +59,7 @@ start:
|
|||
call assembler
|
||||
call formatter
|
||||
|
||||
call display_user_messages
|
||||
movzx eax,[current_pass]
|
||||
inc eax
|
||||
call display_number
|
||||
|
|
@ -151,7 +152,7 @@ current_locals_prefix dd ?
|
|||
labels_list dd ?
|
||||
label_hash dd ?
|
||||
org_origin dd ?
|
||||
org_sib dd ?
|
||||
org_registers dd ?
|
||||
org_start dd ?
|
||||
undefined_data_start dd ?
|
||||
undefined_data_end dd ?
|
||||
|
|
|
|||
|
|
@ -115,6 +115,8 @@ get_params:
|
|||
lodsb
|
||||
cmp al,20h
|
||||
je param_end
|
||||
cmp al,0Dh
|
||||
je param_end
|
||||
or al,al
|
||||
jz param_end
|
||||
jmp copy_param
|
||||
|
|
@ -125,6 +127,8 @@ get_params:
|
|||
lodsb
|
||||
cmp al,22h
|
||||
je string_param_end
|
||||
cmp al,0Dh
|
||||
je param_end
|
||||
or al,al
|
||||
jz param_end
|
||||
stosb
|
||||
|
|
@ -271,18 +275,6 @@ display_string:
|
|||
push ebp
|
||||
call [WriteFile]
|
||||
ret
|
||||
display_block:
|
||||
push ecx
|
||||
push STD_OUTPUT_HANDLE
|
||||
call [GetStdHandle]
|
||||
pop ecx
|
||||
push 0
|
||||
push bytes_count
|
||||
push ecx
|
||||
push esi
|
||||
push eax
|
||||
call [WriteFile]
|
||||
ret
|
||||
display_character:
|
||||
push ebx
|
||||
mov [character],dl
|
||||
|
|
@ -330,6 +322,55 @@ display_number:
|
|||
pop ebx
|
||||
ret
|
||||
|
||||
display_user_messages:
|
||||
mov [displayed_count],0
|
||||
call flush_display_buffer
|
||||
cmp [displayed_count],1
|
||||
jb line_break_ok
|
||||
je make_line_break
|
||||
mov ax,word [last_displayed]
|
||||
cmp ax,0A0Dh
|
||||
je line_break_ok
|
||||
cmp ax,0D0Ah
|
||||
je line_break_ok
|
||||
make_line_break:
|
||||
mov word [buffer],0A0Dh
|
||||
push STD_OUTPUT_HANDLE
|
||||
call [GetStdHandle]
|
||||
push 0
|
||||
push bytes_count
|
||||
push 2
|
||||
push buffer
|
||||
push eax
|
||||
call [WriteFile]
|
||||
line_break_ok:
|
||||
ret
|
||||
display_block:
|
||||
add [displayed_count],ecx
|
||||
cmp ecx,1
|
||||
ja take_last_two_characters
|
||||
jb block_displayed
|
||||
mov al,[last_displayed+1]
|
||||
mov ah,[esi]
|
||||
mov word [last_displayed],ax
|
||||
jmp block_ok
|
||||
take_last_two_characters:
|
||||
mov ax,[esi+ecx-2]
|
||||
mov word [last_displayed],ax
|
||||
block_ok:
|
||||
push ecx
|
||||
push STD_OUTPUT_HANDLE
|
||||
call [GetStdHandle]
|
||||
pop ecx
|
||||
push 0
|
||||
push bytes_count
|
||||
push ecx
|
||||
push esi
|
||||
push eax
|
||||
call [WriteFile]
|
||||
block_displayed:
|
||||
ret
|
||||
|
||||
fatal_error:
|
||||
mov esi,error_prefix
|
||||
call display_string
|
||||
|
|
@ -340,34 +381,44 @@ fatal_error:
|
|||
mov al,0FFh
|
||||
jmp exit_program
|
||||
assembler_error:
|
||||
call flush_display_buffer
|
||||
call display_user_messages
|
||||
push dword 0
|
||||
mov ebx,[current_line]
|
||||
find_error_home:
|
||||
get_error_lines:
|
||||
push ebx
|
||||
test byte [ebx+7],80h
|
||||
jz error_home_ok
|
||||
jz display_error_line
|
||||
mov edx,ebx
|
||||
find_definition_origin:
|
||||
mov edx,[edx+12]
|
||||
test byte [edx+7],80h
|
||||
jnz find_definition_origin
|
||||
push edx
|
||||
mov ebx,[ebx+8]
|
||||
jmp find_error_home
|
||||
error_home_ok:
|
||||
jmp get_error_lines
|
||||
display_error_line:
|
||||
mov esi,[ebx]
|
||||
call display_string
|
||||
mov esi,line_number_start
|
||||
call display_string
|
||||
mov eax,[ebx+4]
|
||||
and eax,7FFFFFFFh
|
||||
call display_number
|
||||
mov dl,']'
|
||||
call display_character
|
||||
cmp ebx,[current_line]
|
||||
pop esi
|
||||
cmp ebx,esi
|
||||
je line_number_ok
|
||||
mov dl,20h
|
||||
call display_character
|
||||
mov esi,[current_line]
|
||||
push esi
|
||||
mov esi,[esi]
|
||||
movzx ecx,byte [esi]
|
||||
inc esi
|
||||
call display_block
|
||||
mov esi,line_number_start
|
||||
call display_string
|
||||
mov esi,[current_line]
|
||||
pop esi
|
||||
mov eax,[esi+4]
|
||||
and eax,7FFFFFFFh
|
||||
call display_number
|
||||
|
|
@ -388,11 +439,14 @@ assembler_error:
|
|||
xor al,al
|
||||
call lseek
|
||||
mov ecx,[esp]
|
||||
mov edx,[memory_start]
|
||||
mov edx,[additional_memory]
|
||||
lea eax,[edx+ecx]
|
||||
cmp eax,[additional_memory_end]
|
||||
ja out_of_memory
|
||||
call read
|
||||
call close
|
||||
pop ecx
|
||||
mov esi,[memory_start]
|
||||
mov esi,[additional_memory]
|
||||
get_line_data:
|
||||
mov al,[esi]
|
||||
cmp al,0Ah
|
||||
|
|
@ -407,11 +461,14 @@ assembler_error:
|
|||
loop get_line_data
|
||||
display_line_data:
|
||||
mov ecx,esi
|
||||
mov esi,[memory_start]
|
||||
mov esi,[additional_memory]
|
||||
sub ecx,esi
|
||||
call display_block
|
||||
mov esi,cr_lf
|
||||
call display_string
|
||||
pop ebx
|
||||
or ebx,ebx
|
||||
jnz display_error_line
|
||||
mov esi,error_prefix
|
||||
call display_string
|
||||
pop esi
|
||||
|
|
@ -502,8 +559,10 @@ make_timestamp:
|
|||
add eax,ecx
|
||||
ret
|
||||
|
||||
character db ?,0
|
||||
character db ?
|
||||
bytes_count dd ?
|
||||
displayed_count dd ?
|
||||
last_displayed rb 2
|
||||
|
||||
error_prefix db 'error: ',0
|
||||
error_suffix db '.'
|
||||
|
|
|
|||
|
|
@ -111,11 +111,10 @@ basic_instruction:
|
|||
jmp instruction_assembled
|
||||
basic_mem_reg_16bit:
|
||||
call operand_16bit_prefix
|
||||
inc [base_code]
|
||||
call store_instruction
|
||||
jmp instruction_assembled
|
||||
jmp basic_mem_reg_store
|
||||
basic_mem_reg_32bit:
|
||||
call operand_32bit_prefix
|
||||
basic_mem_reg_store:
|
||||
inc [base_code]
|
||||
call store_instruction
|
||||
jmp instruction_assembled
|
||||
|
|
@ -232,11 +231,10 @@ basic_instruction:
|
|||
jmp instruction_assembled
|
||||
basic_reg_mem_16bit:
|
||||
call operand_16bit_prefix
|
||||
add [base_code],3
|
||||
call store_instruction
|
||||
jmp instruction_assembled
|
||||
jmp basic_reg_mem_store
|
||||
basic_reg_mem_32bit:
|
||||
call operand_32bit_prefix
|
||||
basic_reg_mem_store:
|
||||
add [base_code],3
|
||||
call store_instruction
|
||||
jmp instruction_assembled
|
||||
|
|
@ -410,11 +408,10 @@ single_operand_instruction:
|
|||
jmp instruction_assembled
|
||||
single_mem_16bit:
|
||||
call operand_16bit_prefix
|
||||
inc [base_code]
|
||||
call store_instruction
|
||||
jmp instruction_assembled
|
||||
jmp single_mem_store
|
||||
single_mem_32bit:
|
||||
call operand_32bit_prefix
|
||||
single_mem_store:
|
||||
inc [base_code]
|
||||
call store_instruction
|
||||
jmp instruction_assembled
|
||||
|
|
@ -686,7 +683,7 @@ mov_instruction:
|
|||
je mov_reg_creg
|
||||
cmp ah,7
|
||||
je mov_reg_dreg
|
||||
ja invalid_operand
|
||||
ja mov_reg_treg
|
||||
sub al,61h
|
||||
mov bl,[postbyte_register]
|
||||
shl al,3
|
||||
|
|
@ -698,19 +695,24 @@ mov_instruction:
|
|||
jne invalid_operand_size
|
||||
call operand_16bit_prefix
|
||||
jmp mov_reg_sreg_store
|
||||
mov_reg_sreg32:
|
||||
mov_reg_sreg32:
|
||||
call operand_32bit_prefix
|
||||
mov_reg_sreg_store:
|
||||
mov_reg_sreg_store:
|
||||
mov al,8Ch
|
||||
stos byte [edi]
|
||||
mov al,bl
|
||||
stos byte [edi]
|
||||
jmp instruction_assembled
|
||||
mov_reg_creg:
|
||||
mov bh,20h
|
||||
mov_reg_treg:
|
||||
cmp ah,11
|
||||
jne invalid_operand
|
||||
mov bh,24h
|
||||
jmp mov_reg_xrx
|
||||
mov_reg_dreg:
|
||||
mov bh,21h
|
||||
jmp mov_reg_xrx
|
||||
mov_reg_creg:
|
||||
mov bh,20h
|
||||
mov_reg_xrx:
|
||||
and al,111b
|
||||
mov bl,[postbyte_register]
|
||||
|
|
@ -858,7 +860,7 @@ mov_instruction:
|
|||
je mov_creg
|
||||
cmp ah,7
|
||||
je mov_dreg
|
||||
ja invalid_operand
|
||||
ja mov_treg
|
||||
sub al,61h
|
||||
mov [postbyte_register],al
|
||||
lods byte [esi]
|
||||
|
|
@ -919,11 +921,16 @@ mov_instruction:
|
|||
mov [base_code],8Eh
|
||||
call store_instruction
|
||||
jmp instruction_assembled
|
||||
mov_creg:
|
||||
mov dl,22h
|
||||
mov_treg:
|
||||
cmp ah,11
|
||||
jne invalid_operand
|
||||
mov dl,26h
|
||||
jmp mov_xrx
|
||||
mov_dreg:
|
||||
mov dl,23h
|
||||
jmp mov_xrx
|
||||
mov_creg:
|
||||
mov dl,22h
|
||||
mov_xrx:
|
||||
and al,111b
|
||||
mov bh,al
|
||||
|
|
@ -6353,9 +6360,13 @@ symbols:
|
|||
db 2,'ch',10h,15h
|
||||
db 2,'cl',10h,11h
|
||||
db 3,'cr0',10h,50h
|
||||
db 3,'cr1',10h,51h
|
||||
db 3,'cr2',10h,52h
|
||||
db 3,'cr3',10h,53h
|
||||
db 3,'cr4',10h,54h
|
||||
db 3,'cr5',10h,55h
|
||||
db 3,'cr6',10h,56h
|
||||
db 3,'cr7',10h,57h
|
||||
db 2,'cs',10h,62h
|
||||
db 2,'cx',10h,21h
|
||||
db 2,'dh',10h,16h
|
||||
|
|
@ -6366,6 +6377,7 @@ symbols:
|
|||
db 3,'dr1',10h,71h
|
||||
db 3,'dr2',10h,72h
|
||||
db 3,'dr3',10h,73h
|
||||
db 3,'dr4',10h,74h
|
||||
db 3,'dr5',10h,75h
|
||||
db 3,'dr6',10h,76h
|
||||
db 3,'dr7',10h,77h
|
||||
|
|
@ -6408,6 +6420,14 @@ symbols:
|
|||
db 3,'st5',10h,0A5h
|
||||
db 3,'st6',10h,0A6h
|
||||
db 3,'st7',10h,0A7h
|
||||
db 3,'tr0',10h,0B0h
|
||||
db 3,'tr1',10h,0B1h
|
||||
db 3,'tr2',10h,0B2h
|
||||
db 3,'tr3',10h,0B3h
|
||||
db 3,'tr4',10h,0B4h
|
||||
db 3,'tr5',10h,0B5h
|
||||
db 3,'tr6',10h,0B6h
|
||||
db 3,'tr7',10h,0B7h
|
||||
db 5,'tword',11h,0Ah
|
||||
db 5,'use16',13h,10h
|
||||
db 5,'use32',13h,20h
|
||||
|
|
|
|||
|
|
@ -1,6 +1,15 @@
|
|||
|
||||
Visit http://flatassembler.net/ for more information
|
||||
|
||||
version 1.49
|
||||
[16-09-2003]
|
||||
------------
|
||||
[+] better error information for macro-generated lines
|
||||
[+] support for test registers
|
||||
[+] fix constant redefinition improved for speed
|
||||
[+] some improvements for PE formatter
|
||||
[-] several small fixes
|
||||
|
||||
version 1.48
|
||||
[24-07-2003]
|
||||
------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue