head	1.3;
access;
symbols;
locks
	yap:1.3; strict;
comment	@# @;


1.3
date	97.11.05.19.44.00;	author yap;	state Exp;
branches;
next	1.2;

1.2
date	97.10.30.17.23.56;	author yap;	state Exp;
branches;
next	1.1;

1.1
date	97.10.29.23.34.21;	author yap;	state Exp;
branches;
next	;


desc
@@


1.3
log
@*** empty log message ***
@
text
@<html>
<title>
	Homework 3:
	V22.0201.002, Machine Org I,
	Fall 1997,
	Chee Yap
</title>
<body bgcolor=fafafa>

<center>
        <h3><font color=aa0000>
	Fall 1997, Professor Yap<br>
        V22.0201.002, Machine Organization I
        </font> </h3>
        <h2><font color=aa00ff>
        HOMEWORK 3
	<br>
	<b> Due</b>: Wed November 5, 1997
        </font>
        </h2>
</center>
<hr>

<h3><font color=aa0000>
INTRODUCTION
</font></h3>

This assignment requires you to write procedures,
and gives you some exercise in manipulating strings.
For the latter, you need to read chapter 11.

Basically, you have to write a procedure to
sort a sequence of strings.  For instance, if
the input strings are
	<pre>
	'abc', 'hey', 'a', 'heee'
	</pre>
Then the sorted output (in increasing order) is the sequence
	<pre>
	'a', 'abc', 'heee', 'hey'.
	</pre>
There is a sorting procedure called SELECT in the textbook
(section 10.3, page 189).   However,
procedure SELECT sorts an array of numbers. 
We want to modify SELECT so that it sorts
an array of strings.


<h3><font color=aa0000>
DETAILS
</font></h3>

<ol>
<li>
First of all, how do you represent strings?
We will use the convention in exercise 11, chap.11 (p.227) for
representing strings.  First define
	<pre>
	MAX_LEN EQU	20
	</pre>
Your program should work in case we replace ``20'' by any other value.
Assume our strings are at most MAX_LEN characters long, and
the end of a string is indicated by storing a carriage return
(CR or 0Dh).
So the <b>actual length</b> of a string is a number between 0 and
MAX_LEN.
Note that the CR is not counted in the actual length.
In addition to strong CR, we also need two other bytes: the first
byte stores the number MAX_LEN, and the second byte stores the
actual length of the string.  So we need to reserve MAX_LEN+3 bytes 
for each string.

<li>
Next you need a procedure to compare two strings.  
Exercise 10 (chap.11, p.227) describes such a procedure.
Please implement this procedure, and call it <b>COMP</b>.
Note that the string of length 0 is smaller than any other strings,
and COMP must be able to handle this case.
The individual characters of a string are compared by
using their ASCII code.  E.g.,
	<pre>
   '!' < '&' < '0' < '1' < 'A' < 'Z' < 'a' < 'b' < '{'
	</pre>
You may assume only printable ASCII codes are in a string
and CR is not in the string.
COMP must be <b>general</b>, i.e., it must not assume that the two
strings to be compared have length MAX_LEN or that they have
the same maximum length.
Assume that COMP returns a value of -1 (if less than),
0 (if equal) and +1 (if greater than).

<li>
Next, adapt the procedure SELECT so that it calls
procedure <b>COMP</b> instead of using the machine instruction <b>CMP</b>.
Call your sorting procedure <b>MYSORT</b>.
You should retain the conventions and logic of procedure
SELECT as much as possible.  In particular,
the input and output conventions of MYSORT should
be those of SELECT (appropriately modified, of course).
Note that SELECT calls a SWAP procedure.  You also
need to modify SWAP.

<li>
The overall program should have the title of ``TEST MYSORT''
and it should be an adaptation of PGM10_3.ASM (p.191).
The data array A in this program should be initialized to
contain the following 16 strings:
	<pre>
	'are',	'at',	'as',	'by',	'but',	'be',
	'91',	'Johnson',	'ASCII', 'USA',	'New York',
	'John',	'a1',	'Number One',	'!!!', 'yap@@cs.nyu.edu'
	</pre>
You must write a procedure called PRINT which outputs the strings in
array A.  Make sure that you call PRINT <b>before</b> and
<b>after</b> sorting in the main program.
NOTE: You can adapt a very similar
procedure found in p.212 of the textbook (PGM 11_2.asm).

