Previous
Previous Product Image

Easy Notes Of Microprocessor unit-4 @Computer Diploma

Original price was: ₹99.99.Current price is: ₹19.99.
Next

Easy Notes Of Data Communication and Computer Network unit-2 @Computer Diploma

Original price was: ₹99.99.Current price is: ₹19.99.
Next Product Image

Easy Notes Of Microprocessor unit-5 @Computer Diploma

Original price was: ₹99.99.Current price is: ₹19.99.

Unit – V Procedure and Macro

5.1 Procedure: Defining and calling procedure PROC, ENDP, FAR and NEAR Directives; CALL and RET instructions; Parameter passing methods, Assembly language programs using procedure

5.2 Macro: Defining macro, MACRO and ENDM Directives, Macro with parameters, Assembly language programs using macro

Hurry Up!
Add to Wishlist
Add to Wishlist

Description

5.1 Procedure (Functions)

This section deals with how modular, reusable code blocks are defined, invoked, and managed within assembly programs.

Defining and Calling Procedures

  • Procedure Declaration and Termination:

    • PROC Directive $\rightarrow$ Procedure Entry Point Definition (e.g., MyProc PROC NEAR/FAR)

    • ENDP Directive 1$\rightarrow$ Procedure Termination Indicator2

    • CALL Instruction $\rightarrow$ Subroutine Call and Return Address Push

    • RET Instruction 3$\rightarrow$ Return from Procedure and Stack Pointer Adjustment4

  • Segment and Scope Directives:

    • NEAR Directive $\rightarrow$ Intra-Segment Procedure Call (Calling within the same code segment; only the Instruction Pointer (IP) is pushed onto the stack).

    • FAR Directive $\rightarrow$ Inter-Segment Procedure Call (Calling across different code segments; both the Code Segment (CS) and Instruction Pointer (IP) are pushed onto the stack).

    • External Procedure Declaration: Using the EXTRN directive to reference a procedure defined in a different source file during Modular Programming.

Parameter Passing Methods

This is how data is exchanged between the calling program and the procedure.

    • Register Passing:

      • General-Purpose Register Exchange (Data passed through registers like AX, BX, CX, DX).5 Fastest method.

    • Stack Passing:

      • Stack-Based Parameter Transfer (Parameters are pushed onto the stack before the CALL and popped or managed by the procedure).6

      • Stack Frame Management: Techniques involving the Base Pointer (BP) register to access parameters and local variables relative to the stack frame (e.g., accessing the $N^{th}$ parameter using offsets like $[BP+N]$).

Shutterstock
* **Caller Cleanup:** The calling program is responsible for removing the parameters from the stack after the `RET` instruction returns.
* **Callee Cleanup:** The called procedure is responsible for removing parameters by using an optional operand with the `RET` instruction (e.g., `RET N`).
  • Global Variable Passing:

    • Shared Data Segment Access (Data exchanged via variables defined in the main data segment, accessible by both the caller and the callee).

Programming Concepts

  • Stack Preservation: Saving and restoring the state of used registers (e.g., using PUSH and POP instructions) at the beginning and end of a procedure to ensure non-side-effect execution.7

  • Reentrant Procedures: Procedures that can be safely interrupted in the middle of execution and called again (“re-entered”) before the first call has concluded, often requiring local variable storage on the stack.

  • Recursive Procedure Implementation: A procedure that calls itself, relying heavily on stack frame allocation for preserving return addresses and local data for each nested call.

5.2 Macro (Code Substitution)

This section covers the concept of macros, which are essentially text substitution mechanisms handled by the assembler during the assembly phase.

Defining and Expanding Macros

  • Macro Definition Block:

    • MACRO Directive 8$\rightarrow$ Macro Header Definition (e.g., MyMacro MACRO param1, param2)9

    • ENDM Directive $\rightarrow$ End of Macro Definition

    • Macro Expansion Process: The assembler’s action of replacing the macro name with the entire block of code defined between MACRO and ENDM before generating machine code.

  • Differences from Procedures:

    • In-Line Code Substitution (Macros insert code at every call site, increasing code size but eliminating procedure call overhead).

    • Assembly-Time Processing (Macros are handled by the assembler; procedures are run-time structures).

    • No Stack Usage Overhead (Since no CALL/RET instructions are used).

Macros with Parameters

  • Positional Parameter Substitution: Arguments passed during the macro call are substituted based on their position in the macro definition (e.g., param1, param2).

  • Local Variable Creation: Using the LOCAL directive inside a macro to ensure that any labels or variables defined within the macro body are unique for each expansion, preventing Multiple Definition Errors.

  • Conditional Assembly within Macros: Using directives like %IF, %ELSE, and %ENDIF inside a macro to allow for flexible code generation based on conditions evaluated during the assembly process.

Advanced Macro Usage

  • Nested Macro Definitions: Defining one macro within the body of another, allowing for complex, layered code generation templates.

  • Repeat/Loop Directives: Using directives like %REPT (Repeat) or %IRP (Indefinite Repeat) within a macro to generate repetitive code structures efficiently.

  • String Manipulation Directives: Advanced directives for manipulating text and strings passed as macro parameters.

Reviews

There are no reviews yet.

Be the first to review “Easy Notes Of Microprocessor unit-5 @Computer Diploma”

Your email address will not be published. Required fields are marked *

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping