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:
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
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
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.)
Wow, Tedd, that's awesome. So, that equate doesn't produce any actual code, right ?
No code, the assembler just assigns the value to "len_stub"
however, forward-referencing isn't possible with this method ...
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