News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to calculate the size of a PROC?

Started by frktons, September 13, 2010, 12:12:56 AM

Previous topic - Next topic

jj2007

Quote from: MichaelW on September 13, 2010, 06:45:28 PM
Instead of the redundant label at the start of the procedure, why not just use the procedure name?

sub  eax,  algo


Michael,
I can't remember the exact conditions, but I have seen cases where that resulted in wrong sizes because a label close to the module entry point was used that contained a jmp MyProc. Since then I use the extra MyProc_s: label.

frktons

This is probably the way I'm going to use the customized version of Jochen's MACRO:


;-------------------------------------------------------
; Jochen's MACRO for calculating the size of a PROC
; customized for my personal taste/need. 13-sep-2010
;-------------------------------------------------------

include \masm32\include\masm32rt.inc

MyTest PROTO: DWORD, :DWORD

MyCodeSize MACRO algo, algosize
  pushad
  mov eax, offset &algo&End
  sub eax, offset &algo&
  mov &algosize&, eax 
  popad
ENDM


.data?

MyProcSize  DWORD ?


.code

start:

Main PROC

  MyCodeSize MyProc, MyProcSize
  print str$(MyProcSize), 9, " bytes for MyProc", 13, 10, 13, 10 
  inkey "Press a key to continue..."
  invoke ExitProcess, 0

Main ENDP

;-------------------------------------------------------
; PROC that we want to calculate the size of
;-------------------------------------------------------
MyProc proc arg1:DWORD, arg2:DWORD
  MsgBox 0, arg1, arg2, MB_OK
  ret
MyProcEnd:: 
MyProc endp


I prefer to store the size of the PROC in a variable for future use.
Do you see any problem that can arise?

Frank
Mind is like a parachute. You know what to do in order to use it :-)