0% found this document useful (0 votes)
9 views14 pages

Unit 5

The document is a question bank for the subject 'Microprocessor' at Sanjay Ghodawat Institute, covering various topics including procedures, macros, and assembly language programming. It includes explanations of recursive and re-entrant procedures, the CALL and RET instructions, and provides examples of using macros for arithmetic operations. Additionally, it features assembly language programs to compute expressions using both procedures and macros.

Uploaded by

alonepiece24
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)
9 views14 pages

Unit 5

The document is a question bank for the subject 'Microprocessor' at Sanjay Ghodawat Institute, covering various topics including procedures, macros, and assembly language programming. It includes explanations of recursive and re-entrant procedures, the CALL and RET instructions, and provides examples of using macros for arithmetic operations. Additionally, it features assembly language programs to compute expressions using both procedures and macros.

Uploaded by

alonepiece24
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/ 14

Institute Code & Name: SANJAY GHODAWAT INSTITUTE,

ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

(2 Marks)

1. Explain Re-Entrant and Recursive Procedure with diagram


2. 1)Recursive procedure:
3. A recursive procedure is procedure which calls itself. This results in
the procedure call
4. to be generated from within the procedures again and again.
5. The recursive procedures keep on executing until the termination
condition is reached.
6. The recursive procedures are very effective to use and to implement
but they take a large
7. amount of stack space and the linking of the procedure within the
procedure takes more
8. time as well as puts extra load on the processor.

9.
10. 2) Re-entrant procedures:
11. In some situation it may happen that Procedure 1 is called from main
program
12. Procrdure2 is called from procedure1And procedure1 is again called
from procdure2. In
13. this situation program execution flow re enters in the procedure1.
These types of
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

14. procedures are called re-entrant procedures.


15. A procedure is said to be re-entrant, if it can be interrupted, used and
re-entered without
16. losing or writing over anything.

17.

18. Define MACRO with its syntax.

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
E.G DISPLAY MACRO 12,13
---------------------
MACRO STATEMENTS
-----------------------
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

ENDM

19. Write any two differences between NEAR and FAR procedure.

20. Explain CALL and RET instruction

CALL and RET Instructions in 8086 Microprocessor

The CALL and RET instructions in the 8086 microprocessor are used to handle subroutines
(procedures) — blocks of code that can be reused from multiple places in a program.

� CALL Instruction (Call Subroutine)


➤ Purpose:

 The CALL instruction is used to transfer program control to a subroutine


(procedure).
 It saves the address of the next instruction (i.e., the return address) on the stack, so
that control can return after the subroutine finishes.

➤ Syntax:
asm
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

CopyEdit
CALL subroutine_label

➤ How it Works:

1. The address of the next instruction (after the CALL) is pushed onto the stack.
2. Control jumps to the subroutine.
3. Execution continues from the subroutine until a RET instruction is encountered.

➤ Example:
asm
CopyEdit
MAIN:
CALL ADDITION ; Call the subroutine
MOV AX, BX ; Continue here after subroutine returns

ADDITION:
MOV BX, 5
ADD BX, 3
RET ; Return to instruction after CALL

� RET Instruction (Return from Subroutine)


➤ Purpose:

 The RET instruction is used at the end of a subroutine to return control back to the
instruction after the CALL.
 It pops the return address from the stack and jumps to that address.

➤ Syntax:
asm
CopyEdit
RET
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

➤ How it Works:

 Pops the saved IP (instruction pointer) from the stack.


 Transfers control to that location in the main program.

� Working Together – CALL and RET:


When CALL is executed:

 Return Address is pushed on the stack.


 Control jumps to subroutine.

When RET is executed:

 Return Address is popped from the stack.


 Control returns to the main program.

� Stack Behavior:

Instruction Action on Stack


CALL Push return address (IP)
RET Pop return address, jump to it

� Key Points:
 CALL saves the return address on the stack.
 RET restores that address and resumes execution
after the CALL.
 Used for modular programming and code reuse.
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

4 Marks
1. Explain MACRO with suitable example. List four advantages of it

