Download ibm pc assembly language - Ron Burkey`s Project Page
Transcript
IBM-PC ASSEMBLY-LANGUAGE LECTURE NOTES PAGE 206/361 The PROCESS STEP. When we get to the SORT STEP, we will find it convenient to have previously calculated (and stored in memory) the length of each text line -- rather than simply to have the lines terminated with CR/LFs as they are when read in from the disk. For convenience, we will impose the condition that all lines contain between 0 and 255 characters. Lines longer than 255 characters will be truncated. This means that a byte variable suffices to hold the line length. We will insist that this byte count be stored in the byte immediately preceding the line. Denoting the line length by "<COUNT>", the PROCESS step consists of converting a line like This is the forest primeval<CR><LF> to <COUNT>This is the forest primeval Also, a pointer to this string (i.e., a word whose value is the offset of <COUNT>) must be added to the end of the pointer array. In the example shown, <COUNT> is 27 since the line (exclusive of the CR/LF) contains 27 characters. This can, perhaps, be made clearer by considering a fictitious example in which a data structure such as the one we are considering has been set up by means of DBs and DWs rather than by calculation: ; Sample data structure of strings pointed to by a pointer array. ; The strings: STRING2 DB 27,"No it's not, it's Cleveland" ... (Anything) ... STRING1 DB 27,"This is the forest primeval" ... (Anything) ... STRING3 DB 19,"Somebody's confused" . . . ; The pointer array: POINTERS DW OFFSET STRING1 DW OFFSET STRING2 DW OFFSET STRING3 . . . Fortunately, no movement of the text is needed to set up this data structure. There is at least one usable byte for the count in front of every text line (except the very first line) since there must be a carriage return (which we don't need in our data structure) at the end of the preceding text line. Since we have pointers to the strings, we don't care about the exact placement of the strings in memory, nor about the relative positions of the strings, nor about garbage between the strings (such as carriage return characters). The pointer array is much like the buffer we used in our simple typewriter program (except that it holds words rather than bytes), so you must provide an appropriate error message and exit in case there are more lines of text in the file than you have provided for in your array. I would suggest that (throughout the PROCESS STEP) BX be mainly HANDOUT