PadhaikoAll subjects

Past exam question: 2081 Chaitra (Regular), Q5

Microprocessors · 6 marks

Open in the Padhaiko app

Topic: 8086 Programs: Arithmetic, Strings, I/O, Number Display

Question

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:

Complete 8086 Assembly Language Program:

8086 Display String on Screen8086 ASM
.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 MAIN

Step-by-Step Code Explanation:

  1. .MODEL SMALL: Selects standard memory model with one code segment (<=64KB) and one data segment (<=64KB).
  2. MSG DB 'Programming is Fun\$': Allocates memory bytes containing ASCII characters for "Programming is Fun", followed by the required '\$' string terminator.
  3. MOV AX, @DATA and MOV DS, AX: Loads the base address of the .DATA segment into AX and transfers it to DS (since segment registers cannot be loaded directly with immediate values).
  4. LEA DX, MSG: Loads the 16-bit offset address of the message into DX. (Equivalent to MOV DX, OFFSET MSG).
  5. MOV AH, 09H followed by INT 21H: Triggers the DOS service dispatcher, which iterates through characters at DS:DX and prints each to standard output until encountering '\$'.
  6. MOV AH, 4CH followed by INT 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.

All past exam questions for Microprocessors