Professional Documents
Culture Documents
Dos Function Calls (Int 21H) : A. Terminate Program and Return To Dos
Dos Function Calls (Int 21H) : A. Terminate Program and Return To Dos
Dos Function Calls (Int 21H) : A. Terminate Program and Return To Dos
DOS function calls preserve the contents of all the registers except the AX register and any
other register or registers in which they explicitly return data.
D. CHARACTER OUTPUT
To display a character, you have to use the DOS function 02h.
Example:
The following code fragment will display a string 'Hey'.
mov DL, 'H'
mov AH, 2
int 21h
mov DL, 'e'
mov AH, 2
int 21h
mov AH, 2
mov DL, 'y'
int 21h
There are some special characters that will give special effect when displayed.
Character Name Meaning
7 Bell Sounds beep
8 Backspace (\b) Moving the cursor one position backward.
9 Horizontal Tab (\t) Moving the cursor 5 position forward
10 Line feed (\n) Moving the cursor to the next line
13 Carriage return (\r) Moving the cursor to the beginning of the line
Example:
The following code fragment will move the cursor to the beginning of the next output line:
mov AH, 02H
mov DL, 0DH
int 21H
mov DL, 0AH
mov AH, 2
int 21H
Example:
DATA
...
STRING_NAME DB 'THE STRING TO BE DISPLAYED$'
...
CODE
MOV AH , 09H
MOV DX , OFFSET STRING_NAME
INT 21H
Note:
If the terminating $ is omitted, the operation displays characters in the memory, after the
string, until it finds a $ character, if any.
To move the cursor to the beginning of the next output line, after displaying a string, put
0Dh and 0Ah after the string and before the terminating $. Example:
PROMPT DB 'PLEASE, ENTER YOUR NAME: ' , 0Dh , 0Ah , '$'
Another way of moving the cursor to the beginning of the next output line is to display ,
using DOS function 09H, a string of the form:
STRING1 DB 0Dh , 0Ah , '$'
Example:
.DATA
...
STRING_NAME DB 'THE STRING TO BE DISPLAYED'
STRINGLEN EQU $ – STRING_NAME
...
.CODE
...
MOV AH , 40H
MOV BX , 01H
MOV CX , STRINGLEN ; string length
MOV DX , OFFSET STRING_NAME
INT 21H
The EQU directive defines a value that the assembler can use to substitute in other
instructions.
An operand containing a dollar symbol, $, refers to the current value in the location
counter. Thus, in the above example $ - STRING_NAME evaluates to the number of
bytes between STRING_NAME and STRINGLEN which is the number of bytes (i.e.,
characters) in ‘THE STRING TO BE DISPLAYED’
The program will wait for the input. The user must press "Enter" key to end the inputting
process. This is the reason for the point d above.
Example:
Define an array called STRING to store a string of maximum length 50 characters to be used by
the service 0Ah of INT 21h.
Solution:
STRING DB 51, 52 DUP(?)
52 bytes
The operation echoes the entered characters on the screen and advances the cursor. If more
characters than the specified maximum (in byte 0) are entered, the speaker beeps and the
additional characters are not read.