Assembly MASM32 push and pop



这是我在网上找到的一个基本的win32程序。到目前为止,我得到了所有内容,但我没有得到的是这两行:

push  hInstance
pop   wc.hInstance

谁能给我解释一下他们是做什么的,如果有另一种方法来做他们使用另一个指令所做的事情。

我试着使用谷歌和其他文档,他们很好地解释了pushpop指令的作用,但是我不能把我对它们的理解放在这个程序的上下文中。

.386
.model flat,stdcall
option casemap:none
include masm32includewindows.inc
include masm32includeuser32.inc
includelib masm32libuser32.lib            ; calls to functions in user32.lib and kernel32.lib
include masm32includekernel32.inc
includelib masm32libkernel32.lib
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
.DATA                     ; initialized data
ClassName db "SimpleWinClass",0        ; the name of our window class
AppName db "Our First Window",0        ; the name of our window
.DATA?                ; Uninitialized data
hInstance HINSTANCE ?        ; Instance handle of our program
CommandLine LPSTR ?
.CODE                ; Here begins our code
start:
invoke GetModuleHandle, NULL            ; get the instance handle of our program.
 ; Under Win32, hmodule==hinstance mov hInstance,eax
mov hInstance,eax
invoke GetCommandLine                        ; get the command line. You don't have to call this function IF
 ; your program doesn't process the command line.
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT        ; call the main function
invoke ExitProcess, eax                           ; quit our program. The exit code is returned in eax from WinMain.
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX                                            ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND
mov   wc.cbSize,SIZEOF WNDCLASSEX                   ; fill values in members of wc
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,NULL
mov   wc.cbWndExtra,NULL
push  hInstance
pop   wc.hInstance
mov   wc.hbrBackground,COLOR_WINDOW+1
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax
invoke RegisterClassEx, addr wc                       ; register our window class
invoke CreateWindowEx,NULL,
ADDR ClassName,
ADDR AppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,
NULL
mov   hwnd,eax
invoke ShowWindow, hwnd,CmdShow               ; display our window on desktop
invoke UpdateWindow, hwnd                                 ; refresh the client area
.WHILE TRUE                                                         ; Enter message loop
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov     eax,msg.wParam                                            ; return exit code in eax
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY                           ; if the user closes our window
invoke PostQuitMessage,NULL             ; quit our application
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam     ; Default message processing
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start

它将hInstance压入堆栈,然后将其弹出到wc.hInstance的内存位置。
程序员也可以这样写:

mov  eax, hInstance
mov  wc.hInstance, eax

如果他们知道他们不需要保存EAX。

最新更新