Displaying a string using DOS interrupt 21H function 09H is a straightforward way to print messages to the screen in 8086 assembly language. This blog post explores an 8086 assembly program that prints the string ‘hello’ to the console.
data segment msg1 db 'hello$' data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov sp,0d00h mov ah,09h int 21h mov ax,4c00h int 21h int 3 code ends end start
Overall Process
The program initializes the necessary segments. It loads the string ‘hello’ into memory and prints it using DOS interrupt 21H function 09H. The program successfully prints ‘hello’ on the console before terminating.
Step-by-Step Explanation
- Data Segment Initialization
msg1 db 'hello$'
stores the string ‘hello’ with$
as a termination character required by DOS.
- Code Execution Flow
mov ax, data
andmov ds, ax
: Initializes the data segment by loading its address into AX and then into DS.mov sp, 0d00h
: Sets up the stack pointer.mov ah, 09h
: Prepares for string output using DOS interrupt function 09H.lea dx, msg1
: Loads the offset of the string into DX register.int 21h
: Calls DOS interrupt 21H to print the string to the console.mov ax, 4c00h
andint 21h
: Terminates the program.int 3
: Generates a breakpoint interrupt.
Flowchart

Output
C:\TASM>masm an_hello.asm Microsoft (R) Macro Assembler Version 5.00 Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved. Object filename [an_hello.OBJ]: Source listing [NUL.LST]: Cross-reference [NUL.CRF]: 50394 + 450262 Bytes symbol space free 0 Warning Errors 0 Severe Errors C:\TASM>link an_hello.obj Microsoft (R) Overlay Linker Version 3.60 Copyright (C) Microsoft Corp 1983-1987. All rights reserved. Run File [AN_HELLO.EXE]: List File [NUL.MAP]: Libraries [.LIB]: LINK : warning L4021: no stack segment C:\TASM>debug an_hello.exe -g hello Program terminated normally -q
Summary of Output
- The program successfully prints ‘hello’ to the console.
- The string output is handled by DOS interrupt 21H with function 09H.
- The program terminates properly after execution.