Chapter – 6
Introduction to Computer Basics
Introduction
Some times, in some cases when you are trying to recover the data or you are performing any data and disk troubleshooting task (or it may be any other system related task) it is very convenient to use DEBUG command of DOC.
Also it may be possible for some particular cases that you feel it easy to do that particular task with the help of DEBUG then with programming. Let us take an example. The following coding of debug will be sufficient to make the back up of DBR. Just type the followings lines:
DEBUG BKDBR.BIN
L 100 2 0 1
R CX
200
W
Q
Here you can see that only by typing the above few lines you can avoid to write a program. Let us see another example of coding that loads the backup copy of DBR to the disk
Always remember! Do not try this without the complete knowledge. Be sure what you are going to do. A careless use of the following Instructions may cause a big data loss as the misuse of Instruction may cause all your information of the disk inaccessible.
DEBUG BKDBR.BIN
W 100 2 0 1
Q
By seeing the coding of this example you can easily guess how much it may help you when you need it most. Also it is not possible to do programming in every situation. However within a limit of simple cases of the problem, to use assembly Instructions, you have to just copy the debug.exe/debug.com in your boot disk and start writing the code.
The functioning and the described examples in this chapter and in this book are compatible with x86 Intel Processor Family architecture only.
First of all we need to get a little knowledge of computer architecture basics to understand the terms used in the coming sections while describing the functioning and examples in different steps. Let us know some computer architecture basics:
Basic concepts
Central Processor
This part is also known as central processing unit or CPU, which in turn is made up by the control unit and the arithmetic and logic unit. Its functions consist in reading and writing the contents of the memory cells, to forward data between memory cells and special registers, and decode and execute the Instructions of a program. The processor has a series of memory cells which are used very often and thus, are part of the CPU.
These cells are known with the name of registers. A processor may have one or two dozens of these registers. The arithmetic and logic unit of the CPU realizes the operations related with numeric and symbolic calculations.
Typically these units only have capacity of performing very elemental operations such as, the addition and subtraction of two whole numbers, whole number multiplication and division, handling of the registers' bits and the comparison of the content of two registers. Personal computers can be classified by what is known as word size, this is, the quantity of bits which the processor can handle at a time.
Central Memory
It is a group of cells, fabricated with semi-conductors, used for general processes, such as the execution of programs and the storage of information for the operations. Each one of these cells may contain a numeric value and they have the property of being direction able. This is that they can distinguish one from another by means of a unique number or an address for each cell. The generic name of these memories is Random Access Memory or RAM.
The main disadvantage of this type of memory is that the integrated circuits lose the information they have stored when the electricity flow is interrupted. This was the reason for the creation of memories whose information is not lost when the system is turned off. These memories receive the name of Read Only Memory or ROM.
In order for the PC to process information, it is necessary that this information be in special cells called registers. The registers are groups of 8 or 16 flip-flops.
A flip-flop is a device capable of storing two levels of voltage, a low one, regularly 0.5 volts, and another one, commonly of 5 volts. The low level of energy in the flip-flop is interpreted as off or 0, and the high level as on or
- These states are usually known as bits, which are the smallest information unit in a computer.
A group of 16 bits is known as word; a word can be divided in groups of 8 bits called bytes, and the groups of 4 bits are called nibbles.
CPU Registers
The CPU has 4 internal registers, each one of 16 bits. The first four, AX, BX, CX, and DX are general use registers and can also be used as 8 bit registers, if used in such a way it is necessary to refer to them for example as: AH and AL, which are the high and low bytes of the AX register. This nomenclature is also applicable to the BX, CX, and DX registers.
The registers known by their specific names:
Register |
Specific Name |
AX |
Accumulator |
BX |
Base register |
CX |
Counting register |
DX |
Data register |
DS |
Data segment register |
ES |
Extra segment register |
SS |
Battery segment register |
CS |
Code segment register |
BP |
Base pointers register |
SI |
Source index register |
DI |
Destination index register |
SP |
Battery pointer register |
IP |
Next Instruction pointer register |
F |
Flag register |
However we’ll use these register in interrupts programming through C in the next chapters in detail but learning the basics of assembly language here will be good ideal and it will help us through out the programming of disk operations etc.
It is possible to visualize the values of the internal registers of the CPU using the Debug program. To begin working with Debug, type the following prompt in your computer:
C:/>Debug <Enter>
On the next line a dash will appear, this is the indicator of Debug, at this moment the Instructions of Debug can be introduced using the following command:
- r <Enter>
All the contents of the internal registers of the CPU are displayed. An alternative of viewing them is to use the "r" command using as a parameter the name of the register whose value wants to be seen. For example:
-rbx <Enter>
This Instruction will only display the content of the BX register and the Debug indicator changes from "-" to ":"
When the prompt is like this, it is possible to change the value of the register which was seen by typing the new value and <Enter>, or the old value can be left by pressing Enter without typing any other value.
It is possible to change the value of the flag register, and use it as a control structure in our programs as we will see later. Each bit of the register has a special name and meaning, the following list describes the value of each bit, on or off and its relation with the operations of the processor:
Overflow
NV = there is no overflow
OV = there is an overflow
Direction
UP = forward
DN = backward
Interrupts
DI = deactivated
EI = activated
Sign
PL = positive
NG = negative
Zero
NZ = it is not zero
ZR = it is zero
Auxiliary Carry
NA = there is no auxiliary carry
AC = there is auxiliary carry
Parity
PO = uneven parity
PE = even parity
Carry
NC = there is no carry
CY = there is carry
Assembler structure
In assembly language code lines have two parts, the first one is the name of the Instruction which is to be executed, and the second one are the parameters of the command. For example:
ADD ah, bh
Here "ADD" is the command to be executed; in this case an addition, and "ah" as well as "bh" are the parameters.
The name of the Instructions in language is made up of two, three or four letters. These Instructions are also called mnemonic names or operation codes, since they represent a function the processor will perform. There are some commands which do not require parameters for their operation, as well as others that only require just one parameter.
Sometimes Instructions are used as follows:
ADD al,[170]
The brackets in the second parameter indicate to us that we are going to work with the content of the memory cell number 170 and not with the 170 value; this is known as direct direction.
Now we are ready to code for our first program with the help of debug. We are going to create a program that works to illustrate what we have been seeing, and what we will do is to add two values that we will directly introduce into the program.
The first step is to initiate the Debug, this step only consists of typing debug <Enter> on the operative system prompt.
To assemble a program on the Debug, the "a" (assemble) command is used. When this command is used, the address where you want the assembling to begin can be given as a parameter, if the parameter is omitted the assembling will be initiated at the locality specified by CS:IP, usually 0100h, which is the locality where programs with .COM extension must be initiated. And it will be the place we will use since only Debug can create this specific type of programs.
Even though at this moment it is not necessary to give the "a" command a parameter, it is recommendable to do so to avoid problems once the CS:IP Registers are used, therefore we type:
-a0100 <Enter>
When this is done something like this will appear on the screen: 0C1B:0100 and the cursor is positioned to the right of these numbers, note that the first four digits, in hexadecimal system, can be different, but the last four must be 0100, since it is the address we indicated as a begin. Now we can introduce the Instructions:
0C1B:0100 mov ax,0002; puts the 0002 value on the ax register
0C1B:0103 mov bx,0004; puts the 0004 value on the bx register
0C1B:0106 add ax,bx; the content of bx is added to the content of ax
0C1B:0108 int 20; provoques the termination of the program.
0C1B:010A
It is not necessary to write the comments which go after the ";". Once the last command has been typed, int 20, <Enter> is pressed without writing anything more, to see the Debugger prompt again.
The last written line is not properly an assembler Instruction, instead it is a call for an operative system interruption, these interruptions save us a great deal of lines and are very useful to access operative system functions.
To execute the program we wrote, the "g" command is used, and when used we will see a message that says:
"Program terminated normally". Naturally with a message like this one we can not be sure the program has done the addition, but there is a simple way to verify it, by using the "r" command of the Debug we can see the contents of all the registers of the processor, simply type:
-r <Enter>
Each register with its respective actual value will appear on the screen like this:
AX=0006 BX=0004 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0C1B ES=0C1B SS=0C1B CS=0C1B IP=010A NV UP EI PL NZ NA PO NC
0C1B:010A OF DB
The possibility that the registers contain different values exists, but AX and BX must be the same, since they are the ones we just modified.
Another way to see the values, while the program is executed, is to use the address where we want the execution to end and show the values of the registers as a parameter for "g", in this case it would be: g108, this Instruction executes the program, it stops on the 108 address and shows the contents of the registers.
A follow up of what is happening in the registers can be done by using the "t" command (trace), the function of this command is to execute line by line what was assembled, showing each time the contents of the registers.
To exit Debug use the "q" (quit) command.
Advantages of the Assembler
The first reason to work with assembler is that it provides the opportunity of knowing more the operation of your PC, which allows the development of software in a more consistent manner.
The second reason is the total control of the computer, which you can have with the use of the assembler. Another reason is that the assembly based programs are quicker and in some cases they are smaller, and have larger capacities than ones created with other languages.
Let me keep my promise!!
In the earlier part of this chapter we were using some instructins as example, to make the backup of DBR and to load the backup of DBR to its original location when it is needed. First we examine the Instruction to make the backup.
C:\>DEBUG A:\BKDBR.BIN <Enter>
File not found
- L 100 2 0 1 <Enter>
- R CX <Enter>
CX 0000
: 200 <Enter>
- W <Enter>
Writing 00200 bytes
- Q <Enter>
In this example let us start studying from the first line. The command DEBUG A:\BKDBR.BIN Initializes the debug command with creating a file in A: floppy drive named as BKDBR.BIN if it is not already present there. That’s why we got the message “File not found” in the starting.
In our second Instruction L 100 2 0 1, The L (load) command is to load the DBR of the instructed drive. Let us learn how? In this Instruction the number 100 is the address of the buffer, where the DBR will be stored, next number 2 is used for the drive C(C :). The drive numbers are given as follows:
Drive Letter |
Number Used |
A: |
0 |
B: |
1 |
C: |
2 |
D: |
3 |
. |
. |
. |
. |
and so on |
. |
The next number 0 is the starting sector number of the number of sectors to be read. Here we are using 0 to read the 1st sector i.e. DBR sector. The next number that is 1 is used to inform the number of sectors to be read.
Here we have given 1 because we only want to read one sector. However we can use the numbers and locations of starting and ending sectors according to our needs in different type of other operations. Therefore it will load one sector staring from 1st sector of the drive C: to the memory location 100.
And R CX Instruction is used to change or to define the length of the data we want to write in BKDBR.BIN file. This Instruction will show the current value of the CX register and allow you to make any change. We typed 200 here because the DEBUG command uses hexadecimal system and the size of DBR in hexadecimal is 200(h) bytes that is 512 bytes in Decimal system.
W command tells the DEBUG to write the 200(h) bytes from location 100 to the BKDBR.BIN file. And finally we use the Instruction Q to quit the DEBUG and go back to the DOS prompt.
Warning!!! Warning!!! Warning!!!
It is strictly recommended that you should know what and how are you doing in the procedure of restoring DBR of any disk. If accidentally you store the illegal or DBR of any other Disk, it is possible in most of the cases that the complete data of the disk may become inaccessible.
when you type the first Instruction of the coding that is:
DEBUG A:\BKDBR.BIN <Enter>
File must be in the given location where you are starting the DEBUG program. Now if you get the error message “File not found” before the DEBUG prompt then immediately stop the process by using the Q (quit) command. Because it means that the BKDBR.BIN file could not be found or opened by the DEBUG program and if you continue this process some junk information will be written on DBR and it will make the complete partition inaccessible. |
Now let us see what we did in the coding of the Instructions for restoring the DBR from the backup file we made named BKDBR.BIN. The commands of DEBUG to restore the backup are as follows:
C:\> DEBUG A:\BKDBR.BIN <Enter>
- W 100 2 0 1 <Enter>
- Q <Enter>
|
This Instruction will write 1 sector of information from the BKDBR.BIN file in floppy drive (a:) in the memory location 100 to the first sector that is sector 0 of 2nd drive that is drive(C:).
Storing and loading the programs
It would not seem practical to type an entire program each time it is needed, and to avoid this it is possible to store a program on the disk, with the enormous advantage that by being already assembled it will not be necessary to run Debug again to execute it.
The steps to save a program that it is already stored on memory are:
- Obtain the length of the program subtracting the final address from the initial address, naturally in hexadecimal system.
- Give the program a name and extension.
- Put the length of the program on the CX register.
- Order Debug to write the program on the disk.
Using the following program as an example, we will have a clearer idea of how to take these steps. When the program is finally assembled it would look like this:
0C1B:0100 mov ax,0002
0C1B:0103 mov bx,0004
0C1B:0106 add ax,bx
0C1B:0108 int 20
0C1B:010 A
-h 10a 100
020a 000a
-n test.com
-rcx
CX 0000
:000a
-w
Writing 000A bytes
To obtain the length of a program the "h" command is used, since it will show us the addition and subtraction of two numbers in hexadecimal. To obtain the length of ours, we give it as parameters the value of our program's final address (10A), and the program's initial address (100). The first result the command shows us is the addition of the parameters and the second is the subtraction.
The "n" command allows us to name the program. The "rcx" command allows us to change the content of the CX register to the value we obtained from the size of the file with "h", in this case 000a, since the result of the subtraction of the final address from the initial address.
Lastly, the "w" command writes our program on the disk, indicating how many bytes it wrote. Also, to save an already loaded file two steps are necessary:
- Give the name of the file to be loaded.
- Load it using the "l" (load) command.
To obtain the correct result of the following steps, it is necessary that the above program be already created.
Inside Debug we write the following:
-n test.com
-l
-u 100 109
0C3D:0100 B80200 MOV AX,0002
0C3D:0103 BB0400 MOV BX,0004
0C3D:0106 01D8 ADD AX,BX
0C3D:0108 CD20 INT 20
The last "u" command is used to verify that the program was loaded on memory. What it does is that it disassembles the code and shows it disassembled. The parameters indicate to DEBUG from where and to where to disassemble. DEBUG always loads the programs on memory on the address 100H, otherwise indicated.
Segments
The architecture of the x86 processors forces to the use of memory segments to manage the information, the size of these segments is of 64kb.
The reason of being of these segments is that, considering that the maximum size of a number that the processor can manage is given by a word of 16 bits or register, it would not be possible to access more than 65536 localities of memory using only one of these registers, but now, if the memory is divided into groups or segments, each one of 65536 localities, and we use an address on an exclusive register to find each segment, and then we make each address of a specific slot with two registers, and it is possible for us to access a quantity of 4294967296 bytes of memory.
In order for the assembler to be able to manage the data, it is necessary that each piece of information or Instruction be found in the area that corresponds to its respective segments. The assembler accesses this information taking into account the localization of the segment, given by the DS, ES, SS and CS registers and inside the register the address of the specified piece of information. It is because of this that when we create a program using the Debug on each line that we assemble, something like this appears:
1CB0:0102 MOV AX,BX
Where the first number, 1CB0, corresponds to the memory segment being used, the second one refers to the address inside this segment, and the Instructions which will be stored from that address follow.
The assembler adjusts the size of the segments taking as a base the number of bytes each assembled Instruction needs, since it would be a waste of memory to use the whole segments. For example, if a program only needs 10kb to store data, the data segment will only be of 10kb and not the 64kb it can handle.
Data movement
I am listing some assembly language Instructions for data operations here for your knowledge and convenience, when we’ll be doing programming with the help of interrupts and other BIOS operations we’ll need its basics.
Detailed introduction and thorough study of assembly language is beyond the limit of this book. Though the knowledge of basics of assembly is necessary to proceed in the further important programming chapters yet if you feel it difficult to understand all the Instructions, you need not to worry but it is recommended that you should gain the basic idea of Instructions.
In any program it is necessary to move the data in the memory and in the CPU registers and there are several ways to do this. it can copy data in the memory to some register, from register to register, from a register to a stack, from a stack to a register, to transmit data to external devices as well as vice versa.
This movement of data is subject to rules and restrictions. The following are some of them:
- It is not possible to move data from one memory location to another directly. It is necessary to first move the data of the source location to a register and then from the register to the destination locality.
- It is not possible to move a constant directly to a segment register; it first must be moved to a register in the CPU.
- It is possible to move data blocks by means of the MOVS Instructions, which copies a chain of bytes or words. MOCSB which copies n bytes from one location to another and MOVSW copies n words from one location to another. The last two Instructions take the values from the defined addresses by DS:SI as a group of data to move and ES:DI as the new localization of the data.
To move data there are also structures called batteries, where the data is introduced with the push Instruction and are extracted with the pop Instruction. In a stack the first data to be introduced is the last one we can take, this is, if in our program we use these Instructions:
PUSH AX
PUSH BX
PUSH CX
To return the correct values to each register at the moment of taking them from the stack it is necessary to do it in the following order:
POP CX
POP BX
POP AX
For the communication with external devices the out command is used to send information to a port and the in command to read the information received from a port.
The syntax of the OUT command is:
OUT DX,AX
Where DX contains the value of the port which will be used for the communication and AX contains the information which will be sent.
The syntax of the IN command is:
IN AX,DX
Where AX is the register where the incoming information will be kept and DX contains the address of the port by which the information will arrive.
MOV Instruction
Used to Data transfer between memory cells, registers and the accumulator. Syntax is as follows:
MOV Destination, Source
The different movements of data allowed for this Instruction are shown in the table given next:
S. No. |
Destination |
Source |
1. |
memory |
accumulator |
2. |
accumulator |
memory |
3. |
segment register |
memory/register |
4 |
memory/register |
segment register |
5. |
Register |
register |
6. |
Register |
memory |
7. |
memory |
register |
8. |
Register |
immediate data |
9. |
memory |
immediate data |
Let us see an example:
MOV AX,0006
MOV BX,AX
MOV AX,4C00
INT 21
This program moves the value of 0006H to the AX register, then it moves the content of AX (0006h) to the BX register, and lastly it moves the 4C00h value to the AX register to end the execution with the 4C option of the 21h interruption. We’ll take a brief introduction of interrupt 13H and interrupt 21H later.
Interruptions
An interrupt is a hardware facility that causes the CPU to suspend execution, save its status, and transfer to a specific location. The transfer location specifies the address of a program that is intended to take action in response to the interrupt. The program that is executed as a result of the interrupt is called an interrupt- handling program.
For example : if DOS wants to send some information to the BIOS or BIOS wants to send some information to the computer system, DOS or BIOS generate interrupts. Whenever an interrupt is generated, computer suspends whatever it is doing and first takes care of the operation which has generated the interrupt.
Each device capable of generating interrupt is given a unique interrupt number to identify which device is generating these interrupts. We shall discuss all the functions and sub functions of interrupt 13H, Extensions of interrupt 13H and interrupt 21H within this book.
Basically, the interruptions may be of following three types:
- Internal hardware interruptions
- External hardware interruptions
- Software interruptions
Internal Hardware interruptions
Internal interruptions are generated by certain events which come up during the execution of a program. This type of interruptions is managed on their totality by the hardware and it is not possible to modify them.
A clear example of this type of interruptions is the one which actualizes the counter of the computer internal clock, the hardware makes the call to this interruption several times during a second in order to maintain the time up to date.
Though we cannot directly manage this interruption, since we cannot control the time updating by means of software yet it is possible to use its effects on the computer to our benefit.
For example : to create a virtual clock updated continuously we only have to write a program which reads the actual value of the counter and to translate it into an understandable format for the user.
External Hardware Interruptions
External interruptions are generated by peripheral devices, such as keyboards, printers, communication cards, etc. They are also generated by coprocessors. It is not possible to deactivate external interruptions.
These interruptions are not sent directly to the CPU but they are sent to an integrated circuit whose function is to exclusively handle this type of interruptions
Software Interruptions
Software interruptions can be directly activated by the assembler invoking the number of the desired interruption with the INT Instruction.
The use of interruptions helps us in the creation of programs and by using them our programs gets shorter. It is easier to understand them and they usually have a better performance mostly due to their smaller size. This type of interruptions can be separated in two categories: the operative system DOS interruptions and the BIOS interruptions.
The difference between the two is that the operative system interruptions are easier to use but they are also slower since these interruptions make use of the BIOS to achieve their goal, on the other hand the BIOS interruptions are much faster but they have the disadvantage that since they are part of the hardware, they are very specific and can vary depending even on the manufacturer brand of the circuit.
The election of the type of interruption to use will depend solely on the characteristics you want to give your program.
Since we shall use interrupts for data recovery programming with the help of C language via Interrupt handling with C, we shall discuss only Interrupt 13H, Interrupt 13H Extensions and Interrupt 21H routines specially. It is not so important to discuss all of the other interrupts and their functions because in C language, easier functions are available to perform most of those tasks. However, the knowledge of Interrupt 13H and its Extensions is must, for data recovery programming. |
Let us take a brief introduction of Interrupt 20H and Interrupt 21H. The value written in brackets (like 0x20) indicates, how to use
INT 20H ( 0x20) --> Terminate process
Call with: CS = segment address of program segment prefix
Returns: Nothing
Comments:
It terminates the current process. This is one of several methods that a program can use to perform a final exit. You can also use functions (00H or 31H or 4CH) of INT 21H or simply INT 27H to perform a final exit where functions 31H and 4CH of INT 21H are generally preferred because they allow a return code to be passed to the parent process.
It is recommended that if you have used File Control Blocks (FCBs) to write any file, you should close the file first otherwise you may lose the data because in the action of final exit all the memory that was taken by the process is released, File buffers are flushed and any open handles for files or devices owned by the process are closed.
Therefore if you have open handles for file you may lose the data.
INT 21H (0x21)
Function 00H (0x00) --> Terminate process
Call with: AH = 00H
CS = segment address of program segment prefix
Returns: Nothing
Comments:
This interrupt terminates the current process. This is one of several methods that a program can use to perform a final exit. For more information see INT 20H
INT 21H (0x21)
Function 01H (0x01) --> Character input with echo
Call with: AH = 01H
Returns: AL = 8-bit input data
Comments:
This interrupt reads a character from the standard input device such as keyboard and echoes it to the standard output device. If no character is ready, waits until one is available.
INT 21H (0x21)
Function 02H (0x02) --> Character output
Call with: AH = 02H
DL = 8-bit data for output
Returns: Nothing
Comments:
It outputs a character to the standard output device. Output can be redirected. If output is redirected, there is no way to detect disk full.
Strings can also be sent strings to the display by performing a write (INT 21H, Function 40H) using the predefined handle for the standard output (0001H), if output has not been redirected, or a handle obtained the logical device CON.
INT 21H (0x21)
Function 03H (0x03) --> Auxiliary input
Call with: AH = 03H
Returns: AL = 8-bit input data
Comments:
It reads a character from the standard auxiliary device. The default is the first serial port (COM1).
If the auxiliary device sends data faster than your program can process it, characters may be lost. There is no way for a user program to read the status of the auxiliary device or to detect I/O errors such as lost characters, through this function call.
INT 21H (0x21)
Function 04H (0x04) --> Auxiliary output
Call with: AH = 04H
DL = 8-bit data for output
Returns: Nothing
Comments:
This function of INT 21H outputs a character to the standard auxiliary device. The default is the first serial port (COM1). Strings can also be sent to the auxiliary device by performing a write (INT 21H Function 40H) using the predefined handle for the standard auxiliary device (00034) or using a handle obtained by opening the logical device AUX.
INT 21H (0x21)
Function 05H (0x05) --> Printer output
Call with: AH = 05H
DL = 8-bit data for output
Returns: Nothing
Comments:
This function sends a character to the standard list device. The default device is the printer on the first parallel port (LPT1). Strings can also be sent to the printer by performing a write (INT 21H Function 40H) using the predefined handle for the standard printer device (0004H) or using a handle obtained by opening the logical device PRN or LPT1.
INT 21H (0x21)
Function 06H (0x06) --> Direct console I/O
Call with: AH = 06H
DL = function requested such that,
If output request, 00H-FEH
If input request, 0FFH
Returns: Nothing, If called with DL = 00H-0FEH
If called with DL = FFH and a character is ready
Zero flag = clear
AL = 8-bit input data
If called with DL = FFH and no character is ready
Zero flag = set
Comments:
It reads a character from the standard input device or writes a character to the standard output device. I/O may be redirected but if I/O has been redirected, there is no way to detect EOF or disk full. This function of INT 21H is used by programs that the need to read and write all possible characters and control codes without any interference from the operating system.
INT 21H (0x21)
Function 07H (0x07) --> Unfiltered character input
without Echo
Call with: AH = 07H
Returns: AL = 8-bit input data
Comments:
This function reads a character from the standard input device without echoing it to the standard output device.
INT 21H (0x21)
Function 08H (0x08) --> Character input without
echo
Call with: AH = 08H
Returns: AL = 8-bit input data
Comments:
This function reads a character from the standard input device without echoing it to the standard output device.
INT 21H (0x21)
Function 09H (0x09) --> Display string
Call with: AH = 09H
DS:DX = segment: offset of string
Returns: Nothing
Comments:
It sends a string of characters to the standard output device. Output may be redirected. If output has been redirected, there is no way to detect disk full. String can also be sent to the display by performing a write (INT 21H Function 40H) using the predefined handle for the standard output (0001H), if it has not been redirected, or a handle obtained by opening the logical device CON.
INT 21H (0x21)
Function 0AH (0x0A or 10) --> Buffered keyboard
input
Call with: AH = 0AH
DS:DX = segment: offset of buffer
Returns: Data placed in buffer, Returns Nothing
Comments:
It reads a string of bytes from the standard input device, up to and including an ASCII carriage return (0DH), and places them in a user-designated buffer. The characters are echoed to the standard output device. The buffer used by the function has following format:
Byte |
Contents |
0 |
Maximum number of characters to read, set by program |
1 |
Number of characters actually read (excluding carriage return), set by MS-DOS |
2+ |
String read from keyboard or standard input, terminated by a carriage return (0DH) |
INT 21H (0x21)
Function 0BH (0x0B or 11) --> Check input status
Call with: AH = 0BH
Returns: AL = 00H (if no character is available)
FFH (if at least one character is available)
Comments:
Checks if a character is available from the standard input device such as keyboard. This function is equivalent to IOCTL INT 21H Function 44H Sub function 06H.
INT 21H (0x21)
Function 0CH (0x0C or 12) --> Flush input buffer
and then Input
Call with: AH = 0CH
AL = number of input to be invoked after resetting
buffer (must be 01H, 06H, 07H, 08H or 0AH)
If AL = 0AH
DS: DX = segment: offset of input buffer
Returns: If called with AL = 01H, 06H, 07H, or 08H,
AL = 8-bit input data
If called with AL= 0AH,
Nothing (data placed in buffer)
Comments:
Clears the standard input buffer and then invokes one of the character input functions. Input can be redirected. A function number in AL except 01H, 06H, 07H, 08H, or 0AH flushes the input buffer and returns control to the calling program.
INT 21H (0x21)
Function 0DH (0x0D or 13) -> Disk reset
Call with: AH = 0DH
Returns:Nothing
Comments:
This function flushes all file buffers. The function does not update the disk directory for any files that are still open.
INT 21H (0x21)
Function 0EH (0x0E or 14) -> Select disk
Call with: AH = 0EH
DL = drive code (0 = A, 1= B, etc.)
Returns: AL = number of logical drives in system
Comments:
Selects the specified drive to be current or default, disk drive and returns the total number of logical drives in the system.
The applications should limit themselves to the drive letters A-Z (0 = A, 1 = B, etc.). Logical drives means, the total number of block devices such as floppy disk and hard-disk drives etc. Generally A single physical hard-disk drive is partitioned into two or more logical drives.
INT 21H (0x21)
Function 0FH (0x0F or 15) -> Open file
Call with: AH = 0FH
S: DX = segment: offset of file control block
Returns: If function successful and file found
AL = 00H
And FCB filled in by MS-DOS is as follows:
Drive field (offset 00H) =1 for drive A, 2 for drive B, etc. Current block field (offset 0CH) = 00H
Record size field (offset 0EH) = 0080H
Size field (offset 10H) = file size from directory
Data field (offset 14H) = date stamp from directory
Time field (offset 16H) = time stamp from directory
If function unsuccessful and file not found
AL = 0FFH
Comments:
Opens a file and makes it available for subsequent read/write operation. If the program is going to use a record size other than 128 bytes, it should set the record-size field at FCB offset 0EH after the file is successfully opened and before any other disk operation.
INT 21H (0x21)
Function 10H (0x10 or 16) -> Close file
Call with: AH = 10H
DS: DX = segment: offset of file control block
Returns: If function successful (directory update successful)
AL = 00H
If function unsuccessful (file not found in directory)
AL = FFH
Comments:
It is used to close a file. It closes a file, flushes all MS-DOS internal disk buffers associated with the file to disk, and updates the disk directory if the file has been modified or extended.
INT 21H (0x21)
Function 11H (0x11 or 17) -> Find first file
Call with: AH = 11H
DS: DX = segment: offset of file control block
Returns: If function successful and matching file found
AL = 00H
And buffer at current disk transfer area (DTA) address filled in as an unopened normal FCB or extended FCB, depending on which type of FCB was input to function.
If function unsuccessful (no matching filename found)
AL = FFH
Comments:
It searches the current directory on the designated drive for a matching filename. You can use wildcards (? and *). This function returns first matching filename.
INT 21H (0x21)
Function 12H (0x12 or 18) -> Find next file
Call with: AH = 12H
DS: DX = segment: offset of file control block
Returns: If function successful and matching filename found
AL = 00H
And buffer at current disk transfer area (DTA) address set up as an unopened normal FCB or extended FCB, depending on which type of FCB was originally input to INT21H function 11H
If function unsuccessful and matching filenames not found
AL = FFH
Comments:
This is the companion of the previous function. If INT 21H Function 11H has been successful, it returns the next matching filename, if any. This function assumes that the FCB used as input has been properly initialized by a previous call to INT 21H Function 11H and possible subsequent calls to INT 21H Function 12H and that the filename or extension being searched for contained at least one wildcard character.
INT 21H (0x21)
Function 13H (0x13 or 19) -> Delete file
Call with: AH = 13H
DS: DX = segment: offset of file control block
Returns: If function is successful and file or files deleted
AL = 00H
If function is unsuccessful and no matching files were found or at least one matching file was read-only,
AL = FFH
Comments:
It deletes all matching files from the current directory on the default or specified disk drive. You can also use wildcards (? and *).
INT 21H (0x21)
Function 14H (0x14 or 20) -> Sequential read
Call with: AH = 14H
DS: DX = segment: offset of previously opened
file control block
Returns: AL = 00H if read successful
01H if end of file
02H if segment wrap
03H if partial record read at end of
file
Comments:
This function reads the next sequential block of data from a file, then increments the file pointer appropriately. The number of bytes of data to be read is specified by the record-size field (offset 0EH) of the file control block (FCB).
The record is read into memory at the current disk transfer area (DTA) address, specified by the most recent call to INT 21H Function 1AH. If the size of the record and the location of the buffer are such that a segment overflow or wraparound would occur, the function fails with a return code of 02H.
INT 21H (0x21)
Function 15H (0x15 or 21) --> Sequential write
Call with: AH = 15H
DS: DX = segment: offset of previously opened file control block
Returns: AL = 00H, if write successful
01H, if disk is file
02H, if segment wrap
Comments:
This function writes the next sequential block of data into a file, then increments the file pointer appropriately. The number of bytes of data to be written is specified by the record size-field (offset 0EH) of the file control block (FCB).
INT 21H (0x21)
Function 16H (0x16 or 22) --> Create file
Call with: AH = 16H
DS: DX = segment: offset of unopened file control block
Returns: If function is successful and file was created or truncated
AL = 00H
And FCB filled in by MS-DOS as follows:
Drive field (offset 00H) = 1 for drive A, 2 for drive B, etc.
Current block field (offset0CH) = 00H
Record size field (offset 0EH) = 0080H
Size field (offset 10H) = file size from directory
Date field (offset 14H) = date stamp from directory
Time field (offset 16H = time stamp from directory
If function unsuccessful (directory full)
AL = FFH
Comments:
This function creates a new directory entry in the current directory or truncates any existing file with the same name to zero length. Also opens the file for subsequent read/write operations. This function must be used with caution because an existing file with the specified name is truncated to zero length and all data in that file is irretrievably lost.
INT 21H (0x21)
Function 17H (0x17 or 23) --> Rename file
Call with: AH = 17H
DS: DX = segment: offset of special file control block
Returns: If function is successful and one or more files renamed
AL = 00H
If function is unsuccessful and no matching files, or new filename matched an existing file
AL = FFH
Comments:
This function changes the name of all matching files in the current directory on the disk in the specified drive.
You can also use wild cards with this. The special file control block has a drive code, filename, and extension in the usual position (bytes 0 through 0BH) and a second filename starting 6 bytes after the first (offset 11H).
INT 21H
Function 18H (0x18 or 24) --> Reserved
INT 21H (0x21)
Function 19H (0x19 or 25) --> Get current disk
Call with: AH = 19H
Returns: AL = drive code (0 for A drive, 1 for B drive etc.)
Comments:
This function returns the drive code of the current or default disk drive.
INT 21H (0x21)
Function 1AH (0x1A or 26) --> Set DTA address
Call with: AH = 1AH
DS: DX = segment: offset of disk transfer area.
Returns: Nothing
Comments:
This function specifies the address of the disk transfer area (DTA) to be used for subsequent FCB-related function calls.
INT 21H (0x21)
Function 1BH (0x1B or 27) --> Get default drive
data
Call with: AH = 1BH
Returns: If function successful
AL = sectors per cluster
DS: DX = segment offset of media ID byte
CX = size of physical sector in bytes
DX = number of clusters for default drive
If function unsuccessful (invalid drive or critical error)
AL = FFH
Comments:
This function obtains selected information about the default disk drive and a pointer to the media identification byte from its file allocation table.
The media ID byte has the following meanings:
Media Descriptor ID |
Medium |
0F0H |
3.5-inch Floppy Disk, double-sided, 18 sectors (or other) |
0F8H |
fixed disk |
0F9H |
5.25-inch Floppy Disk, double-sided, 15 sectors |
0F9H |
3.5-inch Floppy Disk, double-sided, 9 sectors |
0FCH |
5.25-inch Floppy Disk, single-sided, 9 sectors |
0FDH |
5.25-inch Floppy Disk, double-sided, 9 sectors |
0FDH |
8-inch Floppy Disk, single sided, single density |
0FEH |
5.25-inch Floppy Disk, single-sided, 8 sectors |
0FEH |
8-inch Floppy Disk, Single Sided, Single Density |
0FEH |
8-inch Floppy Disk, Double Sided, Double Density |
0FFH |
5.25-inch Floppy Disk, double-sided, 8 sectors |
INT 21H (0x21)
Function 1CH (0x1C or 28) --> Get drive data
Call with: AH = 1CH
DL = Drive Code
Returns: If function is successful
AL = sectors per cluster
DS: BX = segment: offset of media ID byte
CX = size of physical sector in bytes
DX = number of clusters for default or specified drive
If function is unsuccessful and invalid drive or critical error
AL = FFH
Comments:
This function obtains allocation information about the specified disk drive and a pointer to the media identification byte from its file allocation table. Refer the media descriptor ID byte table, given in INT 21H, Function 1BH, for Media ID information.
INT 21H (0x21)
Function 1DH (0x1D or 29) --> Reserved
INT 21H (0x21)
Function 1EH (0x1E or 30) --> Reserved
INT 21H (0x21)
Function 1FH (0x1F or 31) --> Reserved
INT 21H (0x21)
Function 20H (0x20 or 32) --> Reserved
INT 21H (0x21)
Function 21H (0x21 or 33) --> Random read
Call with: AH = 21H
DS: DX = segment: offset of previously opened
file control block
Returns: AL = 00H if read successful
01H if end of file
02H if segment wrap, read canceled
03H if partial record read at end of
file
Comments:
This function reads a selected record from a file into memory. The record is read into memory at the current disk transfer area address, specified by the most recent call to INT 21H Function 1AH.
INT 21H (0x21)
Function 22H (0x22 or 34) --> Random write
Call with: AH = 22H
DS: DX = segment: offset of previously opened
file control block
Returns: AL = 00H if write successful
01H if disk full
02H if segment wrap, write canceled
Comments:
This function writes the data from memory into a selected record in a file.
INT 21H (0x21)
Function 23H (0x23 or 35) --> Get file size
Call with: AH = 23H
DS: DX = segment: offset of unopened file
control block
Returns: If function is successful and matching filename found
AL = 00H
And FCB relative-record field (offset 21H) set to the number of records in the file, rounded up if necessary to the next complete record
If function is unsuccessful and no matching file found
AL = FFH
Comments:
This function searches for a matching file in the current directory; if one is found, updates the FCB with the size of the file in terms of number of records. There is no default record size for this function therefore an appropriate value must be placed in the FCB record size field (offset 0EH) before calling this function.
INT 21H (0x21)
Function 24H (0x24 or 36) --> Set relative record
number
Call with: AH = 24H
DS: DX = segment: offset of previously opened
file control block
Returns: AL is destroyed (other register not affected)
FCB relative-record field (offset 21H) updated
Comments:
This function sets the relative-record number field of a file control block (FCB) to correspond to the current file position as recorded in the opened FCB.
INT 21H (0x21)
Function 25H (0x25 or 37) --> Set interrupt vector
Call with: AH = 25H
AL = interrupt number
DS: DX = segment: offset of interrupt handling
routine
Returns: Nothing
Comments:
This function Initialize a CPU interrupt vector to point to an interrupt handling routine. It should be used in preference to direct editing of the interrupt-vector table by well-behaved applications.
INT 21H (0x21)
Function 26H (0x26 or 38) --> Create new Program
Segment Prefix (PSP)
Call with: AH = 26H
DX = segment: of new program segment
prefix (PSP)
Returns: Nothing
Comments:
This function copies the program segment prefix (PSP) of the currently executing program to a specified segment address in free memory, then updates the new PSP to make it usable by another program.
INT 21H (0x21)
Function 27H (0x27 or 39) --> Random block read
Call with: AH = 27H
CX = number of records to read
DS: DX = segment: offset of previously opened
file control block
Returns: AL = 00H if all requested records read
01H if end of file
02H if segment wrap
03H if partial record read at end of
file
CX = actual number of records read
Comments:
This function reads one or more sequential records from a file into memory, starting at a designated file location. If the size and location of the buffer are such that a segment overflow or wraparound would occur, the function fails with a return code of 02H and if a partial record is read at the end of file, the remainder of the record is padded with zeros.
INT 21H (0x21)
Function 28H (0x28 or 40) --> Random block write
Call with: AH = 28H
CX = number of records to write
DS: DX = segment: offset of previously opened
file control block
Returns: AL = 00H if all requested records written
01H if disk full
02H if segment wrap
CX = actual number of records written
Comments:
This function writes one or more sequential records from memory to a file, starting at a designated file location. If the size and location of the buffer are such that a segment overflow or wraparound would occur, the function fails with a return code 02H.
INT 21H (0x21)
Function 29H (0x29 or 41) --> Parse filename
Call with: AH = 29H
AL = flags to control parsing
Bit 0 = 1, if leading separators will be
scanned off (ignored).
= 0, if leading separators will not be
scanned off
Bit 1 = 1, if drive ID byte in FCB will be
modified only if a drive was
specified in the string being parsed.
= 0, if the drive ID byte in FCB will be
modified regardless, if no drive
specifier is present in the parsed string, FCB drive code field is set to 0 (default)
Bit 2 = 1, if filename field in FCB will be
modified only if a filename is
specified in the string being parsed.
= 0, if filename field in FCB will be modified regardless, if no filename is presenting the parsed string, FCB filename is set to ASCIIZ blanks.
Bit 3 = 1, if extension field in FCB will be
modified, only if an Extension is
specified in the string being parsed.
= 0, if extension field in FCB will be
modified regardless, if no extension
is present in the parsed string, FCB
extension is set to ASCIIZ blanks
DS: SI = segment: offset of string
ES: DI = segment: offset of file control block
Returns: AL = 00H, if no wildcard characters
Encountered 01H, if parsed string
contained wildcard characters FFH,
if drive specifier invalid
DS: SI = segment: offset of first character
after parsed filename
ES: DI = segment: offset of formatted
unopened file control block
Comments:
This function parses a text string into the various fields of a file control block (FCB).
This function regards the characters (: . ; , = + tab space ) as separator characters and regards all control characters and characters (: . ; , = + tab space < > | / “ [ ])as terminator characters.
INT 21H (0x21)
Function 2AH (0x2A or 42) --> Get day and date
Call with: AH = 2AH
Returns: CX = year (1980 through 2099)
DH = month (1 through 12)
DL = day (1 through 31)
AL = day of the week (0 = Sunday,
1= Monday, etc.)
Comments:
This function obtains the system day of the month, day of the week, month and year.
INT 21H (0x21)
Function 2BH (0x2B or 43) --> Set date
Call with: AH = 2BH
CX = year (1980 through 2099)
DH = month (1 through 12)
DL = day (1 through 31)
Returns: AL = 00H if date set successfully
FFH if date not valid (ignored)
Comments:
This function initializes the system clock driver to a specific date but the system time remains unchanged.
INT 21H (0x21)
Function 2CH (0x2C or 44) --> Get time
Call with: AH = 2CH
Returns: CH = hours (0 through 23)
CL = minutes (0 through 59)
DH = seconds (0 through 59)
DL = hundredths of seconds (0 through 99)
Comments:
This is used to obtain the time of day from the system real-time clock driver, converted to hours, minutes, seconds, and hundredths of seconds.
INT 21H (0x21)
Function 2DH (0x2D or 45) --> Set time
Call with: AH = 2DH
CH = hours (0 through 23)
CL = minutes (0 through 59)
DH = seconds (0 through 59)
DL = hundredths of seconds (0 through 99)
Returns: AL = 00H, if time set successfully
FFH, if time not valid (ignored)
Comments:
This function initializes the system real-time clock to a specified hour, minute, second, and hundredth of second. The system date is not affected.
INT 21H (0x21)
Function 2EH (0x2E or 46) --> Set verify flag
Call with: AH = 2EH
AL = 00H, if turning off verify flag
01H, if turning on verify flag
DL = 00H
Returns: Nothing
Comments:
This function turns off or turns on the operating-system flag for automatic read-after-write verification of data. The default setting of the verify flag is OFF because read-after-write verification slows disk operations.
INT 21H (0x21)
Function 2FH (0x2F or 47) --> Get DTA address
Call with: AH = 2FH
Returns:ES: BX = segment: offset of disk transfer area
Comments:
This function obtains the current address of the disk transfer area (DTA) for FCB file read/write operations.
INT 21H (0x21)
Function 30H (0x30 or 48) --> Get MS-DOS
version number
Call with: AH = 30H
AL = 00H
Returns: AL = major version number (MS-DOS 3.10=3, etc.)
AH = minor version number (MS-DOS 3.10= 0AH, etc.)
BH = Original Equipment Manufacturer’s
(OEM’s) serial number (OEM-dependent-usually 00H for IBM’s
PC-DOS, 0FFH or other values for MS-DOS)
BL: CX = 24-bit user serial number (optional, OEM-dependent)
Comments:
It returns the version number of the host MS-DOS operating system.
INT 21H (0x21)
Function 31H (0x31 or 49) --> Terminate and Stay
Resident (TSR)
Call with: AH = 31H
AL = return code
DX = amount of memory in paragraphs, to reserve
Returns Nothing
Comments:
This function terminates the execution of the currently executing program by passing a return code to the parent process but reserves part or all of the memory of the program so that it will be overlaid by the next transient program to be loaded. This function should be used in preference to INT 27H because it supports CS to contain the segment of the program segment prefix.
INT 21H (0x21)
Function 32H (0x32 or 50) --> Reserved
INT 21H (0x21)
Function 33H (0x33 or 51) --> Get or set break flag, get boot Drive
Call with: If getting break flag
AH = 33H
AL = 00H
If setting break flag
AH = 33H
AL = 01H
DL = 00H if turning break flag OFF
01H if turning break flag ON
If getting boot drive
AH = 33H
AL = 05H
Returns: If called with AL = 00H or 01H
DL = 00H break flag is OFF
01H break flag is ON
If called with AL = 05H
DL = boot drive (1 = A, 2 = B, etc.)
Comments:
This function obtains or changes the status of the operating system’s break flag, which influences Ctrl-C checking during function calls.
INT 21H (0x21)
Function 34H (0x34 or 52) --> Reserved
INT 21H (0x21)
Function 35H (0x35 or 53) --> Get interrupt vector
Call with: AH = 35H
AL = interrupt number
Returns: ES: BX = segment: offset of interrupt handler
Comments:
This function obtains the address of the current interrupt-handler routine for the specified machine interrupt.
INT 21H (0x21)
Function 36H (0x36 or 54) --> Get drive allocation
Information
Call with: AH = 36H
DL = drive code (0 default, 1 = A, etc.)
Returns: If function successful
AX = sector per cluster
BX = number of available cluster
CX = bytes per sector
DX = cluster per drive
If function unsuccessful (drive invalid)
AX = FFFFH
Comments:
This function obtains selected information about a disk drive.
This function is very important in data recovery and disk troubleshooting programming from which the drive’s capacity and remaining free space and many other important things can be calculated.
INT 21H (0x21)
Function 37H (0x37 or 55) --> Reserved
INT 21H (0x21)
Function 38H (0x38 or 56) --> Get or set country
information
Call with: If getting country information
AH = 38H
AL = 0, to get current country information
1-FEH, to get information for
countries with code <255
FFH, to get information for countries
with code >=255
BX = country code, if AL = FFH
DS:DX = segment: offset of buffer for returned information
If setting current country code
AH = 38H
AL = 1-FEH, country code for countries with code <255
FFH, for countries with code >=255
BX = country code, if AL = 0FFH
DX = FFFFH
Returns:
If function is successful
Carry flag = clear
And, if getting internationalization information
BX = country code
DS: DX = segment: offset of buffer holding internationalization Information.
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This function obtains international information for the current or specified country or sets the current country code.
INT 21H (0x21)
Function 39H (0x39 or 57) --> Create directory
Call with: AH = 39H
DS: DX = segment: offset of ASCIIZ pathname
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function creates a directory using the specified drive and path.
ASCIIZ is known as the sequence of ASCII characters terminated be, Null or Zero, Byte. |
INT 21H (0x21)
Function 3AH (0x3A or 58) --> Delete directory
Call with: AH = 3AH
DS: DX = segment: offset of ASCIIZ pathname
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function removes a directory using the specified drive and path. If any element of the pathname does not exist or directory is not empty or access is denied or specified directory is also current directory, the function of deleting the directory fails.
INT 21H (0x21)
Function 3BH (0x3B or 59) --> Set current
directory
Call with: AH = 3BH
DS: DX = segment: offset of ASCIIZ pathname
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function sets the current or default directory using the specified drive and path. If the specified path or any element of the path does not exist, the function fails.
INT 21H (0x21)
Function 3CH (0x3C or 60) --> Create file
Call with: AH = 3CH
CX = file attribute, where attribute
significance bits may be Combined.
Significance of bits is given in the following Table:
Bit(s) |
Significance (if set) |
0 |
Read-only |
1 |
Hidden |
2 |
System |
3 |
Volume label |
4 |
Reserved (0) |
5 |
Archive |
6 – 15 |
Reserved (0) |
DS: DX = segment: offset of ASCIIZ
pathname
Returns: If function successful
Carry flag = clear
AX = handle
If function unsuccessful
Carry flag = set
AX = error code
Comments:
If an ASCIIZ pathname is given, this function creates a new file in the designated or default directory on the designated or default disk drive. If the specified file already exists, it is truncated to zero length. In either case, the file is opened and a handle is returned that can be used by the program for subsequent access to the file.
If any element of the pathname does not exists or file is being created in root directory and root directory is full or access is denied or a file with read – only attribute is already in the specified directory, the function of creating file fails.
INT 21H (0x21)
Function 3DH (0x3D or 61) --> Open file
Call with: AH = 3DH
AL = access mode
Access mode bits significance is given in the following table:
Bits |
Significance |
0 – 2 |
Access Mode
000 = read access
001 = write access
010 = read/write access |
3 |
Reserved (0) |
4 – 6 |
Sharing Mode
000 = compatibility mode
001 = deny all
010 = deny write
011 = deny read
100 = deny none |
7 |
Inheritance flag
0 = child process inherits handle
1 = child does not inherit handle |
DS: DX = segment: offset of ASCIIZ pathname
Returns: If function successful
Carry flag = clear
AX = handle
If function unsuccessful
Carry flag = set
AX = error code
Comments:
If an ASCIIZ pathname is given, this function opens the specified file in the designated or default directory on the designated or default disk drive. A handle is returned which can be used by the program for subsequent access to the file.
INT 21H (0x21)
Function 3EH (0x3E or 62) --> Close file
Call with: AH = 3EH
BX = handle
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function flushes all internal buffers associated with the file to disk, closes the file, and releases the handle for reuse, of previously open or created with success of a given handle. If the file was modified, the time and date stamp and file size are updated in the directory entry of the file.
INT 21H (0x21)
Function 3FH (0x3F or 63) --> Read file or device
Call with: AH = 3FH
BX = handle
CX = number of bytes to read
DS: DX = segment: offset of buffer
Returns: If function successful
Carry flag = clear
AX = byte transferred
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function transfers data at the current file-pointer position from the file into the buffer and then updates the file pointer position for a given valid file handle from a previous open or create operation, a buffer address, and a length in bytes.
INT 21H (0x21)
Function 40H (0x40 or 64) --> Write file or device
Call with: AH = 40H
BX = handle
CX = number of bytes to write
DS: DX = segment: offset of buffer
Returns: If function successful
Carry flag = clear
AX = byte transferred
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function transfers data from the buffer into the file and then updates the file pointer position for given valid file handle from a previous open or create operation, a buffer address, and a length in bytes. If the function is called with CX = 0, the file is truncated or extended to the current file pointer position.
INT 21H (0x21)
Function 41H (0x41 or 65) --> Delete file
Call with: AH = 41H
DS: DX = segment: offset of ASCIIZ pathname
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function deletes a file from the default or specified disk and directory. The function deletes a file by replacing the first character of its filename in the root directory with the character E5H (0xE5) and making the file’s clusters as available for the new data in the file allocation table. Till then actual data stored in those clusters is not overwritten.
INT 21H (0x21)
Function 42H (0x42 or 66) --> Set file pointer
Call with: AH = 42H
AL = method code
00H absolute offset from start of file
01H signed offset from current file
pointer
02H signed offset from end of file
BX = handle
CX = most significant half of offset
DX = least significant half of offset
Returns: if function is successful
Carry flag = clear
DX = most significant half of resulting file
pointer
AX = least significant half of resulting file
pointer
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This function sets the file pointer location relative to the start of file, end of file, or current file position.
INT 21H (0x21)
Function 43H (0x43 or 67) --> Get or set file
attributes
Call with: AH = 43H
AL = 00H to get attributes
01H to set attributes
CX = file attribute, if AL=01H. Bits can be combined
DS: DX = segment: offset of ASCIIZ pathname
Returns: If function successful
Carry flag = clear
CX = file attribute
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function obtains or alters the attributes of file (read-only, hidden, system, or archive) or directory. For the significance of bits for different attributes refer Bits significance table given before.
INT 21H (0x21)
Function 44H (0x44 or 68) --> Input/Output
Control (I/O Ctrl)
This function provides a direct path of communication between an application program and a device driver. It allows a program to obtain hardware-dependent information and to request operations that are not supported by other MS-DOS function calls.
The sub functions of Input and output Control have been given in the following table:
Sub function |
Operation Name |
00H |
Get Device Information |
01H |
Set Device Information |
02H |
Receive Control Data from Character Device Driver |
03H |
Send Control Data to Character Device Driver |
04H |
Receive Control Data from Block Device Driver |
05H |
Send Control Data to Block Device Driver |
06H |
Check Input Status |
07H |
Check Output Status |
08H |
Check If Block Device Is Removable |
09H |
Check If Block Device Is Remote |
0AH (10) |
Check If Handle Is Remote |
0BH (11) |
Change Sharing Retry Count |
0CH (12)
|
Generic I/O Control for Character Devices
Value |
Description |
CL = 45H |
Set Iteration Count |
CL = 4AH |
Select Code Page |
CL = 4CH |
Start Code Page Preparation |
CL = 4DH |
End Code Page Preparation |
CL = 5FH |
Set Display Information |
CL = 65H |
Get Iteration Count |
CL = 6AH |
Query Selected Code Page |
CL = 6BH |
Query Prepare List |
CL = 7FH |
Get Display Information |
|
0DH (13)
|
Generic I/O Control for Block Devices
Value |
Description |
CL = 40H |
Set Device Parameters |
CL = 41H |
Write Track |
CL = 42H |
Format and Verify Track |
CL = 47H |
Set Access Flag |
CL = 60H |
Get Device Parameters |
CL = 61H |
Read Track |
CL = 62H |
Verify Track |
CL = 67H |
Get Access Flag |
|
0EH (14) |
Get Logical Drive Map |
0FH (15) |
Set Logical Drive Map |
INT 21H (0x21)
Function 44H (0x44 or 68), sub function 00H (0x00)
I/O Ctrl --> get device information
Call with: AH = 44H
AL = 00H
BX = handle
Returns: If function successful
Carry flag = clear
DX = device information word
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function returns a device information word for the file or device associated with the specified handle.
INT 21H (0x21)
Function 44H (0x44 or 68), sub function 01H (0x01)
I/O Ctrl --> set device information
Call with: AH = 44H
AL = 01H
BX = handle
DX = device information word
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function of function 44H of INT 21H, sets certain flags for a handle associated with a character device. This sub function may not be used for a handle that is associated with a file.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 02H (0x02)
I/O Ctrl --> read control data character device
driver
Call with: AH = 44H
AL = 02H
BX = handle
CX = number of bytes to read
DS: DX = segment: offset of buffer
Returns: If function is successful
Carry flag = clear
AX = bytes read
And buffer contains control data from driver
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
It reads control data from a character-device driver. The length and contents of the data are specified to each device driver and do not follow any standard format. This function does not necessarily result in any input from the physical device.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 03H (0x03)
I/O Ctrl --> write control data character-device
driver
Call with: AH = 44H
AL = 03H
BX = handle
CX = number of bytes to write
DS: DX = segment: offset of data
Returns: If function successful
Carry flag = clear
AX = bytes transferred
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function transfers control data from an application to a character-device driver. The length and contents of the data are specific to each device driver and do not follow any standard format. This function does not necessarily result if any output to the physical device.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 04H (0x04)
I/O Ctrl --> Read control data block-device driver
Call with: AH = 44H
AL = 04H
BL = device code (0= default, 1=A, 2=B, etc.)
CX = number of bytes to read
DS: DX = segment: offset of buffer
Returns: If function successful
Carry flag = clear
AX = bytes transferred
And buffer contains control data from device driver
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function transfers control data from a block-device driver directly into an application program’s buffer. The length and contents of the data are specific to each device driver and do not follow any standard format. This function does not necessarily result in input from the physical device.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 05H (0x05)
I/O Ctrl --> write control data block-device driver
Call with: AH = 44H
AL = 05H
BL = device code (0= default, 1=A, 2=B, etc.)
CX = number of bytes to write
DS: DX = segment: offset of data
Returns: If function successful
Carry flag = clear
AX = bytes transferred
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function transfers control data from an application program directly to a block-device driver. The length and contents of the control data are specific to each device driver and do not follow any standard format. This function does not necessarily result any output to the physical device.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 06H (0x06)
I/O Ctrl --> check input status
Call with: AH = 44H
AL = 06H
BX = handle
Returns: If function successful
Carry flag = clear
And for a device:
AL = 00H, if device not ready
FFH, if device ready
For a file:
AL = 00H, if file pointer at EOF
FFH, if file pointer not at EOF
If function unsuccessful
Carry flag = set
AX = error code
Comments:
It returns a code indicating whether the device or files associated with a handle is ready for input.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 07H (0x07)
I/O Ctrl --> check output status
Call with: AH = 44H
AL = 07H
BX = handle
Returns: If function successful
Carry flag = clear
And for a device:
AL = 00H, if device not ready
FFH, if device ready
For a file:
AL = FFH
If function unsuccessful
Carry flag = set
AX = error code
Comments:
It returns a code indicating whether the device associated with a handle is ready for output.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 08H (0x08)
I/O Ctrl --> check if block device is removable
Call with: AH = 44H
AL = 08H
BL = drive number (0 = default, 1=A, 2=B, etc.)
Returns: If function successful
Carry flag = clear
AL = 00H, if medium is removable
01H, if medium is not removable
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function checks whether the specified block device contains a removable storage medium, such as a floppy disk. If a file is not found as expected on a particular drive, a program can use this sub function to determine whether the user should be prompted to insert another disk.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 09H (0x09)
I/O Ctrl --> check if block device is remote
Call with: AH = 44H
AL = 09H
BL = drive number (0 = default, 1=A, 2=B, etc.)
Returns: If function successful
Carry flag = clear
DX = device attribute word
bit 12 = 0, if drive is local
= 1, if drive is remote
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function checks whether the specified block device is local (attached to the computer running the program) or remote (redirected to a network server).
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 0AH (0x0A or 10) I/O Ctrl --> check if handle is remote
Call with: AH = 44H
AL = 0AH
BX = handle
Returns: If function successful
Carry flag = clear
DX = attribute word for file or device
bit 15 = 0 if local
1 if remote
If function unsuccessful
Carry flag = set
AX = error code
Comments:
It checks whether the specified handle refers to a file or device that is local (located on the PC that is running program) or remote (located on a network server).
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 0BH (0x0B or 11) I/O Ctrl --> change sharing retry count
Call with: AH = 44H
AL = 0BH
CX = delays per retry (default = 1)
DX = number of retries (default = 3)
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function sets the number of times MS-DOS retries a disk operation after a failure caused by a file-sharing violation before it returns an error to the requesting process. This sub function is not available unless the file sharing module is loaded.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 0CH (0x0C or 12) I/O Ctrl generic I/O control for
character devices
Call with: AH = 44H
AL = 0CH
BX = handle
CH =category (major) code:
00H = unknown
01H = COM1, COM2, COM3,OR COM4
03H = CON (keyboard and display)
05H = LPT1, LPT2, OR LPT3
CL = function (minor) code:
45H = Set Iteration Count
4AH = Select Code Page
4CH = Start Code Page Preparation
4DH = End Code Page Preparation
5FH = Set Display Information
65H = Get Iteration Count
6AH = Query Selected Code Page
6BH = Query Prepare List
7FH = Get Display Information
DS: DX = segment: offset of parameter block
Returns: If function successful
Carry flag = clear
And if called with CL = 65H, 6AH, 6BH or 7FH
DS: DX = segment: offset of parameter block
If function unsuccessful
Carry flag = set
AX = error code
Comments:
It provides a general-purpose mechanism for communication between application programs and character-device drivers.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 0DH (0x0D or 13) I/O Ctrl --> generic I/O control for block
devices
Call with: AH = 44H
AL = 0DH
BL = drive code (0 =default, 1=A, 2=B, etc.)
CH = category (major) code:
08H = disk drive
CL = function (minor) code:
40H = Set Drive Parameters
41H = Write Track
42H = Format and Verify Track
47H = Set Access Flag
60H = Get Device Parameters
61H = Read Track
62H = Verify track
67H = Get Access Flag
DS: DX = segment: offset of parameter block
Returns: If function successful
Carry flag = clear
And if called with CL = 60H or 61H
DS: DX = segment: offset of parameter block
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function provides a general-purpose mechanism for communication between application programs and block-device drivers. Allows a program to inspect or change device parameters for a logical drive and to read, write, format, and verify disk tracks in a hardware-independent manner.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 0EH (0x0E or 14) I/O Ctrl -->> get logical drive map
Call with: AH = 44H
AL = 0EH
BL = drive code (0 = default, 1=A, 2=B, etc.)
Returns: If function successful
Carry flag = clear
AL = mapping code
00H, if only one logical drive code
assigned to the block device
01H-1AH logical drive code (1=A,
2=B, etc.) mapped to the block device
If function unsuccessful
Carry flag = set
AX =error code
Comments:
It returns the logical drive code that was most recently used to access the specified block drive.
INT 21H (0x21)
Function 44H (0x44 or 68), Sub function 0FH (0x0F or 15) I/O Ctrl --> set logical drive map
Call with: AH = 44H
AL = 0FH
BL = drive code (0 = default, 1=A, 2=B, etc.)
Returns: If function successful
Carry flag = clear
AL = mapping code
00H, if only one logical drive code
assigned to the block device
01H-1AH, logical drive code (1=A,
2=B, etc.) mapped to the
block device
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function sets the next logical drive code that will be used to reference a block device.
INT 21H (0x21)
Function 45H (0x45 or 69) --> Duplicate handle
Call with: AH = 45H
BX = handle to be duplicated
Returns: If function successful
Carry flag = clear
AX = new handle
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function returns a new handle that refers to the same device or file at the same position for given handle for a currently open device or file.
INT 21H (0x21)
Function 46H (0x46 or 70) --> Redirect handle
Call with: AH = 46H
BX = handle for file or device
CX = handle to be redirected
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
If there are two given handles, this function makes the second handle refer to the same device or file at the same location as the first handle. The second handle is then said to be redirected.
INT 21H (0x21)
Function 47H (0x47 or 71) --> Get current
directory
Call with: AH = 47H
DL = drive code (0 =default, 1=A,
2=B, etc.)
DS: SI = segment: offset of 64-byte buffer
Returns: If function is successful
Carry flag = clear
And buffer is filled in with full pathname from root of current directory.
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This function obtains an ASCIIZ string that describes the path from the root to the current directory, and the name of that directory.
INT 21H (0x21)
Function 48H (0x48 or 72) --> Allocate memory
block
Call with: AH = 48H
BX = number of paragraphs of memory
needed
Returns: If function successful
Carry flag = clear
Ax = base segment address of allocated
block
If function unsuccessful
Carry flag = set
AX = error code
BX = size of largest available block
(paragraphs)
Comments:
It allocates a block of memory and returns a pointer to the beginning of the allocated area.
INT 21H (0x21)
Function 49H (0x49 or 73) --> Release memory
block
Call with: AH = 49H
ES = segment of block to be released
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function is used to Release a memory block and makes it available for use by other programs. The function will fail or can cause unpredictable system errors if the program release a memory block that does not belong to it or the segment address passed in register ES is not a valid base address for an existing memory block.
INT 21H (0x21)
Function 4AH (0x4A or 74) --> Resize memory
block
Call with: AH = 4AH
BX = desired new block size in paragraphs
ES = segment of block to be modified
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
BX = maximum block size available
(paragraphs)
Comments:
This function dynamically shrinks or extends a memory block, according to the needs of an application program.
INT 21H (0x21)
Function 4BH (0x4B or 75) --> Execute program (EXEC)
Call with: AH = 4BH
AL = sub function
00H = Load and Execute Program
03H = Load Overlay
ES: BX = segment: offset of parameter block
DS: DX = segment: offset of ASCIIZ program
pathname
Returns: If function successful
Carry flag = clear
Registers are preserved in the usual fashion.
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function allows an application program to run another program, regaining control when it is finished. Can also be used to load overlays, although this is use is uncommon.
INT 21H (0x21)
Function 4CH (0x4C or 76) --> Terminate process
with Return code
Call with: AH = 4CH
AL = return code
Returns: Nothing
Comments:
This function terminates the current process, passing a return code to the parent process. This is one of several methods that a program can use to perform a final exit.
INT 21H (0x21)
Function 4DH (0x4D or 77) --> Get return code
Call with: AH = 4DH
Returns: AH = exit type
00H, if normal termination by INT 20H, INT 21H
Function 00H, or INT 21H Functions 4CH
01H if termination by user’s entry of Ctrl-C
02H if termination by critical-error handler
03H if termination by INT21H Function 31H or
INT 27H |
AL = return code passed by child process
(0 if child terminated by INT 20H,
INT 21H Function 00H, or INT 27H)
Comments:
This function is used by a parent process, after the successful execution of an EXEC call (INT 21H Function 4BH), to obtain the return code and termination type of a child process.
INT 21H (0x21)
Function 4EH (0x4E or 78) --> Find first file
Call with: AH = 4EH
CX = search attribute (bits may be combined)
DS: DX = segment: offset of ASCIIZ pathname
Returns: If function successful and matching file found
Carry flag = clear
And search results returned in current disk transfer area as follows:
Byte(s) |
Description |
00H-14H |
Reserved (0) |
15H |
Attribute of matched file or directory |
16H-17H |
File time
bits 00H-04H = 2-second increments (0-29)
bits 05H-0AH = minutes (0-59)
bits 0BH-0FH = hours (0-23) |
18H-19H
|
File date
bits 00H-04H = day (1-31)
bits 05H-08H = month (1-12)
bits 09H-0FH = year (relative to 1980) |
1AH-1DH |
File size |
1EH-2AH |
ASCIIZ filename and extension |
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This function searches the default or specified directory on the default or specified drive for the first matching file for a given file specification in the form of an ASCIIZ string. For bit significance of attributes, refer bits significance table given before.
INT 21H (0x21)
Function 4FH (0x4F or 79) --> Find next file
Call with: AH = 4FH
Returns: If function is successful and matching file found
Carry flag = clear
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
If there is a previous successful call to INT 21H Function 4EH, this function finds the next file in the default or specified directory on the default or specified drive that matches the original file specification.
INT 21H (0x21)
Function 50H (0x50 or 80) --> Reserved
INT 21H (0x21)
Function 51H (0x51 or 81) --> Reserved
INT 21H (0x21)
Function 52H (0x52 or 82) --> Reserved
INT 21H (0x21)
Function 53H (0x53 or 83) --> Reserved
INT 21H (0x21)
Function 54H (0x54 or 84) --> Get verify flag
Call with: AH = 54H
Returns: AL = current verify flag value
00H if verify off
01H if verify on
Comments:
This function obtains the current value of the system verify (read-after-write) flag.
INT 21H (0x21)
Function 55H (0x55 or 85) --> Reserved
INT 21H (0x21)
Function 56H (0x56 or 86) --> Rename file
Call with: AH = 56H
DS: DX = segment: offset of current ASCIIZ
pathname
ES: DI = segment: offset of new ASCIIZ
pathname
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function Renames a file and/or moves its directory entry to a different on the same disk. In MS-DOS versions 3.0 and later, this function can also be used to rename directories
If any element of the pathname does not exist or a file with the new pathname already exists or the current pathname specification contains a different disk drive than does the new pathname or the file is being moved to the root directory, and the root directory is full or user has insufficient rights, function to rename files fails.
INT 21H (0x21)
Function 57H (0x57 or 87) --> Get or set file date and time
Call with: If getting date and time
AH = 57H
AL = 00H
BX = handle
If setting date and time
AH = 57H
AL = 01H
BX = handle
CX = time
bits 00H-04H = 2-second increments (0-29)
bits 05H-0AH = minutes (0-59)
bits 0BH-0FH = hours (0-23)
DX = date
bits 00H-04H = day (1-31)
bits 05H-08H = month (1-12)
bits 09H-0FH = year (relative to 1980)
Returns: If function successful
Carry flag = clear
and, if called with AL = 00H
CX = time
DX = date
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function obtains or modifies the date and time stamp in the root directory entry of file.
INT 21H (0x21)
Function 58H (0x58 or 88) --> Get or set allocation strategy
Call with: If getting strategy code
AH = 58H
AL = 00H
If setting strategy code
AH = 58H
AL = 01H
BX = desired strategy code
00H = first fit
01H = best fit
02H = last fit
Returns: If function successful
Carry flag = clear
and, if called with AL = 00H
AX = current strategy code
If function unsuccessful
Carry flag = set
AX = error code
Comments:
Obtains or changes the code indicating the current MS-DOS strategy for allocating memory blocks. The default MS-DOS memory allocation strategy is First Fit (code 0).
In the First fit memory allocation, MS-DOS searches the available memory blocks from low address to high address, assigning the first one large enough to satisfy the block allocation request.
In case of Best fit allocation strategy, MS-DOS searches all available memory blocks and assigns the smallest available block that will satisfy the request, regardless of its position.
In the Last fit memory allocation strategy, MS-DOS searches the available memory blocks from high addresses to low addresses, assigning the highest one large enough to satisfy the block allocation request.
INT 21H (0x21)
Function 59H (0x59 or 89) --> Get extended error
Information
Call with: AH = 59H
BX = 00H
Returns: AX = extended error code
Table of error codes has been given below:
Error Code |
Error |
01H |
function number invalid |
02H |
file not found |
03H |
path not found |
04H |
too many open files |
05H |
access denied |
06H |
handle invalid |
07H |
memory control blocks destroyed |
08H |
insufficient memory |
09H |
memory block address invalid |
0AH (10) |
environment Invalid |
0BH (11) |
format invalid |
0CH (12) |
access code invalid |
0DH (13) |
data invalid |
0EH (14) |
unknown unit |
0FH (15) |
disk drive invalid |
10H (16) |
attempted to remove current directory |
11H (17) |
not same device |
12H (18) |
no more files |
13H (19) |
disk write-protected |
14H (20) |
unknown unit |
15H (21) |
drive not ready |
16H (22) |
unknown command |
17H (23) |
data error (CRC) |
18H (24) |
bad request structure length |
19H (25) |
seek error |
1AH (26) |
unknown media type |
1BH (27) |
sector not found |
1CH (28) |
printer out of paper |
1DH (29) |
write fault |
1EH (30) |
read fault |
1FH (31) |
general failure |
20H (32) |
sharing violation |
21H (33) |
lock violation |
22H (34) |
disk change invalid |
23H (35) |
FCB unavailable |
24H (36) |
sharing buffer exceeded |
25H-31H |
reserved |
32H (50) |
unsupported network request |
33H (51) |
remote machine not listening |
34H (52) |
duplicate name on network |
35H (53) |
network name not found |
36H (54) |
network busy |
37H (55) |
device no longer exists on network |
38H (56) |
net BIOS command limit exceeded |
39H (57) |
error in network adapter hardware |
3AH (58) |
incorrect response from network |
3BH (59) |
unexpected network error |
3CH (60) |
remote adapter incompatible |
3DH (61) |
print queue full |
3EH (62) |
not enough space for print file |
3FH (63) |
print file canceled |
40H (64) |
network name deleted |
41H (65) |
network access denied |
42H (66) |
incorrect network device type |
43H (67) |
network name not found |
44H (68) |
network name limit exceeded |
45H (69) |
net BIOS session limit exceeded |
46H (70) |
file sharing temporarily paused |
47H (71) |
network request not accepted |
48H (72) |
print or disk redirection paused |
49H-4FH |
reserved |
50H (80) |
file already exists |
51H (81) |
reserved |
52H (82) |
cannot make directory |
53H (83) |
fail on INT 24H (critical error) |
54H (84) |
too many redirections |
55H (85) |
duplicate redirection |
56H (86) |
invalid password |
57H (87) |
invalid parameter |
58H (88) |
network device fault |
59H (89) |
function not supported by network |
5AH (90) |
required system component not installed |
BH = error class
01H |
if out of resource (such as storage or handles) |
02H |
if not error, but temporary situation (such as locked region in file) that can be expected to end |
03H |
if authorization problem |
04H |
if internal error in system software |
05H |
if hardware failure |
06H |
if system software failure not the fault of the active process (such as missing configuration files) |
07H |
if application program error |
08H |
if file or item not found |
09H |
if file or item of invalid type or format |
0AH (10) |
if file or item locked |
0BH (11) |
if wrong disk in drive, bad spot on disk, or storage medium problem |
0CH (12) |
if item already exists |
0DH (13) |
unknown error |
BL = recommend action
01H |
Retry reasonable number of times, then prompt user to select abort or ignore |
02H |
retry reasonable number of times with delay between retries, then prompt user to select abort or ignore |
03H |
get correct information from user (typically caused by incorrect file name or device specification) |
04H |
abort application with cleanup (i.e., terminate the program in as orderly a manner as possible: releasing locks, closing files, etc.) |
05H |
perform immediate exit without cleanup |
06H |
ignore error |
07H |
retry after user intervention to remove cause of error |
CH = error locus
01H unknown
02H block device (disk or disk emulator)
03H network
04H serial device
05H memory
ES: DI = ASCIIZ volume label of disk to
insert, if AX = 0022H (invalid disk change)
Comments:
This function obtains detailed error information after a previous unsuccessful INT 21H function call, including the recommended remedial action.
INT 21H (0x21)
Function 5AH (0x5A or 90) --> Create temporary
file
Call with: AH = 5AH
CX = attribute (bits may be combined)
DS: DX = segment: offset of ASCIIZ path
Returns: If function is successful
Carry flag = clear
AX = handle
DS: DX = segment: offset of complete ASCIIZ
pathname
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This function creates a file with a unique name, in the current or specified directory on the default or specified disk drive, and returns a handle that can be used by the program by the program for subsequent access to the file. The name generated for the file is also returned in a buffer specified by the program.
If any element of the pathname does not exist or the file is being created in the root directory, and the root directory is full the function fails.
INT 21H (0x21)
Function 5BH (0x5B or 91) --> Create new file
Call with: AH = 5BH
CX = attribute (bits may be combined)
DS: DX = segment: offset of ASCIIZ pathname
Returns: If function is successful
Carry flag = clear
AX = handle
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This function creates a file in the designated or default directory on the designated or default drive, and returns a handle that can be used by the program for subsequent access to the file for a given ASCIIZ pathname.
If a file with the same name and path already exists or any element of the specified path does not exist or the file is being created in the root directory, and the root directory is full or the user has insufficient access rights, the function fails.
INT 21H (0x21)
Function 5CH (0x5C or 92) --> Lock or unlock file region
Call with: AH = 5CH
AL = 00H if locking region
01H if unlocking region
BX = handle
CX = high part of region offset
DX = low part of region offset
SI = high part of region length
DI = low part of region length
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function locks or unlocks the specified region of a file. This function is not available unless the file-sharing module (such as SHARE.EXE) is loaded.
INT 21H (0x21)
Function 5DH (0x5D or 93) --> Reserved
INT 21H (0x21)
Function 5EH (0x5E or 94), sub function 00H (0x00)
--> Get machine name
Call with: AH = 5EH
AL = 00H
DS: DX = segment: offset of buffer to receive
string
Returns: If function is successful
Carry flag = clear
CH = 00H if name not defined
<> 00H if name defined
CL = netBIOS name number (if CH <> 0)
DX: DX = segment: offset of identifier (if CH <> 0)
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function returns the address of an ASCIIZ string identifying the local computer. This function call is only available when the Microsoft Network is running.
INT 21H (0x21)
Function 5EH (0x5E or 94), sub function 02H (0x02)
--> Set printer setup string
Call with: AH = 5EH
AL = 02H
BX = redirection list index
CX = length of setup string
DS: SI = segment: offset of setup string
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function specifies a string to be sent in front of all files directed to a particular network printer, allowing users at different network nodes to specify individualized operating modes on the same printer.
INT 21H (0x21)
Function 5EH (0x5E or 94), sub function 03H (0x03)
--> Get printer setup string
Call with: AH = 5EH
AL = 03H
BX = redirection list index
ES: DI = segment: offset of buffer to receive
setup string
Returns: If function successful
Carry flag = clear
CX = length of printer setup string
ES: DI = segment: offset of buffer to receive
setup string
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function is used to obtain the printer setup string for a particular network printer.
INT 21H (0x21)
Function 5FH (0x5F or 95), sub function 02H (0x02)
--> Get redirection list entry
Call with: AH = 5FH
AL = 02H
BX = redirection list index
DS: SI = segment: offset of 16-byte buffer to
receive local device name
ES: DI = segment: offset of 128-byte buffer to
receive network name
Returns: If function successful
Carry flag = clear
BH = device status flag
Bit 0 = 0 if device valid
= 1 if not valid
BL = device type
03H, if printer
04H, if drive
CX = stored parameter value
DX = destroyed
BP = destroyed
DS: SI = segment: offset of ASCIIZ local
device name
ES: DI = segment: offset of ASCIIZ network
name
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function allows inspection of the system redirection list, which associates local logical names with network files, directories, or printers. This function call is only available when Microsoft Networks is running and the file-sharing module has been loaded.
INT 21H (0x21)
Function 5FH (0x5F or 95), sub function 03H (0x03) --> Redirect device
Call with: AH = 5FH
AL = 03H
BL = device type
03H, if printer
04H, if drive
DS: SI = segment: offset of ASCIIZ local
device name
ES: DI = segment: offset of ASCIIZ network
name, followed by ASCIIZ password
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
Establishes redirection across the network by associating a local device name with a network name. This function call is only available when Microsoft Networks is running and the file-sharing module (SHARE.EXE) has been loaded.
INT 21H (0x21)
Function 5FH (0x5F or 95), sub function 04H (0x04)
--> Cancel device redirection
Call with: AH = 5FH
AL = 04H
DS: SI = segment: offset of ASCIIZ local
device name
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This sub function cancels a previous redirection request by removing the association of a local device name with a network name. This function call is only available when Microsoft Networks is running and the file-sharing module such as SHARE.EXE has been loaded.
INT 21H (0x21)
Function 60H (0x60 or 96) --> Reserved
INT 21H (0x21)
Function 61H (0x61 or 97) --> Reserved
INT 21H (0x21)
Function 62H (0x62 or 98) --> Get Program Segment
Prefix (PSP) address
Call with: AH = 62H
Returns: BX = segment address of program segment
prefix
Comments:
This function obtains the segment (paragraph) address of the Program Segment Prefix (PSP) for the currently executing program.
INT 21H (0x21)
Function 64H (0x64 or 100) --> Reserved
INT 21H
Function 65H (0x65 or 101) --> Get extended
country Information
Call with: AH = 65H
AL = sub function
00H = Get General
Internationalization Information
02H = Get Pointer to Uppercase
Table
04H = Get Pointer to Filename
Uppercase Table
06H = Get Pointer to Collating Table
07H = Get Pointer to Double-Byte
Character Set (DBCS) Vector
BX = code page of interest (-1 = active
CON device)
CX = length of buffer to receive
information (must be >=5)
DX = country ID (-1 = default)
ES: DI = address of buffer to receive
information
Returns: If function successful
Carry flag = clear
And requested data placed in calling program’s buffer
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This obtains information about the specified country and/or code page. Refer internationalization table given before to know about information bytes.
INT 21H (0x21)
Function 66H (0x66 or 102) --> Get or set code
page
Call with: AH = 66H
AL = sub function
01H = Get Code Page
02H = Select Code Page
BX = code page to select, if AL = 02H
Returns: If function is successful
Carry flag = clear
And, if called with AL = 01H
BX = active code page
DX = default code page
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This function obtains or selects the current code page.
INT 21H (0x21)
Function 67H (0x67 or 103) --> Set handle count
Call with: AH = 67H
BX = number of desired handles
Returns: If function is successful
Carry flag = clear
If function is unsuccessful
Carry flag = set
AX = error code
Comments:
This function sets the maximum number of files and devices that may be opened simultaneously using handles by the current process.
INT 21H (0x21)
Function 68H (0x68 or 104) --> Commit file
Call with: AH = 68H
BX = handle
Returns: If function successful
Carry flag = clear
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function forces all data in internal buffers of MS DOS associated with a specified handle to be physically written to the device. If the handle refers to a file, and the file has been modified, the time and date stamp and file size in the root directory entry of file, are updated.
INT 21H (0x21)
Function 69H (0x69 or 105) --> Reserved
INT 21H (0x21)
Function 6AH (0x6A or 106) --> Reserved
INT 21H (0x21)
Function 6BH (0x6B or 107) --> Reserved
INT 21H (0x21)
Function 6CH (0x6C or 108) --> Extended open file
Call with: AH = 6CH
AL = 00H
BX = open mode
Bit(s) |
Significance |
0-2 |
Access type
000 = read-only
001 = write-only
010 = read/write |
3 |
Reserved (0) |
4-6 |
Sharing mode
000 = compatibility
001 = deny read/write (deny all)
010 = deny write
011 = deny read
100 = deny none |
7 |
Inheritance
0 = child process inherits handle
1 = child does not inherit handle |
8-12 |
Reserved (0) |
13 |
Critical error handling
0 = execute INT 24H
1 = return error to process |
14 |
Write-through
0 = writes may be buffered and deferred
1 = physical write at request time |
15 |
Reserved (0) |
CX = file attribute (bits may be combined;
if ignored if openrefer Bits Significance table.
DX = open flag
Bit(s) |
Significance |
0-3 |
Action if file exists
0000 = fail
0001 = open file
0010 = replace file |
4-7 |
Action if file does not exists
0000 = fail
0001 = create file |
8-15 |
Reserved (0) |
DS: SI = segment: offset of ASCIIZ pathname
Returns:mIf function successful
Carry flag = clear
AX = handle
CX = action taken
1 = file existed and was
opened
2 = file did not exists and
was created
3 = file existed and was
replaced
If function unsuccessful
Carry flag = set
AX = error code
Comments:
This function opens, creates or replaces a file in the designated or default directory on the designated or default disk drive for a given ASCIIZ pathname and returns a handle that can be used by the program for subsequent access to the file.
If any element of the pathname does not exist or the file is being created in the root directory and the root directory is full or the file is being created and a file with the same name and the read-only attribute already exists in the specified directory or the user has insufficient access rights, the function fails.
Page Modified on: 10/01/2022