News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

masm32 procedures

Started by xponential, March 09, 2014, 11:07:35 AM

Previous topic - Next topic

xponential

please can someone link me to a resource where i can learn to create
routines in masm32.
i'm sorry for such dumb request but i've searched the .chm files
in masm32/help but there isn't anything that explains it in details for a
newbie to grasp.
also, i'm asking out of curiousity, when calling a routine in masm32, im i gonna need to
first of all push all parameters onto the stack as explained in the c calling convention
seeing that routines are called using INVOKE(which has parameters embedded just like HLL's) rather than CALL?

dedndave

we generally use the StdCall convention, which is what windows API functions use
you can also use the C convention, if desired

if a function is typed the same way it is prototpyed, the assembler will balance the stack with either convention

Func1 PROTO C :DWORD,:DWORD

    .CODE

Start:
    INVOKE  Func1,Arg1,Arg2
    INVOKE  ExitProcess,0

Func1 PROC C Parm1:DWORD,Parm2:DWORD

    ret

Func1 ENDP

    END     Start


if "C" is omitted on the PROTO and PROC lines, the StdCall convention is used (default)
Func2 PROTO :DWORD,:DWORD

    .CODE

Start:
    INVOKE  Func2,Arg1,Arg2
    INVOKE  ExitProcess,0

Func2 PROC Parm1:DWORD,Parm2:DWORD

    ret

Func2 ENDP

    END     Start

dedndave

you can use the forum search tool, searching for "stack frame" and find several more in-depth discussions

xponential

thank you dendave, much appreciated

raymond

Remember that there is no absolute need to use the INVOKE instruction (which is essentially a macro and not a true assembly instruction) in masm, neither is the use of creating an official procedures for every routine (as with the C/C++ language) as compared to the simple CALL of the routine when there is no need to create a stack frame.

One of the reasons for writing a "procedure" would be if you intend to reuse that code with other programs and don't want to rewrite that same code everytime, specially if it is a complex one. Another reason may be if you need to call that code within the same program with a variety of parameters which you can then easily pass on the stack.
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html