flat assembler
Message board for the users of flat assembler.
Index
> Windows > FASM "TEMPLATE.ASM" questions :? |
Author |
|
vbVeryBeginner 22 Aug 2004, 16:00
hi,
i am back again with some questions regarding the example file, "TEMPLATE.ASM" provided by FASM inside the FASMW version. i created the lite version of it, below is the code Code: ; template for program using standard Win32 headers format PE GUI 4.0 entry start include '%fasminc%\win32a.inc' section '.data' data readable writeable _title db 'Win32 program template',0 _class db 'FASMWIN32',0 mainhwnd dd ? hinstance dd ? msg MSG wc WNDCLASS section '.code' code readable executable start: invoke LoadCursor,0,IDC_ARROW mov [wc.hCursor],eax ;will see hourglass (busy) ;cursor if this line is clear ;some delay perhaps mov [wc.lpfnWndProc],WindowProc mov [wc.lpszClassName],_class mov [wc.hbrBackground],COLOR_BTNFACE+1 ;will see transparent window ;if this line is clear invoke RegisterClass,wc invoke CreateWindowEx,\ 0,\ _class,\ _title,\ WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,\ 128,128,\ 192,192,\ NULL,\ NULL,\ [hinstance],\ NULL mov [mainhwnd],eax msg_loop: invoke GetMessage,msg,NULL,0,0 or eax,eax jz end_loop invoke TranslateMessage,msg invoke DispatchMessage,msg jmp msg_loop end_loop: invoke ExitProcess,[msg.wParam] proc WindowProc, hwnd,wmsg,wparam,lparam cmp [wmsg],WM_DESTROY je wmdestroy defwndproc: invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] jmp finish wmdestroy: invoke PostQuitMessage,0 finish: return endp section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ ExitProcess, 'ExitProcess' import user,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ TranslateMessage, 'TranslateMessage',\ DispatchMessage, 'DispatchMessageA',\ LoadCursor, 'LoadCursorA',\ PostQuitMessage, 'PostQuitMessage' the questions are : 1. do we really need to INVOKE GetModuleHandle? coz lite version could run without it, if we should INVOKE it, i wish somebody could please tell me why and why not to INVOKE it too? Code: ;2. why we need to push ebx esi edi ;in the actual "template.asm" -> proc WindowProc,hwnd,wmsg,wparam,lparam ;and pop them off in the finish: 3. if we use C language to create win32 application, we would run the WinMain function like below, Code: int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) how could we access to the hInstance, hPrevInstance, lpszCmdLine and nCmdShow in Win32 ASM mode? sincerely, vbVeryBeginner (:-|)>-|--< http://sulaiman.thefreebizhost.com |
|||
22 Aug 2004, 16:00 |
|
vbVeryBeginner 22 Aug 2004, 17:40
Quote:
so, does it mean that, if i didn't invoke GetModule, my application would NOT run? or execute? Quote:
what is the use of those values pushed into ebx,esi and edi there? where are that values from? Quote:
if GetModuleHandle for hInstance, how about hPrevInstance, lpszCmdLine and nCmdShow? sincerely, vbVeryBeginner |
|||
22 Aug 2004, 17:40 |
|
vid 22 Aug 2004, 17:53
2. it's calling standard, caller awaits to have those values preserved. It is same when you call some API procedure, you await it won't change value of this registers.
|
|||
22 Aug 2004, 17:53 |
|
decard 22 Aug 2004, 18:54
you call GetCommandLine to obtain lpszCmdLine, hPrevInstance is always NULL, and usually you don't have to care about nCmdShow. Open win32.hlp, and find "WinMain" in index, if you wan't more details.
|
|||
22 Aug 2004, 18:54 |
|
coconut 22 Aug 2004, 19:44
thought window couldnt be created without [hinstance], but his "lite" example works
|
|||
22 Aug 2004, 19:44 |
|
pelaillo 22 Aug 2004, 22:04
GetModuleHandle will always return the same address value (0400000h) because is the start of the virtual address space assigned by windows loader for a running application.
As this could change in future versions of windows, it is a good practice to call GetModuleHandle however and use the returned value. |
|||
22 Aug 2004, 22:04 |
|
vbVeryBeginner 23 Aug 2004, 03:11
to:decard,
sorry for that trouble, i miss look those information in my PSDK ;(, i did scroll that WinMain page before posting... but i guess, i might scroll it too fast :p to: pelaillo, Quote:
according to the PSDK : Code: HMODULE GetModuleHandle( LPCTSTR lpModuleName // module name ); If this parameter (lpModuleName) is NULL, GetModuleHandle returns a handle to the file used to create the calling process. i wish if you could verify that do you mean, when the supplied value for lpModuleName is NULL, the return value will be always (0400000h)? to : vid or anyone does this mean, the proc WindowProc, hwnd,wmsg,wparam,lparam will modify the value of ebx esi edi? if yes, i got a reason to push them there if no, i really wonder why to push them there? sincerely, vbVeryBeginner d(0 >> ***)b |
|||
23 Aug 2004, 03:11 |
|
ShortCoder 23 Aug 2004, 19:11
You save ebx esi and edi because, whenever Windows gains control from your application, it can change the values in any of those without necessarily saving them and restoring them for you.
_________________ Boycott Symantec/Norton/PowerQuest whenever possible |
|||
23 Aug 2004, 19:11 |
|
vid 23 Aug 2004, 19:55
Window procedure CAN'T modify (or more exact - must preserve) value of these 3 registers, so you have reson to push them if you are using it. If you aren't, all API calls will preserve them too, so they will stay preserved. But it is nice to preserve them always, you can prevent some ugly bug with this.
|
|||
23 Aug 2004, 19:55 |
|
vbVeryBeginner 24 Aug 2004, 04:39
ic,
anyway, vid, do you mean that "push ebx esi edi" and pop them off later in the end of WindowProc has becoming so common (a tradition for win32 asm guys) that now already emerges as a "Standard" when you wrote in message #4 Quote:
i wish if you could verify my understanding, does this mean, in win32 ASM world, the WINAPI will ONLY modify the EAX register? and if it(winapi) need to uses the ebx,esi,or edi, it will push them first and pop them off later? does the WINAPI or Windows use the "ebx esi edi"? and what are those registers function as in win32 operating system? sincerely, vbVeryBeginner d(..>)b thanks in advance |
|||
24 Aug 2004, 04:39 |
|
proveren 24 Aug 2004, 09:52
vb, you really should read a decent ASM and Win32ASM tutorial. Sure you can learn from forums, but some questions are TOO basic. Besides ebx, edi, and esi there is not only eax. Yes, the push ebx esi edi is so common that some functions take it as granted so use this push and pop to avoid some bugs.
|
|||
24 Aug 2004, 09:52 |
|
vid 24 Aug 2004, 10:27
Quote:
no it didn't become "standard" by usage. It is defined as standard by microsoft, and not doing this will almost surely cause bug. Window procedure or WINAPI procedure just must preserve them. Quote:
yes, and it also can modify ecx and edx freely. Quote: does the WINAPI or Windows use the "ebx esi edi"? and what are those registers function as in win32 operating system? it uses them, and there is no special function of them in windows. Only special thing about them is that they have to stay preserved after calling procedure, so you can keep values in them between calls of winapi procedures. |
|||
24 Aug 2004, 10:27 |
|
vbVeryBeginner 24 Aug 2004, 14:06
thanks vid,
that really helps Quote:
if that is really what you could see from my post, i have nothing to say :< |
|||
24 Aug 2004, 14:06 |
|
proveren 28 Aug 2004, 07:25
OK, sorry, vb!
(offtopic) You have quite and interesting web site. |
|||
28 Aug 2004, 07:25 |
|
vbVeryBeginner 28 Aug 2004, 07:56
sorry too,
i didn't mean to offend :p so, let us shake our hand and yell, FASM horray! lol |
|||
28 Aug 2004, 07:56 |
|
proveren 28 Aug 2004, 09:16
"FASM - make friends globally!"
|
|||
28 Aug 2004, 09:16 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.