Partager via


PROC

Marks start and end of a procedure block called label. The statements in the block can be called with the CALL instruction or INVOKE directive.

label PROC [[distance]] [[langtype]] [[visibility]] [[<prologuearg>]] 
   [[USES reglist]] [[, parameter [[:tag]]]]...
   [FRAME [:ehandler-address] ]
   statements
   label ENDP

Parameters

  • label
    Defines the name for the procedure. Follows the naming convention of langtype.

  • prologuearg
    Arguments to pass to the prologue procedure. With the default PROLOGUE and EPILOGUE, the FORCEFRAME argument generates a stack segment, even if one is not necessary. LOADDS causes the DS register to be saved in the PROLOGUE and restored in the EPILOGUE. Parameters must be separated by commas. Angle brackets are required but not passed.

  • distance
    Can be NEAR, FAR, NEAR16, NEAR32, FAR16, or FAR32. Indicates the call distance of this procedure. If you choose NEAR or FAR, the assembler will select 16- or 32-bit NEAR or FAR depending on the current segment size. If you do not specify this option, the assembler determines the distance from the memory model and processor type. NEAR is the default if you do not use the .MODEL directive.

  • langtype
    Any valid language type. Determines naming style and calling convention.

  • visibility
    Can be PRIVATE, PUBLIC, or EXPORT. Determines how the procedure is made available to other modules. PUBLIC is the standard default, but the default can be reset with the OPTION PROC directive. EXPORT implies PUBLIC and FAR and informs the linker that the procedure should be placed in the export entry table.

  • reglist
    List of registers that the prologue preserves on the stack and the epilogue restores on exit. Separate multiple registers with spaces.

  • parameter
    Procedure parameter. The assembler translates argument references into a direct reference to the stack location. Separate multiple arguments with commas.

  • tag
    Either a qualified type or VARARG. VARARG allows a variable number of arguments to be passed as a comma separated list to <argument>. If VARARG is used, it must be applied to the last parameter of the PROC directive. VARARG is only allowed with the C, SYSCALL, and STDCALL language types. If tag is omitted, the assembler defaults to WORD in a 16-bit segment or DWORD in a 32-bit segment.

  • statements
    Assembly-language statements and directives.

Remarks

[FRAME [:ehandler-address] ] is only valid with ml64.exe, and causes MASM to generate a function table entry in .pdata and unwind information in .xdata for a function's structured exception handling unwind behavior.

When the FRAME attribute is used, it must be followed by an .ENDPROLOG directive.

See MASM for x64 (ml64.exe) for more information on using ml64.exe.

Example

; ml64 ex1.asm /link /entry:Example1 /SUBSYSTEM:CONSOLE
_text SEGMENT
Example1 PROC FRAME
   push r10
.pushreg r10
   push r15
.pushreg r15
   push rbx
.pushreg rbx
   push rsi
.pushreg rsi
.endprolog
   ; rest of function ...
   ret
Example1 ENDP
_text ENDS
END

The above code will emit the following function table and unwind information:

FileHeader->Machine 34404
Dumping Unwind Information for file ex2.exe

.pdata entry 1 0x00001000 0x00001023

  Unwind data: 0x00002000

    Unwind version: 1
    Unwind Flags: None
    Size of prologue: 0x08
    Count of codes: 3
    Frame register: rbp
    Frame offset: 0x0
    Unwind codes:

      Code offset: 0x08, SET_FPREG, register=rbp, offset=0x00
      Code offset: 0x05, ALLOC_SMALL, size=0x10
      Code offset: 0x01, PUSH_NONVOL, register=rbp

See Also

Other Resources

Directives Reference