You are on page 1of 1

15.

PROCEDURES

 code units that fulfill specific functions


 way of dividing the code in functional parts / blocks so that a specific function can be executed from any
other point in the program without having to insert the same code again and again
 comparable with C functions
 the PROC and ENP directives mark the beginning and the ends of the procedure
 CALL instr. is used to call the defined procedure, RET instr. is used for returning to the calling point
 CALL, RET use the stack to store and restore the return address
 CALL pushes on stack the return address (address after the CALL instr.) and then a jump to the
address at the beginning of the procedure is done
 RET pops from the stack the address introduced by the CALL instr. and returns to the instr. after the
call
 procedures can be found or not in the same segment with the calling instr.
 => 2 types: NEAR and FAR
 when a procedure is declared, its type is declared too
 NEAR type is implicit
 syntax:
<label> PROC [NEAR | FAR]
 specify a # of bytes that will be added to
… the content of SP register after returning
RET [constant]  can be used for deleting from the stack
the arguments that were transmitted to
<label> ENDP
the procedure through the stack

 CALL syntax: CALL {register | memory}


 no procedure may be called both with FAR and NEAR CALL; this function is established very carefully
when projecting the programs (FAR declaration is simple but totally non-economic)
 it is possible to declare imbricated and overlapping procedures

You might also like