The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ecube on October 12, 2009, 07:12:03 AM

Title: uses directive
Post by: ecube on October 12, 2009, 07:12:03 AM
is there any downsides/dangerous to using uses? and what registers does the winapi preserve?
Title: Re: uses directive
Post by: sinsi on October 12, 2009, 07:35:52 AM
dangerous: why? all it does is automatically push and pop the registers
downside: I'm not sure if using "option prolog:none" changes things

winapi: saves ebx,esi,edi,ebp
Title: Re: uses directive
Post by: hutch-- on October 12, 2009, 07:38:59 AM
Cube,

It works OK, just sppecify the registers you want preserved and it will automatically di it for you but there is a down side, if you have multiple exits from the procedure, it write multiple copies of the stack balancing code which may not be what you want in terms of size. I always do my own manually.
Title: Re: uses directive
Post by: jj2007 on October 12, 2009, 07:42:44 AM
Quote from: sinsi on October 12, 2009, 07:35:52 AM
downside: I'm not sure if using "option prolog:none" changes things

It does. No pushn & poppin with PROLOGUE:NONE...  check yourself

include \masm32\include\masm32rt.inc

MyProc PROTO: DWORD, :DWORD, :DWORD

.code
start: int 3  ; greetings to Olly
invoke MyProc, 123,456, 789
exit

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
MyProc proc uses esi edi ebx arg1_:DWORD, arg2_:DWORD, arg3_:DWORD
  ret 4*3
MyProc endp
MyProc_END: ; label for csize macro
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
Title: Re: uses directive
Post by: sinsi on October 12, 2009, 07:59:52 AM
I used to have a macro (xpush/xpop) so you could use "xpush ebx,esi,edi" on one line

Quote from: jj2007 on October 12, 2009, 07:42:44 AM
It does. No pushn & poppin with PROLOGUE:NONE...  check yourself
Thought so. I was just too lazy to test it...
Title: Re: uses directive
Post by: dedndave on October 12, 2009, 09:06:09 AM
i am not sure the api keeps the direction flag cleared, but it should be included in the list with ebx, esi, edi, ebp
you are expected to keep it cleared