Vous êtes sur la page 1sur 4

Birla Institute of Technology & Science, Pilani First Semester 2011-2012

IS C351: COMPUTER ORGANIZATION AND ARCHITECTURE Lab # 2


DOS Function Calls: These are the function calls for the purpose of achieving some standard I/O and file functionalities. In order to use DOS function calls, always place the function number in register AH and load other pertinent information into registers as described in the table as entry data. Once this is accomplished, follow with an INT 21H to execute the DOS function. MEMORY: The memory program. 1. 2. 3. 4. 5. 6.

model determines the size of the code, stack and data segments of the TINY - Code and data no more than 64K combined SMALL - Code and data segments must be no more than 64K each MEDIUM - Code can be more than 64K, data still limited to no more than 64K COMPACT Code limited to no more than 64K, data can be more than 64K LARGE - Code and data can each be more than 64K, no array can be larger than 64K bytes HUGE - Code and data can each be more than 64K, arrays can be larger than 64K bytes Directive is .data for data segment All variables must be declared Different data definition directives for different size chunks of memory DB - define byte (8 bits) DW - define word (16 bits) DD - define double word (32 bits) DQ - define quad word (64 bits) DT - define ten bytes (80 bits) Format for allocating memory: optional_label data_definition_directive value{, value, ...} Data definition directive can be followed by single value, or a comma separated list of values

o o o

o o

Familiarize yourself with the usage of the following DOS function calls: 01H, 02H, 06H, 07H, 08H, 09H , 0AH, 2AH, 2BH, 2CH, 2DH by solving the following problem: Note: You can visit to course web page for the complete list of DOS function calls. DOS provide certain simple operations to be performed by calling its functions. The assembly program may call these functions via the INT 21. The DOS function number is loaded in the 8-bit register AH. Now we will examine some DOS functions used to perform input-output operations. Some standard functions that you need are given here. Tasks for practice in Lab: 1. Input with echo on standard output AH=01 (function #01h) Ex: .model tiny .code .startup Mov ah, 01h Int 21h .exit End

2. Input without echo on the standard output AH= 07H (function #07h) Example: .model tiny .code .startup Mov ah,07h Int 21h .exit End 3. Write to standard output device AH= 02H (function #02h) Example: .model tiny .code .startup Mov ah,02 Mov dl, a ; ASCII charcter to be displayed Int 21h .exit End 4. Input a line from the standard input AH= OAH DS=segment of buffer into which input stream is to be stored DX=offset of buffer First byte of buffer= Max number of characters that can be read-supplied by the user. Example: .model tiny .data message db 100 dup($) ; All bytes initialized by $ .code .startup Mov dx,offset message Mov ah,0ah Int 21h .exit End 5. Display a $ terminated string AH= 09H DS= segment of buffer into which character string is stored DX=starting offset of buffer NOTE: The Character string must end with an ASCII $ (24h) Example: .model small .data message db "Displaying a string",0dh,0ah,"$" .code .startup mov ah,9 mov dx,offset message int 21h .exit End

6. Sample program using OAH, 09H The following program takes a string as an input from the standard input and echoes it back to the standard output. .model tiny .data message db 100 dup($) .code .startup ;read the input string Mov dx,offset message Mov ah,0ah Int 21h ; carriage return (0dh) and line feed (0ah), otherwise the input will be ;overwritten by the output string. Mov ah,02h Mov dl,0dh Int 21h Mov ah,02h Mov dl,0ah Int 21h ;print the string Mov dx,offset message Add dx,2 Mov ah,09h Int 21h .exit End Note: To store 100 characters (terminated by $). Buffer size requirement is 104 bytes. First byte of the buffer must be initialized with 104, indicates total size of the buffer. Remaining 103 bytes have to initialize with $. Second byte of the buffer will contains number of characters supplied by the user. One byte is needed to store Return Key. Test Your Self: 1) Write a program that reads input from the keyboard a series of 3 uppercase letters and converts each character to lowercase and then displays the converted characters on to the screen. Note: the upper case letter should not be displayed 2) Write a program that takes a single character from user and displays the message whether it is a vowel or not. 3) Write a program that takes a line as input from user and counts the number of vowels and consonants in the line. 4) Write a program to take a string as input from user and print it in reverse order. 5) Write a program that reads input from the keyboard a single alphabet character and displays (echoes) it back on the screen all the alphabets up to Z/z starting from the input character. It also has to do error check for a valid input character. 6) Dos function 2AH is used to read the system date, it return: CX = year (1980-2099) DH = month DL = day AL = day of week (00h=Sunday) with INT 21H. Write a

program which finds that whether the current year has a month of February with 28 days or 29 days and prints a message accordingly. 7) Write a program that inputs a string using DOS function 0AH. After that it should display, a count on the screen of the actual number of characters typed by the user. 8) Write a program that uses DOS function 2AH to get and display the system date. Use the following display format: yyyy-mm-dd **********************************************************

Vous aimerez peut-être aussi