📄 sol_fasm.asm
字号:
;---------------------------------------------------
; flat assembler interface for Win32
; Copyright (c) 1999-2006, Tomasz Grysztar.
; All rights reserved.
;----------------------------------------------------
;------------------------------------------------
; FASM port to Solar_OS
; copyright (c) 2007 by Bogdan Valentin Ontanu
; All rights reserved.
;------------------------------------------------
format PE console
;-------------------------
; Create SOL Main window
;-------------------------
start:
call Create_Main_Window
xor eax,eax
ret
;---------------------------------------------
; This will be invoked on "compile" button
;---------------------------------------------
start_fasm:
mov esi,_logo
call display_string
call get_params
jc information
call init_memory
mov esi,_memory_prefix
call display_string
mov eax,[memory_end]
sub eax,[memory_start]
add eax,[additional_memory_end]
sub eax,[additional_memory]
shr eax,10
call display_number
mov esi,_memory_suffix
call display_string
;call [GetTickCount]
mov eax,1122
mov [start_time],eax
call preprocessor
call parser
call assembler
call formatter
call display_user_messages
movzx eax,[current_pass]
inc eax
call display_number
mov esi,_passes_suffix
call display_string
; call [GetTickCount]
mov eax,3344
sub eax,[start_time]
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
information:
mov esi,_usage
call display_string
mov al,1
jmp exit_program
get_params:
mov [memory_setting],0
mov [passes_limit],100
call get_cmd_line
mov esi,eax
mov edi,params
find_command_start:
lodsb
cmp al,20h
je find_command_start
cmp al,22h
je skip_quoted_name
skip_name:
lodsb
cmp al,20h
je find_param
or al,al
jz all_params
jmp skip_name
skip_quoted_name:
lodsb
cmp al,22h
je find_param
or al,al
jz all_params
jmp skip_quoted_name
find_param:
lodsb
cmp al,20h
je find_param
cmp al,22h
je string_param
cmp al,'-'
je option_param
cmp al,0Dh
je all_params
or al,al
jz all_params
inc edi
mov ebx,edi
copy_param:
stosb
lodsb
cmp al,20h
je param_end
cmp al,0Dh
je param_end
or al,al
jz param_end
jmp copy_param
string_param:
inc edi
mov ebx,edi
copy_string_param:
lodsb
cmp al,22h
je string_param_end
cmp al,0Dh
je param_end
or al,al
jz param_end
stosb
jmp copy_string_param
option_param:
lodsb
cmp al,'m'
je memory_option
cmp al,'M'
je memory_option
cmp al,'p'
je passes_option
cmp al,'P'
je passes_option
bad_params:
stc
ret
get_option_value:
xor eax,eax
mov edx,eax
get_option_digit:
lodsb
cmp al,20h
je option_value_ok
cmp al,0Dh
je option_value_ok
or al,al
jz option_value_ok
sub al,30h
jc invalid_option_value
cmp al,9
ja invalid_option_value
imul edx,10
jo invalid_option_value
add edx,eax
jc invalid_option_value
jmp get_option_digit
option_value_ok:
dec esi
clc
ret
invalid_option_value:
stc
ret
memory_option:
lodsb
cmp al,20h
je memory_option
cmp al,0Dh
je bad_params
or al,al
jz bad_params
dec esi
call get_option_value
or edx,edx
jz bad_params
cmp edx,1 shl (32-10)
jae bad_params
mov [memory_setting],edx
jmp find_param
passes_option:
lodsb
cmp al,20h
je passes_option
cmp al,0Dh
je bad_params
or al,al
jz bad_params
dec esi
call get_option_value
or edx,edx
jz bad_params
cmp edx,10000h
ja bad_params
mov [passes_limit],dx
jmp find_param
param_end:
dec esi
string_param_end:
xor al,al
stosb
mov eax,edi
sub eax,ebx
mov [ebx-1],al
jmp find_param
all_params:
xor al,al
stosb
cmp [params],0
je bad_params
lea eax,[params+1]
mov [input_file],eax
mov [output_file],0
movzx ecx,byte [eax-1]
add eax,ecx
cmp byte [eax],0
je params_ok
inc eax
mov [output_file],eax
movzx ecx,byte [eax-1]
add eax,ecx
cmp byte [eax],0
jne bad_params
params_ok:
clc
ret
include 'sol_system.inc'
include '..\version.inc'
_copyright db 'Copyright (c) 1999-2005, Tomasz Grysztar',0Dh,0Ah,0
_logo db 'flat assembler version ',VERSION_STRING,0
_usage db 0Dh,0Ah
db 'usage: fasm <source> [output]',0Dh,0Ah
db 'optional settings:',0Dh,0Ah
db ' -m <limit> set the limit in kilobytes for the memory available to assembler',0Dh,0Ah
db ' -p <limit> set the maximum allowed number of passes',0D,0Ah
db 0
_memory_prefix db ' (',0
_memory_suffix db ' kilobytes memory)',0Dh,0Ah,0
_passes_suffix db ' passes, ',0
_seconds_suffix db ' seconds, ',0
_bytes_suffix db ' bytes.',0Dh,0Ah,0
include '..\errors.inc'
include '..\expressi.inc'
include '..\preproce.inc'
include '..\parser.inc'
include '..\assemble.inc'
include '..\formats.inc'
include '..\x86_64.inc'
include '..\tables.inc'
align 4
include '..\variable.inc'
memory_setting dd ?
start_time dd ?
params rb 1000h
buffer rb 4000h
stack 10000h
section '.idata' import data readable writeable
dd 0,0,0,rva sol_dll_name, rva sol_iat_table
dd 0,0,0,0,0
sol_iat_table:
API_Debug_Out_String dd rva _api_debug_out_string
API_File_Open dd rva _api_file_open
API_File_Close dd rva _api_file_close
API_File_Read dd rva _api_file_read
API_File_Get_Size dd rva _api_file_get_size
API_Memory_Allocate dd rva _api_memory_allocate
API_Memory_Release dd rva _api_memory_release
API_Text_Draw dd rva _api_text_draw
API_Window_Create dd rva _api_window_create
API_Window_Set_Caption dd rva _api_window_set_caption
API_Window_Set_Callback dd rva _api_window_set_callback
API_Window_Get_Caption dd rva _api_window_get_caption
API_Window_Get_Addr dd rva _api_window_get_addr
App_View_Memory_Init dd rva _app_view_memory_init
App_View_Pe_Init dd rva _app_view_pe_init
App_View_Text_Init dd rva _app_view_text_init
; end of IAT imports
dd 0
; DLL Name
sol_dll_name db "sol_os_coff.dll",0
; Import function names
_api_debug_out_string db 0,0,"API_Debug_Out_String",0
_api_file_open db 0,0,"API_File_Open",0
_api_file_close db 0,0,"API_File_Close",0
_api_file_read db 0,0,"API_File_Read",0
_api_file_get_size db 0,0,"API_File_Get_Size",0
_api_memory_allocate db 0,0,"API_Memory_Allocate",0
_api_memory_release db 0,0,"API_Memory_Release",0
_api_text_draw db 0,0,"API_Text_Draw",0
_api_window_create db 0,0,"API_Window_Create",0
_api_window_set_caption db 0,0,"API_Window_Set_Caption",0
_api_window_set_callback db 0,0,"API_Window_Set_Callback",0
_api_window_get_caption db 0,0,"API_Window_Get_Caption",0
_api_window_get_addr db 0,0,"API_Window_Get_Addr",0
; funny: importing full applications as an API ;)
_app_view_memory_init db 0,0,"App_View_Memory_Init",0
_app_view_pe_init db 0,0,"App_View_Pe_Init",0
_app_view_text_init db 0,0,"App_View_Text_Init",0
section '.reloc' fixups data readable discardable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -