CH 5
CH 5
Near Procedure:
A procedure is known as NEAR procedure if is written(defined) in the same code
segment which is calling that procedure. Only Instruction Pointer(IP register) contents
will be changed in NEAR procedure.
FAR procedure :
A procedure is known as FAR procedure if it is written (defined) in the different code
segment than the calling segment. In this case both Instruction Pointer(IP) and the
Code Segment(CS) register content will be changed.
Directives used for procedure :
PROC directive:
The PROC directive is used to identify the start of a procedure. The PROC
directive follows a name given to the procedure.
After that the term FAR and NEAR is used to specify the type of the
procedure.
ENDP Directive:
This directive is used along with the name of the procedure to indicate the end
of a procedure to the assembler.
The PROC and ENDP directive are used to bracket a procedure.
CALL instruction and RET instruction :
CALL instruction :
The CALL instruction is used to transfer execution to a procedure.
It performs two operation.
When it executes, first it stores the address of instruction after the CALL instruction
on the stack .
Second it changes the content of IP register in case of Near call and changes the
content of IP register and cs register in case of FAR call.
When 8086 executes a near CALL instruction, it decrements the stack pointer by 2
and copies the IP register contents on to the stack.
SP SP-2
CS contents stored on stack
SP SP-2
IP contents stored on stack
CS Base address of segment having procedure
IP address of first instruction in procedure.
RET instruction :
The RET instruction will return execution from a procedure to the next instruction after call in the
main program.
At the end of every procedure RET instruction must be executed.