� What is a MACRO?

A MACRO in assembly language is a predefined sequence of instructions that can be


inserted into the program whenever needed, using a macro name. Unlike procedures (which
involve CALL and RET instructions), a macro’s code is directly expanded inline wherever it
is called.

Think of a macro like a template: when used, it’s copied into your code.

� Syntax of a MACRO:
asm
CopyEdit
MACRO_NAME MACRO
; Instructions
ENDM

� Example of a MACRO:

Let’s define a macro to add two numbers stored in registers:

asm
CopyEdit
ADD_NUMBERS MACRO
MOV AX, NUM1
ADD AX, NUM2
ENDM

.DATA
NUM1 DW 0005H
NUM2 DW 0003H

.CODE
START:
ADD_NUMBERS ; Macro call (gets expanded here)
; AX now contains NUM1 + NUM2
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

When the assembler sees ADD_NUMBERS, it replaces it with:

asm
CopyEdit
MOV AX, NUM1
ADD AX, NUM2

So the macro is expanded inline during assembly.

� Four Advantages of MACROs:

Advantage Explanation
1 ⃣ Code Reusability Avoids rewriting the same instructions multiple times.
No CALL and RET overhead like procedures — macro code is
⃣ Faster Execution
expanded inline.
⃣ Improves Makes code cleaner and easier to understand by hiding complex
Readability logic.
⃣ Easy Maintenance Changing the macro definition updates all its uses automatically.

� Note:

 Macros increase the size of the code because they are expanded each time they are
used.
 For large and frequently used code, procedures may be better.

2. Differentiate between Procedure and Macros


Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

3. Write an ALP for Z = (A + B) * (C+ D) using PROCEDURE

Here's an 8086 Assembly Language Program (ALP) using a procedure to compute the
expression:

Z = (A + B) * (C + D)

We'll:

 Use memory variables for A, B, C, D, and Z.


 Use two procedures:
o One for addition
o One for multiplication
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

� ALP with Procedures:


asm
CopyEdit
.MODEL SMALL
.STACK 100H

.DATA
A DB 2 ; Example values
B DB 3
C DB 4
D DB 5
Z DW 0 ; Result is 16-bit, since product may exceed 8 bits

.CODE
MAIN:
MOV AX, @DATA
MOV DS, AX

; Call ADD1 to calculate A + B


CALL ADD1 ; Result in AL

MOV BL, AL ; Save A + B in BL

; Call ADD2 to calculate C + D


CALL ADD2 ; Result in AL

MOV CL, AL ; Save C + D in CL

; Call MULT to calculate (A + B) * (C + D)


CALL MULT ; Result in AX

; Store result in Z
MOV Z, AX

; Exit
MOV AH, 4CH
INT 21H

; ---------------------------
; Procedure: ADD1 = A + B
; ---------------------------
ADD1 PROC
MOV AL, A
ADD AL, B
RET
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

ADD1 ENDP

; ---------------------------
; Procedure: ADD2 = C + D
; ---------------------------
ADD2 PROC
MOV AL, C
ADD AL, D
RET
ADD2 ENDP

; ---------------------------
; Procedure: MULT = BL * CL
; ---------------------------
MULT PROC
MOV AL, BL
MUL CL ; Unsigned multiply: AL * CL -> result in AX
RET
MULT ENDP

END MAIN

� Explanation:

 ADD1 adds A + B and returns result in AL.


 ADD2 adds C + D and returns result in AL.
 MULT multiplies values in BL and CL and stores result in AX.
 Final result Z = (A + B) * (C + D) is stored in the memory variable Z.

4. Write an ALP for Z = (P + Q) * (R + S) using MACRO. Draw flow


chart of the same.

� 8086 Assembly Language Program using MACRO


To compute:

Z = (P + Q) * (R + S)

We'll define two macros:


Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

 One for addition


 One for multiplication

� ALP Code Using MACRO


asm
CopyEdit
.MODEL SMALL
.STACK 100H

