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[512]:BYTE ret Intell ENDP Thanks for Reply.
Posted on 2000-11-30 06:42:00 by Morgatte
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[512]: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
Posted on 2000-11-30 07:35:00 by 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
Posted on 2000-11-30 08:18:00 by Mirno
Thanks, I happy
Posted on 2000-11-30 11:42:00 by Morgatte
J'll examine that to see if it's really that
Posted on 2000-11-30 11:43:00 by Morgatte
I come just to try with W32Dasm, it works :)
Posted on 2000-11-30 12:07:00 by Morgatte
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, hutch@pbq.com.au
Posted on 2000-11-30 19:53:00 by hutch--
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
Posted on 2000-11-30 21:32:00 by BogdanOntanu
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
Posted on 2000-11-30 23:24:00 by ub1
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, hutch@pbq.com.au
Posted on 2000-12-01 17:26:00 by hutch--