Paxi Posted October 28, 2010 Posted October 28, 2010 Hey guys, I am new here and just started into learning Assembler. First of all I have to say this Forum really rocks! I already found tons of information I´m interested in and I´m really impressed by the skills of some members here..Well I started working myself through Iczelion´s famous Win32 Asm Tuts at the beginning of this week after i got some basic information from the Book: The Art of Assembly Language I ordered a time ago.The question belongs to Tut3 I just finished working on.There is the WinMain proc, where 4 arguments are passed in the function parameter list. My question belongs to the first parameter, the instance handler from type HINSTANCE.In the .DATA? section we defined a global variable hInstance from type HINSTANCE. Than we move the return value from GetModuleHanlde inside and pass it to the WinMain proc afterwords..DATA?hInstance HINSTANCE ? ...invoke GetModuleHandle, NULLmov hInstance, eax ..invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULTThere is my first question, why do we have to pass it to the WinMain Proc since it´s globally defined? Couldn´t we just define the WinMain PROTO WinMain proto :DWORD,:DWORD,:DWORD instead of WinMain proto :DWORD,:DWORD,:DWORD,:DWORD and do not pass it to the WinMain Proc?Well afterwards in WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,FirstWindowState:DWORDpush hInstancepop wc.hInstanceWe passed it to the WinProc before, so why do we have to push the global variable hInstance on the stack now and pop it to wc.hInstance and can´t just mov the one passed in like mov wc.hInstance, hInst? I tried it but got the error "invalid instruction operands afterwards".Thanks it advance guys, probably there are some more questions to come since i only programmed in C and Java so far..^^And sorry if there is any missspelling or wrong grammar. Englisch isn´t my mothers tongue
Hyperlisk Posted October 28, 2010 Posted October 28, 2010 There is my first question, why do we have to pass it to the WinMain Proc since it´s globally defined? Couldn´t we just define the WinMain PROTO WinMain proto :DWORD,:DWORD,:DWORD instead of WinMain proto :DWORD,:DWORD,:DWORD,:DWORD and do not pass it to the WinMain Proc?You could do it like that, he probably demonstrated how he did becaue that is the common WinMain signature.Well afterwards in WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,FirstWindowState:DWORDpush hInstancepop wc.hInstanceWe passed it to the WinProc before, so why do we have to push the global variable hInstance on the stack now and pop it to wc.hInstance and can´t just mov the one passed in like mov wc.hInstance, hInst? I tried it but got the error "invalid instruction operands afterwards".You had to do that because there is not a mov [mem], [mem] intruction.
hezz Posted October 28, 2010 Posted October 28, 2010 (edited) Couldn´t we just define the WinMain PROTO WinMain proto :DWORD,:DWORD,:DWORD instead of WinMain proto :DWORD,:DWORD,:DWORD,:DWORD and do not pass it to the WinMain Proc? The WinMain-Proc is defined like this in the Win32-Api: int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window ); If you haven't already, you should download the Win32.hlp or the MS Platform SDK. It will help you a lot while programming Windows Apps. We passed it to the WinProc before, so why do we have to push the global variable hInstance on the stack now and pop it to wc.hInstance and can´t just mov the one passed in like mov wc.hInstance, hInst ? I tried it but got the error "invalid instruction operands afterwards". The mov-instruction doesn't support two Memory-Operands. For a full list of the X86-Opcodes and their Operands look here: http://ref.x86asm.net/coder32.html Edit: Sry, didn't saw that Hyperlisk already replied Edited October 28, 2010 by hezz
Ufo-Pu55y Posted October 28, 2010 Posted October 28, 2010 We passed it to the WinProc before, so why do we have to push the global variable hInstance on the stack now and pop it to wc.hInstance and can´t just mov the one passed inyou could push the argument 'hInst' as well. the global var 'hInstance' is just kept like a good habit in that example, as it often has to be used again for other WinAPI funcs later on in the code
What Posted October 29, 2010 Posted October 29, 2010 ...push hInstancepop wc.hInstance...mov wc.hInstance, hInstMasm32 comes with a macro include file '\masm32\macros\macros.asm'. Add this file in your project and you will be able to use useful macros like m2m which basically does the push pop or mrm which uses the eax to move memory.mrm wc.hInstance, hInst == (mov eax, hInst; mov wc.hInstance, eax)m2m wc.hInstance, hInst == (push hInst; pop wc.hInstance)
Paxi Posted October 29, 2010 Author Posted October 29, 2010 Thanks for the input guys! I already downloaded the win32.hlp file and i will have a look at the masm macros too. I should had a better look at the mov instruction before, that there is no mov mem mem instruction but now i get it.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now