CSc 343
Computer Organization and Programming
Spring Quarter 1998
Programming Assignment #4 (3 June 1998, Wednesday)

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

Problem Description: Write an assembler program that will count the number of characters, words and lines in text files. The following is some of the many ways you should be able to run your program.

A:\>wc *.txt
A:\>wc /lcw *.txt
A:\>wc /lc *.txt
A:\>wc /l *.txt
A:\>wc /c *.txt
The program should be called wc and it has at least one command line parameter, the file specification. An optional parameter may precede the file specification which starts with a slash (/) and has any subset of the three letters l, c, w after the slash. When the program is invoked without the optional parameter, the /lcw option should be implemented. The l character in the optional parameter requests a count of the lines, the w character requests a count of words (assume a word to be a continuous string of non-white-space character; white-space character is a space, tab or newline), and the c character requests a count of the characters, which includes all characters including the newlines, tabs etc. The file specification may include wild card characters * and ?.

The output should be one line per file and one summary line. A sample run is shown at the end. If the wc command is executed with invalid command line parameters, your program should respond with the message:

Usage: wc -lcw file-spec
After displaying this message the program should terminate.

Submission Instructions: Electronically submit wc.asm and wc.exe by the deadline and submit program listing of wc.asm.

Hints:

  1. The command line is stored in the program segment prefix (PSP) at offset 81H. The program name itself (wc) 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 three files which match the file specification *.sql (t.sql, test.sql and upd.sql),

A:>type t.sql
select e.fname,e.minit,e.lname,e.ssn,sum(w.hours)
                from csc498.employee e,csc498.works_on w
            where e.ssn=w.essn
            group by e.ssn,e.fname,e.lname,e.minit
            order by sum(w.hours) desc;
A:>type test.sql
create table t1 (a integer, b char(10), c char(10));
create table t2 (a integer not null, b char(10), primary key (a));
insert into t1 (b,c) values ('Jones','aaa');
insert into t1 (b,c) values ('Smith','bbb');
insert into t1 (b,c) values ('Blake','ccc');
insert into t2 values (111,'Jones');
insert into t2 values (222,'Blake');
insert into t2 values (333,'Smith');

A:>type upd.sql
update t1
set    a = (select a from t2 where t1.b = t2.b);
A:>wc -lcw *.sql
   Lines   Words Characters File
       5      15        229 t.sql
       9      54        367 test.sql
       2      13         59 upd.sql
      16      82        655 total



Raj Sunderraman
Thu May 21 1998