<li>
This assignment is worth 40 points.
Here is the breakdown of these points.
	<ul>
	<li>
	If your program executes correctly, you automatically
	get 15 points.  <b>If it does not assemble</b>, you get nothing
	out of these 15 points.  So make sure you get rid of all
	syntax errors!
	<li>
	We give up to 5 points for useful and
	good comments (including specifying the input and output
	before of each procedure).
	<li>
	We give up to 5 points for elegant design of
	your program.  NOTE: usually, elegant programs are
	also small and compact.
	<li>
	Up to 5 points for use of the string instructions
	(found in chapter 11).
	<li>
	Up to 7 points for proper packaging of your homework
	(details below).
	<li>
	3 discretionary points.
	</ul>
</ol>

<h3><font color=aa0000>
TO BE HANDED IN
</font></h3>

<ol>
<li> A 3.5'' disk containing
	your program file (named <b>hw3.asm</b>),
	an executable (named <b>mysort.exe</b>),
	and a bat file called <b>db.bat</b>.
	The db.bat file contains the following lines
	<pre>
	@@rem debug batch file
	echo DEBUGGING HW3
	tasm /z /zi hw3
	tlink /v hw3
	td hw3
	echo DONE DEBUGGING HW3
	</pre>
	REASON: we want to execute db.bat to get quickly into
	the turbo debugger to examine your sorting program.
	[3 pts]
<li> A printout of your program hw3.asm.
	[2 pts]
<li> Hand in everything in an envelop (prefer smaller envelops).
	Please write your name, ID, ``HW3'',
	and class information on the envelop
	and also on the diskette.
	Please DO NOT use any of the NYU envelops.
	[2 pts]
</ol>

<h3><font color=aa0000>
APPENDIX (subsequent information)
</font></h3>

<ol>
<li>
	Apparently (as demonstrated in class today), there
        is some descrepancy between int 21h, function 10 as
        described in the book (exercise 11, p.227) and
        what happens on my machine (and presumably yours as well).
        The difference is minor -- if the MAX_LEN of a
        a string is 20, say, then my machine allows only
        up to 19 characters (not counting the final CR character).
        In the following, I will follow the book's assumption.
        (This does no harm for my machine -- it
        only wastes one byte per string, since the last
        byte will never be used.)
<br>
        A slight elaboration of the program I demo'ed in
        class is available as <b>readstring.asm</b>
        from the sample programs directory here.
 
<li>
	Several of you wondered how to enter the strings
        into your program.  Here is how I would do it: to enter
        the strings
        <pre>
        'are', 'at, 'zzzz', etc,
        </pre>
        into the array A, my data segment will look like this:
        <pre>
        .data
        A db    MAX_LEN,3,'are',CR,MAX_LEN-3 dup (?)
          db    MAX_LEN,2,'at',CR,MAX_LEN-2 dup (?)
          db    MAX_LEN,4,'zzzz',CR,MAX_LEN-4 dup (?)
          ... etc
        </pre>

<li> In your diskette, please do not leave unnecessary
	files around.  If you have such files, I suggest
	you create a subdirectory called "old" and move
	them into old.  E.g., hw1.asm should be there.

<li> Some students pointed out that when they call their
	mysort program, the printout on the screen just
	flashes by quickly and one cannot see what is printed
	out first.  There are three solutions to this:
	<ul>
	<li> You can insert some "pause" instructions to
		slow down the output.  E.g., print a
		string "PLEASE TYPE ANY KEY" and then
		call function 1, int 21h (to read the
		key input, which is of course discarded).

	<li> You can redirect the output of your program into
		a file.  E.g.,
		<pre>
		:> mysort > outfile
		</pre>
		will put the output of mysort into the file "outfile".
	<li> You can "pipe" the output through the "more" program:
		<pre>
		:> mysort | more
		</pre>
		and this will pause when the output fills one screenful.
		You need to type a space for it to continue.
	</ul>
	NOTE: if you are familiar with UNIX, solutions (2) and (3) are
		standard paradigms in UNIX.

</ol>
</body>
</html>

@


1.2
log
@*** empty log message ***
@
text
@d125 3
a127 2
	15 points.  It it does not assemble, you get nothing
	out of these 15 points.
d178 71
@


1.1
log
@Initial revision
@
text
@d116 2
d121 1
a121 1
Here are some breakdown of these points.
d125 2
a126 2
	18 points.  It it does not assemble, you get nothing
	out of these 18 points.
d132 1
a132 1
	We give up to 7 points for elegant design of
d135 8
@
