0% found this document useful (0 votes)
37 views27 pages

CH 5

The document discusses the concepts of procedures and macros in assembly language programming, highlighting their advantages and disadvantages. Procedures facilitate modular programming, allowing for code reusability, easier debugging, and reduced development time, while macros offer simplicity and improved readability but can lead to larger object files. It also covers types of procedures, methods for passing parameters, and a comparison between procedures and macros.

Uploaded by

salunkhej32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views27 pages

CH 5

The document discusses the concepts of procedures and macros in assembly language programming, highlighting their advantages and disadvantages. Procedures facilitate modular programming, allowing for code reusability, easier debugging, and reduced development time, while macros offer simplicity and improved readability but can lead to larger object files. It also covers types of procedures, methods for passing parameters, and a comparison between procedures and macros.

Uploaded by

salunkhej32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Program: Computer Engineering

(NBA accredited)

Microprocessors
(Course Code: 22415)
Course Teacher: Anjali Gharat
Procedure and Macro:

Procedure:
A large program is difficult to implement even if an algoritham is available,
Hence it should be split into number of independent tasks which can be easily
Designed and implemented

The process of splitting a large program into small tasks and designing
them independently is known as modular programming

A repeated group of instructions in a program can be organized as subprogram

A subprogram are called as subroutine or procedures in assembly


language programming

2
Advantages

Reusability of code:
The procedures provide us an ease in our code by making the set
of instructions reusable. So, we need not write the same set of
instructions again and again when required.

Less usage of memory:


The procedure is a subprogram which is stored in the memory
only one. But it can used as many times as required. So, this
occupies less memory space.
Development becomes easier:
By using procedures in a code, the modular programming can be
well implemented and so, each part of the code is written in a
different module which can be developed by a separate
developer. So, this reduces the burden on one developer and the
programming becomes simple for each of them.
3
Advantages

Reduced development time:


As separate developers can work on different modules of programs
separately, multiple developers can work on the project
simultaneously which reduces the total development time of the
project.

Debugging and error fixing becomes easier:


It becomes easier to detect and fix errors if the program is
present in different modules rather than the entire program being
present in a single code fragment

4
Disadvantages of using procedures

Extra code is required to integrate the procedures:


Every time a procedure is to be implemented in the program, we
require CALL and RET instructions to integrate the procedures
with the calling program

Extra time required to link the procedures:


Whenever a call to procedure is made, the control of the
processor goes to the procedure code, and then returns to the
calling program code. This takes a lot of extra time.

Not efficient way to use for a small set of instructions:


When the number of instructions is much less, then the calling and
returning from the procedures itself takes a lot more time than
executing the instructions itself. So, it is better to use procedures in
cases where the set of instructions to be included in the procedure
is large. 5
Disadvantages of using procedures

Extra load on the processor:


The processor needs to do extra work to save the status of the current
procedure and load status of the called procedure. Also, the instruction
queue must be emptied so that the instructions of the procedure can be
filled in the queue

6
Types of procedure

A procedure can be of two types. 1) Near Procedure 2) Far Procedure

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.

7
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.

General form :
procedure name PROC [Near/far]

Example:

ADD PROC NEAR


--------
--------
Procedure codes
-----

ADD ENDP
Directives used for procedure :

ENDP Directive: This directive is used along with the name of the
procedure to indicate the end

9
Explain NEAR CALL and FAR CALL procedure

10
Describe recursive procedure &reentrant
procedure with the help of schematic diagram

1)Recursive procedure :A recursive procedure is procedure which calls


itself. This results in the procedure call to be generated from within the
procedures again and again. This can be understood as follows

11
Recursive procedure

The recursive procedures keep on executing until the


termination condition is reached. The recursive procedures are
very effective to use and to implement but they take a large
amount of stack space and the linking of the procedure within
the procedure takes more time as well as puts extra load on the
processor 12
Re-entrant procedure

13
Re-entrant procedure

In some situation, it may happen that procedure 1 is called from


main
program and procedure 2 is called from procedure 1.And again
procedure 1 is called from procedure 2.
In this situation , program execution flow re-enters in the
procedure 1 ( first time when procedure 1 was
called from main program and second time when procedure 1 was
called from procedure 2) .Hence this
type of procedure is called as Reentrant procedure

14
Passing Parameter to procedure and from
procedure :

There are four major ways


of passing parameters to and from a procedure.

1) In register
2) In dedicated memory locations accessed by name
3) With pointer passed in register.
4) With the stack

15
1) Passing parameters in registers :

The main program can pass upto 6 parameters to the procedure through
the registers AX,BX,CX,DX,SI & DI before executing the call instruction.
e.g. consider the program to calculate a square of given number.

16
2)Passing parameters in dedicated
memory locations accessed by name :

when large number of parameters is to be passed to the


procedure, then these parameters can be placed in an
argument list as dedicated memory locations in one of the data
segment from memory.
e.g. consider the program to calculate a square of given number.

17
3) Passing parameters with Pointer

In the main program, before we call the procedure we can set up SI as a


pointer to pass values to procedures and set DI as pointer to receive values
from procedures.
e.g. consider the program to calculate a square of given number

18
4) Passing parameters with stack

Alternate method of passing large number of parameters is to push the


parameters on the stack in the main program before we call the
procedure.
e.g. consider the program to calculate a square of given number.

19
20
Macro

Defining Macro : A MACRO is group of small instructions that


usually performs one task. It is a reusable section of a software
program.A macro can be defined anywhere in a program using
directive MACRO &ENDM

General Form :
MACRO-name MACRO [ARGUMENT
1,……….ARGUMENT N]
-----
MACRO CODIN GOES HERE
ENDM

21
Macro

E.G DISPLAY MACRO 12,13


---------------------
MACRO STATEMENTS
-----------------------
ENDM

The Label prior to MACRO is the macro


name which should be used in the actual
program. The ENDM directive marks the
end of the instructions.A macro can be
called by quoting its name along with any
values to be passed to the macro.12 & 13
are values to be passed with macro

22
Advantages and disadvantages of MACRO :

Advantages:

1) Program written with macro is more readable.


2) Macro can be called just writing by its name along with
parameters, hence no extra code is required like CALL & RET.
3) Execution time is less bcz of no linking and returning
4) Finding errors during debugging is easier.

23
Disadvantages :

1) Machine code is generated every time a macro is called hence


object file becomes lengthy.
2) For large group of instructions macro cannot be preferred

24
Comparison Of Macro and Procedure

Sr. no PROCEDURE MACRO

1 Accessed by CALL and RET Accessed during assembly with name


instruction during program given to Macro when defined.
execution.

2 Machin code for instructions in Machine code is generated for


put only once in the memory. instructions each time when macro is
called.

3 With procedure less memory is With macro more memory is


required. required.
4 Parameters can be passed in Parameters passed as part of
register, Memory location or statement which calls macro.
Stack.
25
Sr. no PROCEDURE MACRO

Procedures are used for large Procedures are used for small group of
5
group of instructions to be instructions to be repeated
repeated

Length of the object file is less Object file becomes lengthy.


6

Directives PROC & ENDP are used Directives MACRO and ENDM are used
7
for defining procedure. for defining MACRO
More time is required for it’s Less time is required for it’s execution
8
execution

26
Thank You

27

You might also like