hi,

im trying to write hello world program in fasm

here is what i got, but it doesnt work:(



format PE GUI 4.0
entry start

include 'include\kernel.inc'
include 'include\user.inc'

include 'include\macro\stdcall.inc'
include 'include\macro\import.inc'


section '.data' data readable writeable

hConsoleOutput dd 0 ; handle to console
strHelloWorld db 'Hello World',10,0

section '.code' code readable executable

start:
invoke AllocConsole

invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [hConsoleOutput],eax
invoke lstrlen, strHelloWorld
invoke WriteConsole,hConsoleOutput,strHelloWorld,eax,0,0

msg_loop:
invoke GetAsyncKeyState,VK_ESCAPE
test eax,eax
jnz end_loop
jmp msg_loop

end_loop:

invoke FreeConsole

invoke ExitProcess,0

section '.idata' import data readable writeable

library kernel,'KERNEL32.DLL',\
user,'USER32.DLL'

kernel:
import AllocConsole,'AllocConsole',\
GetStdHandle,'GetStdHandle',\
lstrlen,'lstrlenA',\
WriteConsole,'WriteConsoleA',\
FreeConsole,'FreeConsole',\
ExitProcess,'ExitProcess'

user:
import GetAsyncKeyState,'GetAsyncKeyState'


P.S. how to debug asm programs ?
Posted on 2002-07-16 20:41:38 by pahan
Since I too, had just started coding using FASM. Please be nice :grin:


format PE CONSOLE 4.0
entry start

include '\fasm\EXAMPLES\WIN32\INCLUDE\kernel.inc'
include '\fasm\EXAMPLES\WIN32\INCLUDE\user.inc'
include '\fasm\EXAMPLES\WIN32\INCLUDE\macro\stdcall.inc'
include '\fasm\EXAMPLES\WIN32\INCLUDE\macro\import.inc'

section '.data' readable writeable

g_dbText DB 'Hello Cruel World', 0
g_dwByteWrtn DD ?

section '.code' readable writeable

start:

invoke GetStdHandle, STD_OUTPUT_HANDLE
invoke WriteFile, eax, g_dbText, 17, g_dwByteWrtn, NULL
invoke ExitProcess, NULL

section '.idata' import data readable writeable

library kernel,'KERNEL32.DLL'

kernel:
import GetStdHandle, 'GetStdHandle', \
WriteFile, 'WriteFile', \
ExitProcess, 'ExitProcess'
This one is the basic Hello Cruel World Console. :grin:

::edit::

Does FASM have a SIZEOF/LENGTHOF ??? Can't seem to find it.
Posted on 2002-07-17 00:18:49 by stryker



Does FASM have a SIZEOF/LENGTHOF ??? Can't seem to find it.



Look at the include files:



struc WNDCLASSEX
{
.cbSize dd ?
.style dd ?
.lpfnWndProc dd ?
.cbClsExtra dd ?
.cbWndExtra dd ?
.hInstance dd ?
.hIcon dd ?
.hCursor dd ?
.hbrBackground dd ?
.lpszMenuName dd ?
.lpszClassName dd ?
.hIconSm dd ?
[b] .size = $-.cbSize[/b]
}


Don't think there is one if Thomasz uses that way for calculating the size :/
Posted on 2002-07-17 02:00:52 by bazik
How weird... Anyway, I was asking because I don't want to count the characters in a string.


format PE CONSOLE 4.0
entry start

include '\fasm\EXAMPLES\WIN32\INCLUDE\kernel.inc'
include '\fasm\EXAMPLES\WIN32\INCLUDE\user.inc'
include '\fasm\EXAMPLES\WIN32\INCLUDE\macro\stdcall.inc'
include '\fasm\EXAMPLES\WIN32\INCLUDE\macro\import.inc'

section '.data' readable writeable

g_dbText DB 'Hello Cruel World', 0
g_szText = $-g_dbText
g_dwByteWrtn DD ?

section '.code' readable writeable

start:

invoke GetStdHandle, STD_OUTPUT_HANDLE
invoke WriteFile, eax, g_dbText, g_szText, g_dwByteWrtn, NULL
invoke ExitProcess, NULL

section '.idata' import data readable writeable

library kernel,'KERNEL32.DLL'

kernel:
import GetStdHandle, 'GetStdHandle', \
WriteFile, 'WriteFile', \
ExitProcess, 'ExitProcess'
Thanks for the info!!!
Posted on 2002-07-17 02:10:27 by stryker
I found the problem in my program :)

insted of

invoke WriteConsole,hConsoleOutput,strHelloWorld,eax,0,0

i needed to put

invoke WriteConsole,,strHelloWorld,eax,0,0

Thanks for responses :alright:
Posted on 2002-07-17 02:23:42 by pahan
How weird... Anyway, I was asking because I don't want to count the characters in a string.


but isn't it possible to use "lstrlen" or even the string commands to do the job in FASM?

cya
Posted on 2002-07-17 12:05:30 by NOP-erator
lstrlen counts the length of a string during runtime, this isn't practical if the string is already known like the one I declared on the data section. I only use lstrlen if the string is unknown in size. While SIZEOF/LENGTHOF in MASM/TASM are performed during assembly time. Thus saving time, space, cycle counts...

You don't need lstrlen to give the string count, SIZEOF/LENGTHOF can just place an immediate value right then and there.
Posted on 2002-07-17 12:09:45 by stryker
The interesting solution is to redefine the
labeled variant of DB directive using the struc macro:


struc DB [data]
{ common .start db data
.size = $ - .start }


Now with the following definition:


g_dbText DB 'Hello Cruel World'

g_dbText is the label for data and g_dbText.size is the size of that data.
Posted on 2002-07-17 14:38:58 by Tomasz Grysztar
Wow, I never knew it's that flexible. :alright: Thanks!!!
Posted on 2002-07-17 14:44:41 by stryker