Professional Documents
Culture Documents
Data Conversions
Describes conversions between binary and ASCII Binary data are removed from a register or memory and converted to ASCII for the video display
Example 7-27 illustrates a program that uses the procedure DISP that processes the binary value in AL (0-99) and display it on the video screen as decimal
Example 7-29 illustrates a procedure (READN) used in a program that implements this algoritm
Using Lookup Tables for Data Conversions A lookup table is formed in the memory as a list of data that is referenced by a procedure to perform conversions is used XLAT instruction
Disk Files
Data are found stored on the disk in the form of files The disk is organized in four main parts :
the boot sector the file allocation table (FAT) the root directory the data storage
Disk Organization Fig. 7-2 illustrates the organization of sectors and tracks on the surface of the disk Fig. 7-3 shows the organization of data on a disk
Disk Files(contd)
File Creation
A file is created by the INT 21 H function call number 3CH The file name must be stored at a location addressed by DS:DX before calling the function CX must contain the attribute of the file (or subdirectory) created An ASCII-Z string is a character string that ends with a 00H or null character Example 7-37 lists a short procedure that creates the new file on the disk Table 7-5 lists and defines the attribute bit positions
Disk Files(contd)
Writing to a File
Before writing to a file, the file must have been created or opened The file handle is used to refer to the file whenever data are written Function number 40H is used to write data to an opened or newly created file. In addition to loading a 40H into AH, we must also load BX = the file handle, CX = the number of bytes to be written, and DS:DX = the address of the area to be written to the disk ( see Example 7-38 and 7-39)
Disk Files(contd)
The File Pointer
It is a 32-bit number that addresses any byte in a file Once a file is opened, the file pointer can be changed with the move file pointer function number 42H A file pointer can be moved : from the start of the file (AL=00H) from the current location (AL=01H) from the end of the file (AL=02H) The distance moved by the file pointer is specified by registers CX and DX
Disk Files(contd)
Register BX must contain the file handle before using function 42H to move the file pointer Example 7-40 shows a procedure that opens a file, moves the file pointer to the end of the file, writes 256 bytes of data, and then closes the file Fig. 7-5 shows how this is accomplished by creating a second file (see Example 7-41)
Example Programs
Calculator Program This program demonstrates how data conversion plays an important part in many application programs (see Example 7-44)
Numeric Sort Program Fig. 7-6 shows five numbers that are sorted with a bubble sort Example 7-45 illustrates a program that accepts 10 numbers from the keyboard (0-65535)
Interrupt Hooks
Hooks are used to tap into or intercept the interrupt structure of the microprocessor a special keystroke, called a hot key, can be detected when we hook into the keyboard interrupt Whenever the hot-key is typed, a terminate and stay resident (TSR) program that performs a special task, can be accessed see Example 7-48