Successfully reported this slideshow.
Upcoming SlideShare
×

Chapter7.2-mikroprocessor

477 views

Published on

• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Chapter7.2-mikroprocessor

1. 1. Programming the Microprocessor A Course in Microprocessor Electrical Engineering Dept. University of Indonesia
2. 2. Data Conversions <ul><ul><li>Describes conversions between binary and ASCII </li></ul></ul><ul><ul><li>Binary data are removed from a register or memory and converted to ASCII for the video display </li></ul></ul>
3. 3. <ul><li>Converting from Binary to ASCII </li></ul><ul><ul><li>Conversion from binary to ASCII is accomplished in two ways : </li></ul></ul><ul><ul><ul><li>by the AAM instruction if the number is less than 100 or </li></ul></ul></ul><ul><ul><ul><li>by a series of decimal divisions (divided by 10) </li></ul></ul></ul>Data Conversions (cont’d)
4. 4. Data Conversions (cont’d) <ul><ul><li>The algorithm for converting from binary to ASCII code is : </li></ul></ul><ul><ul><ul><li>Divide by the 10 and save the remainder on the stack as a significant BCD Digit </li></ul></ul></ul><ul><ul><ul><li>Repeat step 1 until the quotient is a 0 </li></ul></ul></ul><ul><ul><ul><li>Retrieve each remainder and add a 30H to convert to ASCII before displaying or printing </li></ul></ul></ul><ul><ul><li>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 </li></ul></ul>
5. 5. Data Conversions (cont’d) <ul><li>Converting from ASCII to Binary </li></ul><ul><ul><li>The algorithm for converting from ASCII to binary is : </li></ul></ul><ul><ul><ul><li>Begin with a binary result of 0 </li></ul></ul></ul><ul><ul><ul><li>Subtract 30H from the character typed on the keyboard to convert it to BCD </li></ul></ul></ul><ul><ul><ul><li>Multiply the result by 10 and add the new BCD digit </li></ul></ul></ul><ul><ul><ul><li>Repeat steps 2 and 3 until the character typed is not an ASCII-coded number </li></ul></ul></ul><ul><ul><li>Example 7-29 illustrates a procedure (READN) used in a program that implements this algorithm </li></ul></ul>
6. 6. Data Conversions (cont’d) <ul><li>Displaying and Reading Hexadecimal Data </li></ul><ul><ul><li>Reading Hexadecimal Data </li></ul></ul><ul><ul><ul><li>see Example 7-30 </li></ul></ul></ul><ul><ul><li>Displaying Hexadecimal Data </li></ul></ul><ul><ul><ul><li>see Example 7-31 </li></ul></ul></ul><ul><li>Using Lookup Tables for Data Conversions </li></ul><ul><ul><li>A lookup table is formed in the memory as a list of data that is referenced by a procedure to perform conversions </li></ul></ul><ul><ul><li>is used XLAT instruction </li></ul></ul>
7. 7. Data Conversions (cont’d) <ul><ul><li>Converting from BCD to 7-segment Code </li></ul></ul><ul><ul><ul><li>Example 7-32 illustrates a lookup table that contains the 7-segment codes for the numbers 0 to 9 </li></ul></ul></ul><ul><ul><li>Using a Lookup Table to Access ASCII Data </li></ul></ul><ul><ul><ul><li>Example 7-33 shows a table that references ASCII-coded character strings located in the code segment </li></ul></ul></ul>
8. 8. Disk Files <ul><ul><li>Data are found stored on the disk in the form of files </li></ul></ul><ul><ul><li>The disk is organized in four main parts : </li></ul></ul><ul><ul><ul><li>the boot sector </li></ul></ul></ul><ul><ul><ul><li>the file allocation table (FAT) </li></ul></ul></ul><ul><ul><ul><li>the root directory </li></ul></ul></ul><ul><ul><ul><li>the data storage </li></ul></ul></ul><ul><li>Disk Organization </li></ul><ul><ul><li>Fig. 7-2 illustrates the organization of sectors and tracks on the surface of the disk </li></ul></ul><ul><ul><li>Fig. 7-3 shows the organization of data on a disk </li></ul></ul>
9. 9. Disk Files (cont’d) <ul><ul><li>Files are usually accessed through DOS INT 21H function calls </li></ul></ul><ul><ul><ul><li>There are two ways to accesse a file using </li></ul></ul></ul><ul><ul><ul><li>INT 21H : </li></ul></ul></ul><ul><ul><ul><ul><li>uses a file control block </li></ul></ul></ul></ul><ul><ul><ul><ul><li>uses a file handle </li></ul></ul></ul></ul><ul><li>Sequential File Access </li></ul><ul><ul><li>All DOS files are sequential files </li></ul></ul>
10. 10. Disk Files(cont’d) <ul><ul><li>File Creation </li></ul></ul><ul><ul><ul><li>A file is created by the INT 21 H function call number 3CH </li></ul></ul></ul><ul><ul><ul><li>The file name must be stored at a location addressed by DS:DX before calling the function </li></ul></ul></ul><ul><ul><ul><li>CX must contain the attribute of the file (or subdirectory) created </li></ul></ul></ul><ul><ul><ul><li>An ASCII-Z string is a character string that ends with a 00H or null character </li></ul></ul></ul><ul><ul><ul><li>Example 7-37 lists a short procedure that creates the new file on the disk </li></ul></ul></ul><ul><ul><ul><li>Table 7-5 lists and defines the attribute bit positions </li></ul></ul></ul>
11. 11. Disk Files(cont’d) <ul><ul><li>Writing to a File </li></ul></ul><ul><ul><ul><li>Before writing to a file, the file must have been created or opened </li></ul></ul></ul><ul><ul><ul><li>The file handle is used to refer to the file whenever data are written </li></ul></ul></ul><ul><ul><ul><li>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 ) </li></ul></ul></ul>
12. 12. Disk Files(cont’d) <ul><ul><li>The File Pointer </li></ul></ul><ul><ul><ul><li>It is a 32-bit number that addresses any byte in a file </li></ul></ul></ul><ul><ul><ul><li>Once a file is opened, the file pointer can be changed with the move file pointer function number 42H </li></ul></ul></ul><ul><ul><ul><li>A file pointer can be moved : </li></ul></ul></ul><ul><ul><ul><ul><li>from the start of the file (AL=00H) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>from the current location (AL=01H) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>from the end of the file (AL=02H) </li></ul></ul></ul></ul><ul><ul><ul><li>The distance moved by the file pointer is specified by registers CX and DX </li></ul></ul></ul>
13. 13. Disk Files(cont’d) <ul><ul><ul><li>Register BX must contain the file handle before using function 42H to move the file pointer </li></ul></ul></ul><ul><ul><ul><li>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 </li></ul></ul></ul><ul><ul><ul><li>Fig. 7-5 shows how this is accomplished by creating a second file (see Example 7-41 ) </li></ul></ul></ul><ul><ul><li>Random Access Files </li></ul></ul><ul><ul><ul><li>Creating a Random Access File (see Example 7-42 ) </li></ul></ul></ul><ul><ul><ul><li>Reading and Writing a Record (see Example 7-43 ) </li></ul></ul></ul>
14. 14. Example Programs <ul><li>Calculator Program </li></ul><ul><ul><li>This program demonstrates how data conversion plays an important part in many application programs (see Example 7-44 ) </li></ul></ul><ul><li>Numeric Sort Program </li></ul><ul><ul><li>Fig. 7-6 shows five numbers that are sorted with a bubble sort </li></ul></ul><ul><ul><li>Example 7-45 illustrates a program that accepts 10 numbers from the keyboard (0-65535) </li></ul></ul>
15. 15. Interrupt Hooks <ul><ul><li>Hooks are used to tap into or intercept the interrupt structure of the microprocessor </li></ul></ul><ul><ul><li>a special keystroke, called a hot key, can be detected when we hook into the keyboard interrupt </li></ul></ul><ul><ul><li>Whenever the hot-key is typed, a terminate and stay resident (TSR) program that performs a special task, can be accessed </li></ul></ul><ul><ul><li>see Example 7-48 </li></ul></ul>