Assignment No.1
Assignment No.1
Disadvantages:
1. Extra code may be required to integrate procedures.
2. Liking of procedures may be required.
3. Processor needs to do extra work to save status of current procedure and load status
of called procedure. The queue must be emptied so that instructions of the procedure
can be filled in the queue.
Macros:
Whenever it is required to use a group of instructions several times in a program, there
are two ways to use that group of instructions: One way is to write the group of instructions as
a separate procedure. We can call the procedure whenever it is required to execute that group
of instructions. But disadvantage of using a procedure is we need stack. Another disadvantage
is that time is required to call procedures and return to calling program. When the repeated
group of instruction is too short or not suitable to be implemented as a procedure, we use a
MACRO. A macro is a group of instructions to which a name is given. Each time a macro is
called in a program, the assembler will replace the macro name with the group of instructions.
Advantages:
1. Macro reduces the amount of repetitive coding.
2. Program becomes more readable and simpler.
3. Execution time is less as compared to calling procedures.
4. Reduces errors caused by repetitive coding.
Disadvantage:
Examples:
Program using procedures:
ASSUME CS:CODE, DS:DATA, SS:STACK_SEG
DATA SEGMENT
NUM1 DB 50H
NUM2 DB 20H
ADD_RES DB ?
SUB_RES DB ?
DATA ENDS
STACK_SEG SEGMENT
DW 40 DUP(0) ; stack of 40 words, all initialized to zero
TOS LABEL WORD
STACK_SEG ENDS
CODE SEGMENT
START: MOV AX, DATA ; initialize data segment
MOV DS, AX
MOV AX, STACK_SEG ; initialize stack segment
MOV SS, AX
MOV SP, OFFSET TOS ; initialize stack pointer to TOS
CALL ADDITION
CALL SUBTRACTION
MOV AH, 4CH
INT 21H
ADDITION PROC NEAR
MOV AL, NUM1
MOV BL, NUM2
ADD AL, BL
MOV ADD_RES, AL
RET
ADDITION ENDP
SUBTRACTION PROC
MOV AL, NUM1
MOV BL, NUM2
SUB AL, BL
MOV SUB_RES, AL
RET
SUBTRACTION ENDP
CODE ENDS
END START