News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

POP EBP within FRAME

Started by LL, October 10, 2005, 10:56:51 PM

Previous topic - Next topic

LL

Hi all,

I adapted Iczelion's tut03 to work with Goasm and Golink.  To do so, I had to use FRAME and ENDF.  Which adds a POP EBP before it does a RET.  The window didn't work because of this extra POP on the stack. I added, just after the POP, PUSH EBP.  The window then work properly.  Why this extra POP EBP within FRAME/ENDF ?  Quite new with win32 assembly and Goasm/Golink !

LL

Infro_X

It'd help to know what you are talking about if we could have a look at what you changed.

LL

Here is what I wrote,

Data section
ClassName db "SimpleWinClass",0
AppName  db "Iczelion's First Window fut modifié par Leonard",0

hInstance DD   0
CommandLine DD   0

Code section
start:
   PUSH   0
   CALL   GetModuleHandleA   ;invoke GetModuleHandle, NULL
   MOV   [hInstance],EAX      ;mov    hInstance,eax
   CALL   GetCommandLineA      ;invoke GetCommandLine   
   MOV   [CommandLine],EAX   ;mov    CommandLine,eax   
   PUSH   10D         ;10D = SW_SHOWDEFAULT   
   PUSH   [CommandLine]      ;CommandLine
   PUSH   0         ;NULL
   PUSH   [hInstance]      ;hInstance
   CALL   WinMain         ;invoke WinMain
   PUSH   EAX         ;eax
   CALL   ExitProcess      ;invoke ExitProcess


JUS STRUCT         ;4 bytes
   WNDCLASS DD 12 DUP 0   ;12*4=48 bytes (4+48+24+4 = 80D)
   MSG    DD 06 DUP 0   ;6*4= 24 bytes          and
   HWND    DD 0      ;1*4=  4 bytes  (80D is = to 50h)
ENDS

WinMain   FRAME hinst,hPrevInst,CmdLine,CmdShow
LOCAL   Smaller,rcl:JUS      ;LOCAL wc:WNDCLASSEX & LOCAL msg:MSG & LOCAL hwnd:HWND

   MOV D[EBP-48D],48D   ;mov   wc.cbSize,SIZEOF WNDCLASSEX
   MOV D[EBP-44D],3   ;mov   wc.style, CS_HREDRAW or CS_VREDRAW
   MOV D[EBP-40D],ADDR WndProc ;mov   wc.lpfnWndProc, OFFSET WndProc
   MOV D[EBP-36D],0   ;mov   wc.cbClsExtra,NULL
   MOV D[EBP-32D],0   ;mov   wc.cbWndExtra,NULL
   PUSH [hInstance]   ;Note: not sure ???
   POP  [EBP-28D]      ;pop   wc.hInstance
   MOV D[EBP-16D],6   ;mov   wc.hbrBackground,COLOR_WINDOW+1
   MOV D[EBP-12D],0   ;mov   wc.lpszMenuName,NULL
   MOV D[EBP-8] ,ADDR ClassName ;mov   wc.lpszClassName,OFFSET ClassName
   PUSH 32512D      ;7F00h = 32512D or IDI_APPLICATION
   PUSH 0             ; hInst = NULL
   CALL LoadIconA
   MOV D[EBP-24D],EAX   ;mov   wc.hIcon,eax
   MOV D[EBP-4],EAX   ;mov   wc.hIconSm,eax
   PUSH 32512D      ;7F00h = 32512D or IDC_ARROW
   PUSH 0         ;NULL 
   CALL LoadCursorA
   MOV D[EBP-20D],EAX   ;mov   wc.hCursor,eax
   LEA EAX,D[EBP-48D]   ;addr wc
   PUSH EAX                ; pWndClassEx
   CALL RegisterClassExA   ;invoke RegisterClassEx
   PUSH 0                  ; lParam = NULL
   PUSH [EBP+8]              ; hInst
   PUSH 0                  ; hMenu = NULL
   PUSH 0                  ; hParent = NULL
   PUSH 300D      ; Height = was 80000000h (-2147483648.)
   PUSH 500D      ; Width = was 80000000h (-2147483648.)
   PUSH 150D      ; Y = was 80000000h (-2147483648.)
   PUSH 150D      ; X = was 80000000h (-2147483648.)
   PUSH 0FC0000h      ;0CF0000h |Style = WS_OVERLAPPED|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU|WS_THICKFRAME|WS_CAPTION
;see windows.inc for valuess to add V_Scroll and H_Scroll, and value to take off WS_MINIMIZEBOX|WS_MAXIMIZEBOX

   PUSH ADDR AppName   ;ADDR AppName (13565952D = 0CF0000h)
   PUSH ADDR ClassName   ;ADDR ClassName
   PUSH 0         ; ExtStyle = 0
   CALL CreateWindowExA   ;INVOKE CreateWindowEx
   MOV D[EBP-80D],EAX
   PUSH 1         ; ShowState = SW_SHOWNORMAL
   PUSH [EBP-80D]      ; hWnd
   CALL ShowWindow      ; ShowWindow
   PUSH [EBP-80D]      ; hWnd
   CALL UpdateWindow   ; UpdateWindow
LL0:   PUSH 0                  ; MsgFilterMax = 0
   PUSH 0                  ; MsgFilterMin = 0
   PUSH 0                  ; hWnd = NULL
   LEA EAX,D[EBP-76D]   ;ADDR msg
   PUSH EAX                ; Msg
   CALL GetMessageA         ;invoke GetMessage
   OR EAX,EAX
   JE >LL1
   LEA EAX,D[EBP-76D]   ;ADDR msg
   PUSH EAX      ; Msg
   CALL TranslateMessage    ;invoke TranslateMessage
   LEA EAX,D[EBP-76D]   ;ADDR msg
   PUSH EAX      ; Msg
   CALL DispatchMessageA    ;invoke DispatchMessage
   JMP <LL0
LL1:   MOV EAX,D[EBP-68D]
   LEAVE
   RET
ENDF

WndProc FRAME hWnd, uMsg, wParam, lParam
   CMP D[EBP+12D],2
   JNZ >LL2
   PUSH 0         ;ExitCode = 0
   CALL PostQuitMessage   ;PostQuitMessage
   JMP >LL3
LL2:   PUSH [EBP+20D]      ;lParam
   PUSH [EBP+16D]      ;wParam
   PUSH [EBP+12D]      ;Message
   PUSH [EBP+8]      ;hWnd
   CALL DefWindowProcA   ;invoke DefWindowProc
   LEAVE
PUSH EBP   ;The Frame ends with a POP EBP, need to return the EBP with a PUSH EBP
   RET
LL3:   XOR EAX,EAX
   LEAVE
PUSH EBP   ;The Frame ends with a POP EBP, need to return the EBP with a PUSH EBP
   RET
ENDF


LL

jorgon

Hi LL, welcome to the forum

The "LEAVE" is causing the extra POP EBP, but you would only use "LEAVE" after an "ENTER" which you don't need anyway since all the work is done automatically by FRAME...ENDF.  If you remove the LEAVEs you can also remove the PUSH EBP which you added to compensate. 
Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

LL

Hi jorgon,

Did what you said and it worked out just great.  I'm just learning, so thank you for redirecting me.

LL