(Part 8)
Procedures
Procedure is a part of code that can be called from your program in
order to make some specific task. Procedures make program more
structural and easier to understand. Generally procedure returns to the
same point from where it was called.
The syntax for procedure declaration:
name PROC
; here goes the code
; of the procedure ...
RET
name ENDP
name - is the procedure name, the same name should be in the top and
the bottom, this is used to check correct closing of procedures.
Probably, you already know that RET instruction is used to return to
operating system. The same instruction is used to return from procedure
(actually operating system sees your program as a special procedure).
PROC and ENDP are compiler directives, so they are not assembled into
any real machine code. Compiler just remembers the address of
procedure.
CALL instruction is used to call a procedure.
Here is an example: