Procedures IN ASSEMBLY LANGUAGE

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

PROCEDURES

By: NIMRA TARIQ


What are Procedures

 a named group of statements that perform an operation or task.


 can be called by the main program or another procedure.
 It is used for large set of instructions which are divided into smaller
parts/procedures.
Syntax

 Assembler directive PROC is used to define procedure and assembler directive


ENDP is used to indicate the body is over
Example:
name proc ; Return ret is used so the control will come back
. ;to the calling function.
.
Ret
name endp
Example:

 Subof PROC ; subof is the name of procedure


 mov ax,46
 mov bx,77
 sub ax,bx

 Ret
 SubOf ENDP
why do we need it?

 It allows complex jobs to run in a simpler way.


 It is memory efficient, as it requires less memory.
 It is faster in speed, as its execution time is less.
 Reusability .
CALL and RET Instructions

CALL RET

• The CALL instruction • The RET instruction


calls a procedure. returns from a
procedure.

• Call is used in calling • Return RET is used so


procedure to call the control will come
another procedure. back to calling function.
Types of procedures:

1.  User-defined functions
2. Built in functions
User-defined functions

 Function and its functionality is defined according to user’s need.


 E.g:
 Sumof
 Mymethod
 sample
Built in functions:

Built in functions are already defined in the library.

Function Description
Name
MESSAGE Displays a message on the
screen.
MAXSTRLEN Returns the defined length of a
string variable
ARRAYLEN Returns the number of
elements in an array.
Local method and Global methods

 A local method can only be


local global
accessed or called from where it is
declared.
 A global method can be called from Local Mymethod Mymethod
anywhere. proc proc
Nested Procedure Calls

 Procedure nesting occurs when one stored procedure calls another.


 The nesting level increments when the called procedure begins execution, and
decrements when the called procedure completes execution. Exceeding the
maximum of 16 levels of nesting causes the transaction to fail.
Example:Nested Procedure Calls

 main PROC
call Sum1
exit main
ENDP
 Sum1 PROC
call Sum2
Ret
Sum1
ENDP
 Sum2 PROC
Ret
Sub2 endp

You might also like