News:

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

How to read the byte length of a procedure in masm

Started by hutch--, May 14, 2006, 04:50:09 AM

Previous topic - Next topic

hutch--

This topic has been a question in another pace but as I cannot safely post there, I have placed one easy approach here for anyone who is interested. A "PROC" in masm is effectively a label and can be addressed by the OFFSET operator at assembly time but there is an even easier way where you don't have to store both values and do the calculation and this is demonstrated below. Now where there is a potential limitation that may return a larger BYTE count than the proc size is if each procedure is aligned and the alignent padding is included in the two OFFSETs that are used. In this context if it was a problem a label placed after the RET would yield the correct result.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    var = last_proc - how_big   ;;;; calculated at assembly time
    mov eax, var
    print str$(eax)," = how_big proc length in BYTES",13,10

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

how_big proc

    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop

    ret

how_big endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

last_proc proc

    nop

    ret

last_proc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ossa

Hutch,

as I understand it, the OP was trying to find this info at assemble time (but then again, I'm not too sure).

Ossa
Website (very old): ossa.the-wot.co.uk

hutch--

Ossa,

"var = last_proc - how_big" does the calculation at assembly time, I just used screen display to show the results. The value of the calculation result in "var" is written as an immediate with the following "mov eax, var" so if "var" is 9 then the code is generated as "mov eax, 9"
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ossa

Website (very old): ossa.the-wot.co.uk