## ALP Programming Guide and Reference

[prev][next][parent][TOC]

### PROC (Identify Code Procedure)

The PROC directive identifies a block of code. By dividing the code into blocks, each of which performs a distinct function, you can clarify the overall function of the complete module.

The PROC directive also identifies the procedure distance to help insure that the assembler generates the appropriate instructions for calling and returning from the procedure while maintaining the integrity of the run- time stack.

Syntax

    Procedure - Name   PROC   [ Attributes ]   [ Register - List ]   [ Parameter - List ]
        .
        .
        .
    RET   [ Constant ]
        .
        .
        .
    Procedure - Name   ENDP

Refer to the following sections for descriptions of the optional arguments to the PROC directive:

Attributes
Register-List
Parameter-List

Remarks

You can execute the block of code identified by the PROC directive in-line, jump to it, or start it with a CALL instruction. If the PROC is called from code that has another ASSUME CS value, you must use the appropriate FAR, FAR16, or FAR32 distance attribute.

The NEAR attribute causes any RET instruction coded within the procedure to be an intra-segment return that pops a return offset from the stack. You can call a NEAR subroutine only from the same segment. However, the FAR attribute causes RET to be an inter-segment return that pops both a return offset and a segment base from the stack. You can call a FAR subroutine from any segment; a FAR subroutine is usually called from a segment other than the one containing the subroutine.

Example

In this example, the Near_Name subroutine is called by the Far_Name subroutine.

               PUBLIC     Far _ Name
    Far _ Name    PROC       FAR
               CALL   Near _ Name
               RET                  ; Pops   return   offset   and   seg   base   value
    Far _ Name    ENDP

               PUBLIC     Near _ Name
    Near _ Name   PROC       NEAR
               .
               .
               .
               RET                  ; pops   only   return   offset
    Near _ Name   ENDP

You can call the Near_Name subroutine directly from a NEAR segment by using :

    CALL   Near _ Name

A FAR segment can indirectly call the second subroutine by first calling the Far_Name subroutine with:

    CALL   Far _ Name

A CALL to a forward-referenced symbol assumes the symbol is NEAR. If that symbol is FAR, the CALL must have an override, for example:

    CALL   FAR   PTR   Forward _ Reference