IUP Computer Science
COSC 300 Spring 2001

Assignment #2
(Due in class on 19 February 2001)

Write an assembly language program that counts the approximate number of words and lines in a portion of text. The program should declare one or more variables that hold character information (the text). The total number of characters may NOT be stored in a variable in the program; also, the total number of characters may NOT be used as a constant (numeric or symbolic) in the program. The total number of characters should be greater than 100 and the collection of characters should occupy at least three lines, if it were output to the screen.

The program should use program offset information to determine how many characters are stored and then use that number in loop control to examine the text and count space and linefeed characters. The number of words in any given text is approximately the number of spaces + the number of linefeeds + 1; the number of lines is approximately the number of linefeeds + 1. Below is an example of the something you might use as the text, although it is a bit on the short side. Do not use this sample in your program; use something that is longer.

first     db   "Here are a few words",0dh,0ah
          db   "that occupy several lines.  They are not very "
last      db   "interesting.",0dh,0ah,0ah,"But they work."
Your program should examine each character of this text. Space characters and linefeed characters should cause the number of words to be incremented (keep this in the 16-bit variable WORDS); linefeeds should also cause the number of lines to be incremented (keep this in the 16-bit variable LINES). For the text above, the program should have 19 (0013 in hexadecimal) in WORDS and 4 (0004 in hexadecimal) in LINES when it is finished. There are no restrictions on the characters in the text, except that they must be displayable (or, like 0dh and 0ah, control the display).

Hand in an assembly-generated listing of your well-commented program.

Note: Do NOT attempt to input the text to be examined; it must be declared in the program itself. Note: Counting in the manner suggested above does NOT necessarily produce an accurate count for words or lines - there are only 17 words above. Don't let this bother you, just count the words and lines as indicated, by recognizing space and linefeed characters.