Past exam question: 2081 Chaitra (Regular), Q5
Open in the Padhaiko appQuestion
Write an Assembly language programming in 8086 to display "Programming is Fun" in screen.
Solution
Program Design & DOS Function Used: To display a text string on the screen in 8086 MS-DOS assembly:
- We use the DOS function
INT 21HwithAH = 09H(Print String). - Requirements for
AH = 09H:DS:DXmust point to the starting address of the string in memory.- The string must terminate with the character
'\$'(24H).
- Program termination:
- We use DOS function
INT 21HwithAH = 4CH(Exit to DOS).
- We use DOS function
Complete 8086 Assembly Language Program:
.MODEL SMALL
.STACK 100H
.DATA
; Declare the string terminated by '$'
MSG DB 'Programming is Fun$'
.CODE
MAIN PROC
; 1. Initialize the Data Segment register (DS)
MOV AX, @DATA
MOV DS, AX
; 2. Load the offset address of MSG into DX
LEA DX, MSG
; 3. Call DOS Function 09H to display string
MOV AH, 09H
INT 21H
; 4. Terminate the program and return control to DOS
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAINStep-by-Step Code Explanation:
.MODEL SMALL: Selects standard memory model with one code segment (<=64KB) and one data segment (<=64KB).MSG DB 'Programming is Fun\$': Allocates memory bytes containing ASCII characters for "Programming is Fun", followed by the required'\$'string terminator.MOV AX, @DATAandMOV DS, AX: Loads the base address of the.DATAsegment into AX and transfers it to DS (since segment registers cannot be loaded directly with immediate values).LEA DX, MSG: Loads the 16-bit offset address of the message into DX. (Equivalent toMOV DX, OFFSET MSG).MOV AH, 09Hfollowed byINT 21H: Triggers the DOS service dispatcher, which iterates through characters at DS:DX and prints each to standard output until encountering'\$'.MOV AH, 4CHfollowed byINT 21H: Safely releases resources and exits to the DOS command prompt.
Answer:
The 8086 program declares the string 'Programming is Fun$' in the data segment, initializes DS with @DATA, loads DX with the string offset using LEA DX, MSG, and invokes DOS service INT 21H with AH=09H to display the text, followed by AH=4CH to terminate.