flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
hopcode 20 Jun 2009, 11:10
Hallo,pstarczewski
on http://flatassembler.net/examples.php or compile the examples in the EXAMPLE directory of your fasm dwonloaded package First af all, 1) set up path for fasm compiler in a batch file/win environment, or at the prompt as follows (i have fasm.exe on J:\fasm) path=%path%;J:\fasm 2) set up include directory in a batch file/win environment, or at the prompt as follows (i use %fasminc%" as veriable name ) set fasminc=J:\fasm\include Now, i will try to do my best for a Console standard app: 3) include main macros and standard includes in your code Code: format PE CONSOLE 4.0 entry start include '%fasminc%\win32a.inc' 4) global data go in a data section Code: section ".data" data readable writeable szGlobalString db "Hello World", 13,10,0 szPause db "pause",0 szMessage db "In the subroutine local dword is=%x",13,10,0 5)your code goes in the .code section Code: section ".code" code readable executable start: cinvoke printf,szGlobalString cinvoke system,szPause ret 6) if you have sub-routines declare it as follows in this model Code: proc myroutine _arg1dword local .onstack_dword:DWORD mov eax,[.onstack_dword] add eax,[_arg1dword] cinvoke printf,szMessage,eax ret endp 7) all the function you use must be imported in an import section called .idata Code:
section '.idata' import data readable writeable
8 ) enable importing function from MSVCRT.DLL Code: library msvcrt,"MSVCRT.DLL" 9) import explicitly function one by one,not omitting alias Code: ;NOTE this functions use cinvoke convention import msvcrt,\ printf,"printf",\ _getch,"_getch",\ system,"system" All together Code: format PE CONSOLE 4.0 entry start include '%fasminc%\win32a.inc' section ".data" data readable writeable szGlobalString db "Hello World", 13,10,0 szPause db "pause",0 szMessage db "In the subroutine local dword is (hexadecimal) %x",13,10,0 szMessage1 db "You have passed (hexadecimal) %x as argument",13,10,0 szMessage2 db "In the subroutine sum of local+passed arg is (hexadecimal) %x",13,10,0 section ".code" code readable executable start: cinvoke printf,szGlobalString push 12345h ; this goes in _arg1dword call myroutine cinvoke system,szPause ret proc myroutine _arg1dword local .onstack_dword:DWORD cinvoke printf,szMessage1,[_arg1dword] ; assign an arbitary value to .onstack_dword mov [.onstack_dword],56789h cinvoke printf,szMessage,[.onstack_dword] mov eax,[.onstack_dword] add eax,[_arg1dword] cinvoke printf,szMessage2,eax ret endp section '.idata' import data readable writeable library msvcrt,"MSVCRT.DLL" import msvcrt,\ printf,"printf",\ _getch,"_getch",\ system,"system" NOTE: for Windowing Example you need tutorials from Iczelion (MASM, but i cannot find at the moment the translation for Fasm, here on board ) or try CreateWindowEx in search box on board. NOTE2: study the use of "proc" (it is a macro) and the difference of "struc" and "struct", searching them on FAQ or on searchbox Ok, this is a PE console app (PE CONSOLE) using only the printf/and system function Try to compile it. Hope it is useful and... happy fasming. ![]() Regards, hopcode |
|||
![]() |
|
pstarczewski 20 Jun 2009, 23:21
Thanks hopcode,
Looks very interesting. I did look at those examples and they look like a good start for me - total beginner at asm. Thanks for your help. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.