0% found this document useful (0 votes)
28 views21 pages

Macro Procedure

This document discusses macros and procedures in assembly language. It explains that PROC and ENDP directives are used to indicate the start and end of a procedure. A NEAR procedure resides in the same code segment while a FAR procedure can be located anywhere in memory. Macro is a group of instructions defined with MACRO and ENDM. On calling a macro, object code is generated for each call while a procedure's code is generated only once. Some common BIOS interrupts for input, output and time functions are also outlined. Examples are given to display a character at the screen center using interrupts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views21 pages

Macro Procedure

This document discusses macros and procedures in assembly language. It explains that PROC and ENDP directives are used to indicate the start and end of a procedure. A NEAR procedure resides in the same code segment while a FAR procedure can be located anywhere in memory. Macro is a group of instructions defined with MACRO and ENDM. On calling a macro, object code is generated for each call while a procedure's code is generated only once. Some common BIOS interrupts for input, output and time functions are also outlined. Examples are given to display a character at the screen center using interrupts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

MACRO AND PROCEDURES

Dr.Rekha.K.S
Associate Professor
Dept of cs&E,NIE
PROC and ENDP
• Indicate start and end of a procedure
(subroutine).
– they force structure because the procedure is
clearly defined
• If structure is to be violated for whatever
reason, use the CALLF, CALLN, RETF, and RETN
instructions.
• Both the PROC and ENDP directives require a
label to indicate the name of the procedure.
• The PROC directive, which indicates the start of
a procedure, must also be followed with a
NEAR or FAR.
– A NEAR procedure is one that resides in the same
code segment as the program, often considered to
be local
– A FAR procedure may reside at any location in the
memory system, considered global
• The term global denotes a procedure that can
be used by any program.
• Local defines a procedure that is only used by
the current program.
DIPLAY PROC
MOV AH,9
INT 21H
RET
DISPLAY ENDP
Macro
• Macro is a group of instructions and it can be
defined by MACRO and ENDM directives.
• MACRO is used at the beginning of the Macro
and ENDM is used at the end of the Macro
• EX: Read MACRO
• MOV AH,1
• INT 21H
• ENDM
Read.mac
READ MACRO
MOV AH,08H
INT 21H
ENDM

Disp.mac
DISP MACRO
MOV AH,2
INT 21H
ENDM
Difference between
Procedure & MACRO
• Macro
• More memory is required
• Object code is generated for each macro call
• Macro name is used to access Macro
• Procedure
• Less memory is required
• Object code is generated only once
• CALL and RET instructions to access a procedure
Functions used in Programs
• Function 01H : Read character from standard
input device
• AH=01H
• AL= 8 bit input data(ascii code of input data)

• Mov AH,01H
• INT 21H
• Function 02H : write character to standard
output device
• AH =02H
• DL = 8 bit output data (ASCII Code)
• MOV AH,02H

• FUNCTION 09H :Display String


• AH=09H
• DX=Offset of string to be displayed to be
terminated by $
• Function 2CH get DOS system time
• AH = 2ch
• CH= Hour
• CL=Minutes
• DH=Seconds
• DL 100th of second

• Function 4CH;Terminate with return code EXIT(n)


• AH=4CH
• AL=Return code
Write a program to set cursor at the centre of the
screen using BIOS Interrupt

.Code
MOV AX,@DATA
MOV DS,AX
MOV BH,0 ; Current page number
MOV AH,02H ; Service number(set cursor position)
MOV DH,12 : row number
MOV DL,40 ;column number
INT 10H ; BIOS Call to set cursor
INT 21H
END
Write a program to set cursor at the centre of the
screen & display a character at the centre of the screen

.data
Char db ‘s’
.Code
MOV AX,@DATA
MOV DS,AX
MOV BH,0 ; Current page number
MOV AH,02H ; Service number(set cursor position)
MOV DH,12 : row number
MOV DL,40 ;column number
INT 10H ; BIOS Call to set cursor
MOV,DL,CHAR
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
END
• Write an ALP Macros
• 1) to read a character from the keyboard in
Macro1(in a different file)
• 2) to display a character in Macro2( in a
different file)
• 3) use the above 2 macros to read a string of
characters from the keyboard terminated by
carriage return.
Read.mac
READ MACRO
MOV AH,08H
INT 21H
ENDM

Disp.mac
DISP MACRO
MOV AH,2
INT 21H
ENDM
INCLUDE READ.MAC
INCLUDE DISP.MAC
.MODEL SMALL
.DATA
MSG DB 10,13 “enter any string” 10,13, “ $”
.CODE
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG
MOV AH,9
INT 21H
REP : READ
CMP AL,0DH
JZ DONE
DISP
JMP REPEAT
DONE: MOV AH,4CH
INT 21H
(SHR AL,CL) ->SHIFT AL BY 4 NUMBER OF TIME
04
0000 0100
0000 0010
0000 0001
0000 0000

1
AND BL,0FH
BL=04
0000 0100
0000 1111
---------------
0000 0100
Read an alphanumeric character and display its equivalent ASCII Code at
the center of the screen
• Data
MSG DB “press esc to exit$”
MSG1 DB 10,13, “enter any alphanumeric character $”
Esc1 DB 27
Res DB “ $”
.code
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG
MOV AH,09H
INT 21H
LEA DX,MSG1
MOV AH,09H
INT 21H
START: MOV AH,8
INT 21H
CMP AL,ESC1
JE EXIT
MOV BL,AL
MOV CL,4
SHR AL,CL
CMP AL,0AH
JC DIGIT
ADD AL,07
DIGIT: ADD AL,30
MOV RES,AL
AND BL,0FH
CMP BL,0AH
JC DIGIT1
ADD BL,7
DIGIT1: ADD BL,30H
MOV RES+1,BL
MOV AH,2
MOV BH,0
MOV DH,12
MOV DL,40
INT 10H
LEA DX,RES
MOV AH,09H
INT 21H
JMP START
EXIT : MOV AH,4CH
INT 21H
END

You might also like