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 *.txtThe 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-specAfter 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:
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)
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