What is 'uses esi edi' ? Why sometime we put that and other time we don't ? Intell PROC use esi edi entree1:DWORD, entree2:BYTE LOCAL buffer:BYTE ret Intell ENDP Thanks for Reply.
I maybe wrong here (I'm fairly new to this asm stuff), but I think it means that at the end of the PROC those registers are restored to the value they had when the PROC was called. Its the same as: Intell PROC entree1:DWORD, entree2:BYTE LOCAL buffer:BYTE push edi push esi ... mov edi, stuff ;We use edi in our code
mov esi, more_stuff ;We also use esi in our code ... pop esi ;Restore esi to value when called pop edi ;Restore edi to value when called ret Intell ENDP Then again I may be getting confused with something else... :P Mirno
Doh! It got confused by my "
" bit! Just incase that doesnt turn out right: Doh! It got confused by my "(Less than)Code goes here(Greater than)" bit! :) Mirno
Thanks, I happy
J'll examine that to see if it's really that
I come just to try with W32Dasm, it works :)
Morgatte, 32 bit windows has a convention in relation to which registers you can freely use and which ones you must preserve. You can freely use EAX, ECX & EDX but you must preserve EBX, ESI & EDI if you use them in a procedure. Some people use the MASM notation "uses ESI EDI" but it works just as well if you manually preserve the registers, ProcName proc par1:DWORD, par2:DWORD etc ... push esi push edi ; write code that uses esi edi pop edi pop esi ret ; always have a return instruction ProcName endp Make sure you do the pushes and pops in reverse order. Regards, email@example.com
We have to save esi and edi everywhere or only in Wndproc ? or message loop? surely not in a sepparate thread...dont let me down :) Bogdan
If you use EDI, ESI, or EBX in a callback, you must save and restore them. Callback functions include window procs, dialog procs, timer procs... As a general rule: If you need to push a function address as an argument to a Win32 API, it's a callback function. If you need to store a function address in a structure used by a Win32 API, it's a callback function. Conversely, because the Windows API follows the same conventions, you don't need to save and restore those registers when calling the API. push esi ; saving this is redundant push edi ; saving this is redundant push ebx ; saving this is redundant ; push arguments here call APIfunction pop ebx pop edi pop esi WndProc proc push esi ; needed push edi ; needed push ebx ; needed ; code that uses ESI, EDI, and EBX pop ebx ; needed before every RET pop edi pop esi ret endp
There is something being confused here, win 32 convention (like it or lump it) is to preserve EBX, ESI & EDI in a procedure if they are used. This means if you use EBX in the procedure, you push it at the start and pop it at the end before the RET. This means that the procedure can freely use EAX, ECX & EDX without having to take any precautions. The catch is that if you call another procedure and it conforms to the same convention, you DON'T have to preserve EBX, ESI & EDI either side of the procedure call but you MAY have to preserve EAX, ECX & EDX as the called procedure can ALSO freely use them. This is not specific to only callback or message handling procedures, this convention works across ALL of 32 bit Windows. This will not stop you from writing bits of code that do not conform to this convention but if you wish to interact with API functions and the operating system in general, you will have to observe this convention. Regards, firstname.lastname@example.org