News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ebp not accesible in the message loop ?

Started by gelatine1, June 15, 2014, 05:36:02 AM

Previous topic - Next topic

gelatine1

I had written this message loop for my window and it crashed somehow.

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov eax,uMsg

cmp eax, WM_DESTROY
jnz __cont1
invoke PostQuitMessage,NULL
jmp __cont

__cont1:
cmp eax,WM_KEYDOWN
jnz __cont2

mov eax,wParam
mov ebp,pmem
mov dword ptr [ebp],eax
;irrelevant stuff

jmp __cont

__cont2:
invoke DefWindowProc,hWnd,uMsg,wParam,lParam     ; Default message processing
ret

__cont:
xor eax,eax
ret
WndProc endp


As you can see I change ebp if the user presses a key and this is exactly why the program crashes. In the debugger I saw that ebp already gets used in this message loop so if its altered it crashes ofcourse. But I don't really see why it gets used already so could anyone explain that to me ? I hope I was clear and otherwise ask me for clarification.

thanks in advance,
Jannes

dedndave

EBP is quite often used as a stack frame Base Pointer

also, WndProc is a call-back process - EBX, EBP, ESI, and EDI should be preserved
and, if you set the direction flag, you should clear it before exiting

the routine may be written without using EBP for a stack frame, but i don't recommend it for beginners
simply preserve EBX, ESI, or EDI and use that, instead

gelatine1


MichaelW

EBP is normally used to point to data on the stack. And while EBP and ESP are classified as general-purpose registers, they are specialized in that using them as a base register in a memory operand will cause the default segment selection to use SS instead of DS. This difference will not cause problems in a Win32 app because DS and SS point to the same segment, but would cause problems in a DOS app where SS and DS pointed to different segments.
Well Microsoft, here's another nice mess you've gotten us into.