Professional Documents
Culture Documents
2 3 2
L A B 3 :
D O S
I N T E R R U P T S
Instructor: Dr Syed Misbahuddin Objectives: To introduce the students to: DOS functions 01H , 02H, 08H, 09H, 40H, and 0AH. Debugging the program using Microsoft CodeView program.
Example: Sub-function 09H of Interrupt 21H displays a $-terminated string on the screen. The sub-function requires the offset of that string to be passed in the DX register: MOV DX , OFFSET STRING MOV AH , 09H INT 21H Note: DPMI (DOS Protected Mode Interface) is an interface allowing a DOS program to run in protected mode and to access extended memory under a multitasking operating system like Microsoft Windows 3.0 and later.
D. CHARACTER OUTPUT
To display a character, you have to use the DOS function 02h. The Initial requirement AH = 02h DL = Character or ASCII Code The result The character stored in DL will be displayed.
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
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
0Dh stored in this byte if the length of the string is 50 50 bytes 51 bytes
Actual string length is stored in this byte To read a string from the keyboard into an array called BUFFER as defined above, we invoke DOS function 0AH as: MOV AH , 0AH MOV DX , OFFSET STRING INT 21H 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. To display the above array generally by using DOS function 40H: MOV AH, 40H MOV BX, 01H MOVZX CX, STRING[1] MOV DX, OFFSET STRING[2] INT 21H ; file handle for the screen ; Initialize CX with the string length
LAB EXERCISES:
1. Type the following program and name it as PROG31.ASM. Assembly and link the program. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 .586 DOSSEG OPTION SEGMENT: USE16 .MODEL SMALL .STACK 64 .DATA MESSAGE DB 13, 10, 'Hello! What''s your name please? $' CUSTOMER DB 31, 32 dup(0) Msg1 DB 'Mr. $' Welcome DB ' studies 8086 Assembly language programming.$' .CODE .STARTUP ; Display the string mov AH , 9 mov DX , OFFSET MESSAGE int 21h ; Read a string mov AH, 10 mov DX, OFFSET CUSTOMER int 21h mov AH, 9 mov DX, OFFSET Msg1
23 24 25 26 27 28 29 30 31 32 33 34
int 21h mov AH, 40H mov BX, 01H ; file handle for the screen movzx CX, CUSTOMER[1] ; Initialize CX with the string length mov DX, OFFSET CUSTOMER[2] int 21h mov AH, 9 mov DX, OFFSET welcome int 21h mov AX , 4C00h int 21h END
2. Write an EXE-format assembly language program that prompts for and reads a users name USERNAME (of maximum length 30 characters). It then displays a message of the form: Mr. USERNAME studies Assembly language programming. Mr. USERNAME is a student of ICS Department at KFUPM. Example: Hello, What's your name please? Ghozy Baalawy Abu Soso Mr. Ghozi Baalawy Abu Soso studies 8086 Assembly language programming. Mr. Ghozi Baalawy Abu Soso is a student of Computer Science Department in UOH