News:

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

how to get a function size?

Started by stbfish, September 12, 2009, 01:22:19 PM

Previous topic - Next topic

stbfish


stub proc
    ;
    pushfd
    pushad
    ;
    popad
    popfd
    ret
stub endp

like this function, how to count this function size in bytes.
i got idea is put two lables, on at top, one at end. then
mov eax, offset lab1
mov ebx, offset lab2
sub eax, ebx   :dazzled:


dedndave

there are a few ways to do it

        dd EndOfStub-stub

stub proc
    ;
    pushfd
    pushad
    ;
    popad
    popfd
    ret
stub endp

EndOfStub LABEL BYTE

        mov     eax,offset EndOfStub-stub

hutch--

stbfish,


MyProc proc args etc ....  ; < this is actually a label.

  ; Your Code

    ret

MyProc endp

  end_label::   ; < notice :: for global label.

NextProc etc ....

; ============

; Later when length is required calculate length dynamically.
  mov eax, OFFSET end_label
  sub eax, OFFSET MyProc
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Tedd

There is a simple way..

stub proc
    ;...
    ret
stub endp
len_stub equ $-OFFSET stub

"len_stub" can then be used as a constant wherever you need the size of the function (in bytes.)
No snowflake in an avalanche feels responsible.

BlackVortex

Wow, Tedd, that's awesome. So, that equate doesn't produce any actual code, right ?

Tedd

No code, the assembler just assigns the value to "len_stub"
No snowflake in an avalanche feels responsible.

qWord

however, forward-referencing isn't possible with this method ...
FPU in a trice: SmplMath
It's that simple!

dedndave

qword is right - that is why i use a label (it can be a code or data label - no diff)
if you use an equate, it has to be defined in the file before it can be used
(some assemblers may allow it - not masm, though)
re: post #2 of the thread