-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDisplay_String_Using_Macro.asm
More file actions
47 lines (42 loc) · 1.98 KB
/
Display_String_Using_Macro.asm
File metadata and controls
47 lines (42 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
; =================================================================================================
; AUTHOR : Amey Thakur
; REPOSITORY : https://github.com/Amey-Thakur/MICROPROCESSOR-AND-MICROPROCESSOR-LAB
; DESCRIPTION : 8086 Assembly program to display a string using a Macro.
; -------------------------------------------------------------------------------------------------
; WHAT IS A MACRO?
; A macro is like a "shortcut" or a "template" for code. Instead of writing the same 3 or 4
; lines every time you want to print a message, you define a macro once and just use its
; name whenever you need it. The assembler "copies and pastes" the actual code for you.
;
; HOW IT WORKS:
; 1. Define a macro named 'DISPLAY_STR' that takes one argument (the message to print).
; 2. In the main program, simply "call" the macro by writing its name followed by the message.
; 3. This makes the code much cleaner and easier to read.
; =================================================================================================
; --- MACRO DEFINITION ---
; This is our reusable template for displaying strings.
DISPLAY_STR MACRO MSG
LEA DX, MSG ; Load the memory address of the message into the DX register
MOV AH, 09H ; DOS function: Display a '$'-terminated string
INT 21H ; Trigger the interrupt to perform the display
ENDM
DATA SEGMENT
MES1 DB 10, 13, " ------------------------------"
DB 10, 13, " DISPLAYING STRING USING MACRO"
DB 10, 13, " ------------------------------$"
MES2 DB 10, 13, " HELLO! THIS PROGRAM WAS BUILT USING REUSABLE MACROS.$"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA, CS:CODE
START:
; -- Initialization --
MOV AX, @DATA
MOV DS, AX
; -- Using the Macro --
DISPLAY_STR MES1 ; The assembler replaces this line with the code from the macro
DISPLAY_STR MES2 ; It also replaces this with the same code, but for MES2
; -- Exit Program --
MOV AH, 4CH
INT 21H
CODE ENDS
END START