Program:Computer Engineering
Microprocessors (22415)
5. Procedure and Macro
1.Define MACRO, Give an example indicating how
a MACRO can be used in 8086 ALP.
Ans:Macro: Small sequence of the codes of the same
pattern are repeated frequently at different places which
perform the same operation on the different data of
same data type, such repeated code can be written
separately called as Macro.
When assembler encounters a Macro name later in the The recursive procedures keep on
source code, the block of code associated with the executing until the termination
Macro name is substituted or expanded at the point of condition is reached. The recursive
call, known as macro expansion.
procedures are very effective to use and
Macro called as open subroutine 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.
2.Describe recursive procedure &reentrant
procedure with the help of schematic diagram.
Ans:1)Recursive
procedure :A recursive procedure is
procedure which calls itself. This
results in the procedure call to be
This is called a re-entrant procedure because a
generated from within the procedures procedure is re-entering into itself form another
again and again. This can be understood procedure which is also present inside its own body.
The re-entrant procedure occurs in the following
as follows: three conditions: when the procedure is undergoing
recursion, when multi-threading is being implemented
inside a program or when some interruption is being
generated. Like the recursive procedures, it is important
to have a termination condition for the procedures in
the re-entrant procedures also, else we can face
machine halts due to infinite procedure calls.
Page 1 of 4
Program:Computer Engineering
Microprocessors (22415)
3.Explain NEAR CALL and FAR CALL procedure. 5. ALP to add two numbers using procedure.
( Any four points 1 Mark each)
Ans:.model small
Ans: .data
NEAR call FAR call num1 db 12h
num2 db 13h
A near call is a call to A far call is a call to procedure
procedure which is in ends
which is in same code
segment different segment .code
start:
The contents of CS is The contents of CS is also
not stored stored along mov ax,@data
with offset.
mov ds,ax
In near call contents In Far call contents of SP are
call add1
of SP is decremented
decremented by 2 and by 2 and value of CS is loaded. add1 proc near
contents of Then SP is
offset address IP is again decremented by 2 and IP mov al,num1
stored is loaded.
mov bl,num2
Example : CALL Example :CALL FAR PTR add al,bl
Delay Delay
add1 endp
mov ah,4ch
int 21h
4. Write the difference between PROCEDURE and
MACRO. (Any 4 points – 1Mark each) ends
Ans:
end start
Sr. PROCEDURE MACRO
no end
1 Accessed by CALL Accessed during
and RET instruction assembly with name 6. ALP to add two numbers using Macro.
during program given to Macro when
execution. defined. Ans:.model small
2 Machin code for Machine code is
instructions in put generated for add_num macro no1,no2
only once in the instructions each time
memory. when macro is called. mov ax,no1
3 With procedure less With macro more
memory is required. memory is required. add ax,no2
4 Parameters can be Parameters passed as
passed in register, part of statement which endm
Memory location or calls macro.
Stack. .data
num1 dw 1234h
num2 dw 4321h
Page 2 of 4
Program:Computer Engineering
Microprocessors (22415)
res dw ? int 21h
.code find_resendp
mov ax,@data ends
mov ds,ax end
add_num num1,num2 8.ALP using macro to solve equation : Z = (A+B) *
(C+D)
ends
Ans:.model small
end
add_no1 macro a,b,res_add1
7. ALP using procedure to solve equation : Z =
(A+B) * (C+D) mov al,a
Ans: .model small add al,b
.data mov res_add1,al
a db 02h endm
b db 03h
c db 04h add_no2 macro c,d,res_add2
d db 05h mov al,c
z dw ? add al,d
ends mov res_add2,al
.code endm
mov ax,@data multiply_num macro res_add1,res_add2
mov ds,ax mov al,res_add1
call find_res mul res_add2
find_resproc near endm
mov al,a .data
mov bl,b a db 02h
mov cl,c b db 03h
mov dl,d c db 04h
add al,bl d db 05h
add cl,dl res_add1 db ?
mul cl res_add2 db ?
mov ah,4ch ends
Page 3 of 4
Program:Computer Engineering
Microprocessors (22415)
Page 4 of 4