CSc 3210
Computer Organization and Programming
Fall 1999
Programming Assignment #5 (29 November 1999, Monday)

Assignment Objectives: To learn how to manipulate disk files using DOS services, process command line parameters, read lines of text from ascii files, search for substrings, and to become more proficient at writing assembly programs.

Problem Description: Write an assembler program that will perform a search of individual lines of text within text files for a given pattern. The pattern (a fixed string) to be searched will be the first of two command line parameters to your program. The second command line parameter will be a file specification (may include wild card characters * and ?). There could be any number of spaces between the command line parameters. If the search command is executed with fewer than two command line parameters, your program should respond with the message:

Usage: search pattern file-spec
after displaying this message the program should terminate.

Submission Instructions: Submit search.asm and search.exe by the deadline and submit program listing of search.asm.

Hints:

  1. The command line is stored in the program segment prefix (PSP) at offset 81H. The program name itself (search) is not stored there, however. The byte at offset 80H indicates the length of the string that begins at 81H. The segment address of the PSP is stored in DS and ES when the program begins to execute. See pages 447-452 of the text for more details.
  2. Your program should read blocks of 512 bytes from the input files; reading bytes one at a time is too slow. You must use a buffering scheme in which you will store the 512 bytes read from the input files in a buffer. A separate procedure to read a line of text from the buffer should be written. The buffer should be refilled with the next 512 bytes from the input file once the end of the buffer is reached. This process continues until end of file is detected (attempt is made to read the next 512 bytes from file when there are no more bytes left).
  3. Use the following DOS services (in addition to any others you have used in the past assignments):
      INT  21H, Function 4EH  ; Find first matching file
      INT  21H, Function 4FH  ; Find next matching file
      INT  21H, Function 3DH  ; Open file
      INT  21H, Function 3EH  ; Close file
      INT  21H, Function 3FH  ; Read record from file
      INT  21H, Function 1AH  ; Set the Disk Transfer Area (DTA)

  4. It would be useful to write the following procedures:

The following is a sample output assuming that there are only two files which match the file specification *.tex (f1.tex and f2.tex),

A:>type f1.tex
This is line 1 of f1.tex
This is line 2 of f1.tex
This is Line 3 of f1.tex
This is line 4 of f1.tex
This is Line 5 of f1.tex
This is Line 6 of f1.tex
This is line 7 of f1.tex
This is Line 8 of f1.tex
This is line 9 of f1.tex
This is Line 10 of f1.tex
This is line 11 of f1.tex
This is the last line (12) of f1.tex

A:>type f2.tex
This is line 1 of f2.tex
This is 2 of f2.tex
This is the last line of f2.tex

A:>search line *.tex
   1:F1.TEX:This is line 1 of f1.tex
   2:F1.TEX:This is line 2 of f1.tex
   4:F1.TEX:This is line 4 of f1.tex
   7:F1.TEX:This is line 7 of f1.tex
   9:F1.TEX:This is line 9 of f1.tex
  11:F1.TEX:This is line 11 of f1.tex
  12:F1.TEX:This is the last line (12) of f1.tex
   1:F2.TEX:This is line 1 of f2.tex
   3:F2.TEX:This is the last line of f2.tex



Raj Sunderraman
Mon Nov 10 21:14:10 PST 1997