0
1.9kviews
Write short note on 1.Procedure. 2. Macros
1 Answer
0
97views

Short Notes :-


1. Procedure :-

A procedure is group of instructions that usually performs one task. It is a reusable section of a software program which is stored in memory once but can be used as often as necessary.

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.


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.


Advantages of using procedure :-

  • Allows to save memory space.
  • Program development becomes easier.
  • Debugging of errors in program become easy.
  • Reduced size of program
  • Reusability of procedure.

Disadvantages of using procedure :-

  • CALL and RET instructions are always required to integrate with procedures.
  • Requires the extra time to link procedure and return from it.
  • For small group of instructions, linking and returning back time more than the execution time, hence for small group of instructions procedures cannot be preffered.



2. Macros :-

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.

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.


Advantages of MACRO :

  • Program written with macro is more readable.
  • Macro can be called just writing by its name along with parameters, hence no extra code is required like CALL & RET.
  • Execution time is less bcz of no linking and returning
  • Finding errors during debugging is easier.


Disadvantages of MACRO :

  • object code is generated every time a macro is called hence object file becomes lengthy.
  • For large group of instructions macro cannot be preferred
Please log in to add an answer.