Tekil Mesaj gösterimi
Alt 06-09-2008, 15:13   #9
Constantin
ยŦยк
 
Constantin - ait Kullanıcı Resmi (Avatar)
 

FCB method


Introduction
There are two types of FCB, the normal, whose length is 37 bytes and the extended one of 44 bytes.On this tutorial we will only deal with the first type, so from now on whenI refer to an FCB, I am really talking about a 37 bytes FCB.

The FCB is composed of information given by the programmer and by information which it takes directly from the operative system. When thesetypes of files are used it is only possible to work on the current directory since the FCBs do not provide sport for the use of the organization by directories of DOS.
The FCB is formed by the following fields:
POSITION LENGTH MEANING
00H 1 Byte Drive
01H 8 Bytes File name
09H 3 Bytes Extension
0CH 2 Bytes Block number
0EH 2 Bytes Register size
10H 4 Bytes File size
14H 2 Bytes Creation date
16H 2 Bytes Creation hour
18H 8 Bytes Reserved
20H 1 Bytes Current register
21H 4 Bytes Random register
To select the work drive the next format is followed: drive A = 1; drive B = 2; etc. If 0 is used the drive being used at that moment will be taken as option.

The name of the file must be justified to the left and in case it is necessary the remaining bytes will have to be filled with spaces, and the extension of the file is placed the same way.

The current block and the current register tell the computer which register will be accessed on reading or writing operations. A block is a gro of 128 registers. The first block of the file is the block 0. The first register is the register 0, therefore the last register of the first block would be the 127, since the numbering started with 0 and the block can contain 128 registers in total.

Opening files
To open an FCB file the 21H interruption, 0FH function is used. The unit, the name and extension of the file must be initialized before opening it. The DX register must point to the block. If the value of FFH is returned on the AH register when calling on the interruption then the file was not found, if everything came out well a value of 0 will be returned. If the file is opened then DOS initializes the current block to 0, the size of the register to 128 bytes and the size of the same and its date are filled with the information found in the directory.
Creating a new file

For the creation of files the 21H interruption 16H function is used. DX must point to a control structure whose requirements are that at least the logic unit, the name and the extension of the file be defined. In case there is a problem the FFH value will be returned on AL, otherwise this register will contain a value of 0.

Sequential writing

Before we can perform writing to the disk it is necessary to define the data transfer area using for this end the 1AH function of the 21H interruption.

The 1AH function does not return any state of the disk nor or the operation, but the 15H function, which is the one we will use to write to the disk, does it on the AL register, if this one is equal to zero there was no error and the fields of the current register and block are dated.

Sequential reading

Before anything we must define the file transfer area or DTA. In order to sequentially read we use the 14H function of the 21H interruption. The register to be read is the one which is defined by the current block and register. The AL register returns to the state of the operation, if AL

contains a value of 1 or 3 it means we have reached the end of the file. A value of 2 means that the FCB is wrongly structured. In case there is no error, AL will contain the value of 0 and the fields of the current block and register are dated.

Random reading and writing

The 21H function and the 22H function of the 21H interruption are the ones in charge of realizing the random readings and writings respectively.

The random register number and the current block are used to calculate the relative position of the register to read or write.

The AL register returns the same information for the sequential reading of writing. The information to be read will be returned on the transfer area of the disk, likewise the information to be written resides on the DTA.

Closing a file

To close a file we use the 10H function of the 21H interruption.

If after invoking this function, the AL register contains the FFH value, this means that the file has changed position, the disk was changed or there is error of disk access.

Channels of communication
Working with handles

The use of handles to manage files greatly facilitates the creation of files and programmer can concentrate on other aspects of the programming without worrying on details which can be handled by the operative system. The easy use of the handles consists in that to operate o a file, it is only necessary to define the name of the same and the number of the handle to use, all the rest of the information is internally handled by the DOS.

When we use this method to work with files, there is no distinction between sequential or random accesses, the file is simply taken as a chain of bytes.

Functions to use handles
The functions used for the handling of files through handles are described in unit 6: Interruptions, in the section dedicated to the 21H interruption.

Macros and procedures

• Procedures

• Macros
o Definition of a macro
o Syntax of a macro
o Macro libraries
________________________________________
Procedure

Definition of procedure

A procedure is a collection of instructions to which we can direct the flow of our program, and once the execution of these instructions is over control is given back to the next line to process of the code which called on the procedure.

Procedures help us to create legible and easy to modify programs.

At the time of invoking a procedure the address of the next instruction of the program is kept on the stack so that, once the flow of the program has been transferred and the procedure is done, one can return to the next line of the original program, the one which called the procedure.

Syntax of a Procedure

There are two types of procedures, the intrasegments, which are found on the same segment of instructions, and the inter-segments which can be stored on different memory segments.

When the intrasegment procedures are used, the value of IP is stored on the stack and when the intrasegments are used the value of CS:IP is stored.

To divert the flow of a procedure (calling it), the following directive is used:

CALL NameOfTheProcedure

The part which make a procedure are:
Declaration of the procedure
Code of the procedure
Return directive
Termination of the procedure
For example, if we want a routine which adds two bytes stored in AH and AL each one, and keep the addition in the BX register:
Adding Proc Near ; Declaration of the procedure
Mov Bx, 0 ; Content of the procedure
Mov B1, Ah
Mov Ah, 00
Add Bx, Ax
Ret ; Return directive
Add Endp ; End of procedure declaration
On the declaration the first word, Adding, corresponds to the name of out procedure, Proc declares it as such and the word Near indicates to the MASM that the procedure is intrasegment.
The Ret directive loads the IP address stored on the stack to return to the original program, lastly, the Add Endp directive indicates the end of the procedure.

To declare an inter segment procedure we substitute the word Near for the word FAR.

The calling of this procedure is done the following way:
Call Adding
Macros offer a greater flexibility in programming compared to the procedures, nonetheless, these last ones will still be used.

Macros

Definition of the macro

A macro is a gro of repetitive instructions in a program which are codified only once and can be used as many times as necessary.

The main difference between a macro and a procedure is that in the macro the passage of parameters is possible and in the procedure it is not, this is only applicable for the TASM - there are other programming languages which do allow it. At the moment the macro is executed each parameter is substituted by the name or value specified at the time of the call.

We can say then that a procedure is an extension of a determined program, while the macro is a module with specific functions which can be used by different programs.

Another difference between a macro and a procedure is the way of calling each one, to call a procedure the use of a directive is required, on the other hand the call of macros is done as if it were an assembler instruction.

Syntax of a Macro

The parts which make a macro are:

Declaration of the macro
Code of the macro
Macro termination directive

The declaration of the macro is done the following way:
NameMacro MACRO [parameter1, parameter2...]
Even though we have the functionality of the parameters it is possible to create a macro which does not need them.

The directive for the termination of the macro is: ENDM

An example of a macro, to place the cursor on a determined position on the screen is:
Position MACRO Row, Column
PUSH AX
PUSH BX
PUSH DX
MOV AH, 02H
MOV DH, Row
MOV DL, Column
MOV BH, 0
INT 10H
POP DX
POP BX
POP AX
ENDM
To use a macro it is only necessary to call it by its name, as if it were another assembler instruction, since directives are no longer necessary as in the case of the procedures.
Example:
Position 8, 6
Macro Libraries
Constantin Ofline   Alıntı ile Cevapla