DOS is an old operating system that was used on computers before
Windows. It had a text-based screen no icons, no mouse, only commands.
Role of DOS in Assembly Language
When we use INT 21h, we are calling the functions of DOS, such as:
09h → Print a string
01h → Take input from the keyboard
02h → Display a single character
4Ch → Exit the program
Meaning:
In assembly language, we are basically telling DOS:
"You do this task for us!"
,Line-by-Line Explanation:
.model small
This tells the compiler that the program will use the Small Memory
Model. In this model, the Code segment is 64KB and the Data segment is
64KB a small, simple, and perfect model for beginners.
.stack 100h
This reserves stack memory; 100h = 256 bytes.
The stack is used to hold temporary data, return addresses, parameters,
etc.
.data
Here we declare our variables.
S1 db "Helloworld$"
S1 is a string variable.
"Helloworld$" is the text we want to print on the screen.
The $ sign indicates the end of the string (it tells the DOS interrupt
where the string finishes).
.code
This is where the actual instructions start.
main proc
This declares the main function of the program.
mov ax, @data
The address of the Data Segment is loaded into the AX register.
, mov ds, ax
Now DS is set equal to AX.
This means the Data Segment is activated, and we can now access S1.
lea dx, s1
Meaning of LEA: Load Effective Address
It loads the address of string S1 into the DX register.
Now DOS interrupt knows where the string is stored and from where it
should read it.
mov ah, 9
AH = 09h means:
We want to use DOS function 09h, which is the Display String function.
INT 21h
Interrupt 21h runs function 09h,
and it prints "Helloworld" on the screen.
mov ah, 4Ch
Function 4Ch = Terminate Program
INT 21h
This properly exits the program.
main endp / end main
Both the function and the program are closed.