.DATA
P DB 2
Q DB 3
R DB 4
S DB 5
Z DW 0 ; Result is 16-bit because multiplication can exceed 8 bits

.CODE
; Define ADD macro (adds two variables and stores result in AL)
ADD_MACRO MACRO VAR1, VAR2
MOV AL, VAR1
ADD AL, VAR2
ENDM

; Define MUL macro (multiplies AL and another register, result in AX)


MUL_MACRO MACRO REG
MUL REG ; Unsigned multiply: AL * REG, result in AX
ENDM

MAIN:
MOV AX, @DATA
MOV DS, AX

; ---- Compute (P + Q) ----


ADD_MACRO P, Q ; AL = P + Q
MOV BL, AL ; Store in BL

; ---- Compute (R + S) ----


ADD_MACRO R, S ; AL = R + S
MOV CL, AL ; Store in CL

; ---- Multiply (P+Q) * (R+S) ----


MOV AL, BL ; AL = (P + Q)
MUL_MACRO CL ; AX = (P + Q) * (R + S)
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

; ---- Store result in Z ----


MOV Z, AX

; ---- Exit ----


MOV AH, 4CH
INT 21H

END MAIN

� Flowchart for Z = (P + Q) × (R + S)
Here’s a simple textual representation of the flowchart:

pgsql
CopyEdit
┌───────────────┐
│ Start Program │
└──────┬────────┘


┌────────────────────┐
│ Load P and Q │
│ Compute A = P + Q │
└────────┬───────────┘


┌────────────────────┐
│ Load R and S │
│ Compute B = R + S │
└────────┬───────────┘


┌──────────────────────────┐
│ Compute Z = A × B │
└────────┬─────────────────┘


┌────────────────────┐
│ Store Z in memory │
└────────┬───────────┘


┌─────────────┐
│ End Program │
└─────────────┘
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

5. Write a MACRO to perform 32 bit by 16 bit division of unsigned numbers

� Purpose:

To divide a 32-bit unsigned dividend by a 16-bit unsigned divisor, and obtain:

 16-bit Quotient
 16-bit Remainder

� Registers Used:

 Dividend:
o High 16 bits in DX
o Low 16 bits in AX
 Divisor: in CX
 Result:
o Quotient → AX
o Remainder → DX

� MACRO Definition:
asm
CopyEdit
DIV32_16 MACRO
; Assumes:
; - 32-bit dividend in DX:AX
; - 16-bit divisor in CX
; Result:
; - Quotient in AX
; - Remainder in DX
DIV CX ; Performs (DX:AX) ÷ CX
ENDM

� Example Usage:
asm
CopyEdit
Institute Code & Name: SANJAY GHODAWAT INSTITUTE,
ATIGRE (1644)
Question Bank (K scheme)
Name of subject: MICROPROCESSOR ALL CHAPTERS
Subject code: 314321 Course :CW
Semester: IV

CHAPTER 5: Procedure and MACRO (CO5) (10 Marks)

.MODEL SMALL
.STACK 100H

.DATA
; 32-bit dividend: 00020001h (i.e., 131073 in decimal)
; Divisor: 100h (i.e., 256 in decimal)
RESULT DW 0
REMAINDER DW 0

.CODE
MAIN:
MOV AX, @DATA
MOV DS, AX

; Load 32-bit dividend into DX:AX


MOV DX, 0002H ; High word
MOV AX, 0001H ; Low word

MOV CX, 0100H ; Divisor (256)

DIV32_16 ; Macro call to perform 32-bit ÷ 16-bit

; Store results
MOV RESULT, AX ; Quotient
MOV REMAINDER, DX ; Remainder

; Exit
MOV AH, 4CH
INT 21H

END MAIN

� Explanation:

 DIV CX is the instruction that performs (DX:AX) ÷ CX.


 The 8086 handles 32-bit ÷ 16-bit division using this format:
o Dividend: DX:AX (64K × 64K = 4GB range)
o Divisor: any 16-bit register (CX in this case)
o Quotient → AX
o Remainder → DX

You might also like