The MASM Forum

General => The Campus => Topic started by: mabdelouahab on November 29, 2015, 06:03:34 PM

Title: Size Of Function
Post by: mabdelouahab on November 29, 2015, 06:03:34 PM
Good morning all
To determine the address of a Proc I use "offset MyProc", my question is:
Is there any way to know the size of this proc or to know the address of the end proc
Title: Re: Size Of Function
Post by: hutch-- on November 29, 2015, 06:34:50 PM
Yes, write a procedure AFTER the procedure you want to find the address for and put a label AFTER is but before the next procedure and you get both the start address and by subtracting the start address from the end label address, you get the exact length as well.
Title: Re: Size Of Function
Post by: Siekmanski on November 29, 2015, 06:39:48 PM
Put a label endtestproc: after your proc

testproc proc
   
   xor eax,eax
   ret
testproc endp
endtestproc:

   mov   eax,(endtestproc - offset testproc)   ; eax = the code size of your proc

EDIT: Hutch was faster.  :biggrin:

Title: Re: Size Of Function
Post by: hutch-- on November 29, 2015, 11:56:07 PM
 :biggrin:

Yeah, you have to watch us old fellas, we are not as slow as we look.  ;)
Title: Re: Size Of Function
Post by: jj2007 on November 30, 2015, 05:30:33 AM
CodeSize (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1221) 8)
Title: Re: Size Of Function
Post by: mabdelouahab on November 30, 2015, 09:08:48 AM
hutch,jj2007,Siekmanski, Thanks for the information
Usually The procedure ends with one of two things:
RETN ;(C3) :1 word
or
LEAVE   ;(C9) :1 word
RETN x  ;(C2 x 00 ):3 word

Can we take advantage of them, Instead of the LABEL hutch  :biggrin:
I suspect that it needs an algorithm :redface:
Title: Re: Size Of Function
Post by: sinsi on November 30, 2015, 09:21:31 AM
You could try your own prologue/epilogue.
Title: Re: Size Of Function
Post by: jj2007 on November 30, 2015, 09:44:01 AM
Quote from: mabdelouahab on November 30, 2015, 09:08:48 AM
Can we take advantage of them, Instead of the LABEL hutch  :biggrin:

Of course you can, but why should you? Unless you only have the exe and no source, of course :icon_mrgreen: