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


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

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


desc
@@


1.2
log
@*** empty log message ***
@
text
@<html>
<title>
	Homework 4:
	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 4
	<br>
	<b> Due</b>: Wed November 26, 1997
        </font>
        </h2>
</center>
<hr>

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

This homework is based on chapters 12 and 13.
It is in two parts, but the two parts are not necessarily related.
PART A tests your knowledge of assembly syntax and simple
use of the debugger.
PART B requires some video text mode programming.
You will also be asked to use MACROS and INCLUDE
statements to organize your program.
<p>
I mentioned in class on Monday that I was hesitating
between requiring you to hand in this homework or not.  But I feel
strongly enough about the usefulness of this exercise for the
final project that I decided that you have to hand it in.
Two concessions are
(i) I will give you 2 weeks to do this,
and (ii) you are to do this in your PROJECT TEAMS.
I suggest that each team immediately schedule a FIRST meeting.
If you delay this you are just taking
up time that you can use for your final project!

<h3><font color=aa0000>
PART A: ASSEMBLY PROGRAMMING KNOWLEDGE
</font></h3>

Please answer the following questions.  
The answers may not be found in the textbook.
The recommended way to answer some of these questions is to
write trivial programs using these instructions,
and assemble them to find out what happens.
If necessary, go into the debugger for more information.
	<ol>
	<li> Which of the following instructions are legal?
		<pre>
	(a) mov ax, WORD PTR bh
	(b) mov BYTE PTR [di], bh
	(c) REP mov ax,bx
	(d) mov es,ds
	(e) mov ah,[ByteVar+3]
	(f) mov si,[si]
	(g) mov sp,ax
	(h) mov sp,WordVar
		</pre>	

	<li> How many bytes are used in the machine
		code for CMPSW? 

	<li> You are using TD to debug a program that displays something
		on the screen.  TD has just
		executed the code that does the display function
		(e.g., int 21h, function 2).
		Without leaving TD, how do you see what is actually
		displayed?  (You need to get out of the debugger
		windows somehow.)  And, how do you return to TD?

	<li> What is wrong with the following macro definition?
		Further, please say what the assembler
		error message is.
		<pre>
		newmac macro n
		mov ax,n
		newmac endm
		</pre>

	</ol>


<h3><font color=aa0000>
PART B: PROGRAMMING
</font></h3>

<ol>
<li>	MACROS.  Please collect the following macros from
        the book (chapter 13) into a file called <b>mymacros.lib</b>
	(lib for ``library'').
        You may add more of your own if you like (but be
	sure to comment them properly so that we can understand
	what these macros do!).
	<pre>
	DOS_RTN, NEW_LINE, DISP_STR, SAVE_REGS, RESTORE_REGS, HEX_OUT
	</pre>
	In the future (e.g., in the game project),
	please use these macros whenever possible.
	You can include the macros in your file using the form
	suggested by the book:
	<pre>
	IF1
		INCLUDE MYMACROS.LIB
	ENDIF
	</pre>
	Whenever you invoke a macro, please add comments saying that
	you are invoking one.  E.g.
	<pre>
	DOS_RTN		; invoke macro in mymacros.lib
	</pre>
<li>	MORE EDITOR FEATURES.  The program
	PGM12_3.asm in chapter 12 of the text
	has the outlines of a very simple editor.
	It was demostrated in class, and you can even pick up
	a copy from our course homepage!  Your assignment
	is to modify this editor to add some more features.
	<ul>
	<li> INSERTION MODES.  The ``insertion mode''
	in PGM12_3 may be called
	the REPLACE MODE, that is, the charaters you
	type will replace the characters already on the
	screen.  We want you to implement another kind
	of insertion mode, called the APPEND MODE.
	In the APPEND MODE,
	the characters you type are INSERTED into
	the current position.  That means each character
	to the RIGHT of the current position in the current line 
	must move one position to the right.
	E.g., if the
	cursor is at the letter ``c'' in the following
	line,
		<pre>
		____abcd__12345______WXYZ_____
		</pre>
	then after you type ``HERE'', the new line will become
		<pre>
		____abHEREcd__12345______WXYZ_
		</pre>
	and the cursor would still be at the letter ``c''.
	NOTE: the underscores (<pre>___</pre>) signify blanks.
	<p>
	More precisely, consider what happens when you insert a
	single character (inserting many characters just repeats
	this procedure): of course, each character to the right
	of the current cursor position moves one position to the
	right.  The interesting question is what to do with the
	last character.  We have two possibilities:
	<br>
	(1) if the last character is a blank,
	then it simply disappears and the insertion process ends.
	<br>
	(2) if the last character is any non-blank character,
	it will be inserted into the beginning of
	the next row.  Of course, this may have a cascading effect
	and cause further insertions into the row after next, etc.
	If this causes an insertion into the row
	beyond the last row (row 24)
	then we create a new blank row by scrolling the screen
	up by one row (the contents of the previous row 0 is lost).
	<p>
	E.g., in the above example, suppose that there are
	two blank spaces after ``WXYZ'' before the end of line. 
	Then inserting ``HERE'' in the example will cause
	(in turn) the insertion of ``YZ''
	into the beginning of the next line.

	<li> TOGGLING BETWEEN THE TWO MODES.  At any moment,
	we are in the REPLACE or the APPEND MODE.  We want you
	to toggle between the two modes whenever the special
	key <b>INS</b> is typed (INS or ``INSERT KEY'') has scan code
	of 82 (or 52h), as seen in table 12.7 (p.245).

	<li> MARKING THE CURRENT POSITION.  We also want
	to be able to ``mark'' the current position whenever
	the user types the function key F1
	(=scan code 3Bh; see table H.1, p.528).
	We can have only one marked position at a time.
	So any previously marked position is forgotten
	after you type F1.  Initially, the position (0,0) is marked.

	<li> JUMPING TO THE MARKED POSITION.
	The user can jump to the marked position by typing
	the function key F2 (=scan code 3Ch).

	<li> NOT REQUIRED FOR THIS HW BUT WOULD BE NICE TO DO: 
	<br>
	(i) Implement the ability to DELETE a character
	(the opposite of the APPEND MODE).
	<br>
	(ii) Write the contents of the current screen into a
	file (called myfile.txt) whenever the user types F3.
	To do this, you need to do some simple file I/O.
	See chapter 19
	for some INT 21h functions for this purpose.
	<br>
	(iii) Files I/O is also useful if your editor wants to keep
	track of information that is larger than one screenful
	(so when you scroll up or scroll down, nothing is
	really lost).
<li> HOW TO MODIFY PGM12_3.asm.  We suggest that you
	retain the overall logic of the original program
	as much as possible.  Any new functionality
	should be implemented by defining new
	procedures and using function calls.
	We further suggest that you debug each new
	function thoroughly before putting them all together!
</ol>

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

<ul>
<li>
This assignment is worth 65 points.
PLEASE HAND IN ONLY ONE SOLUTION SET PER TEAM.
Part A is worth 20 points.
Part B is worth 45 points, broken down as follows.
	<ul>
	<li>
	If your program assembles and executes correctly,
	you automatically get 20 points.
	<b>If it does not assemble</b>, you get nothing
	out of these 20 points.  So make sure you get rid of all
	syntax errors!
	<li>
	Up to 5 points for using including MYMACROS.LIB and
	using macros the there whenever possible.
	<li>
	Up 5 points for placing useful and
	good comments (including specifying the input and output
	before of each procedure and macro).
	<li>
	Up to 5 points for elegant design of
	your program.  NOTE: usually, elegant programs are
	also small and compact.
	<li>
	Up to 6 points for proper packaging of your homework
	(details below).
	<li>
	We will give you 2 points if you 
	break up your program into two separate modules,
	<b>hw4.asm</b> (containing the main procedure)
	and <b>hw4a.asm</b> (containing the additional procedures).
	See section 14.2 for how to do this (you need
	to use the EXTRN and PUBLIC pseudo instructions).
	<b>HINT: You will find this skill useful
	in the final project.  So why not learn it now?</b>
	<li>
	2 discretionary points.
	</ul>
</ul>

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

<ol>
<li> A 3.5'' disk containing
	your program file (named <b>hw4.asm</b>),
	an executable (named <b>myeditor.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 HW4
	tasm /z /zi hw4
	tlink /v hw4
	td hw4
	echo DONE DEBUGGING HW4
	</pre>
	If you have two modules (hw4.asm and hw4a.asm)
	then these instructions must be modified appropriately.
	[2 pts]
<li> A printout of your files mymacros.lib
	and hw4.asm (and possibly hw4a.asm).
	[2 pts]
<li> Hand in everything in an envelop (prefer smaller envelops).
	Please write the following information on the envelop,
	and also on the diskette:
	<br>
	(a) your names, IDs and email addresses <b>for each team member</b>.
	<br>
	(b) ``HW3'',
	<br>
	(c) class information (``V22.0201.002'').
	<br>
	Please DO NOT use any of the official NYU envelops.
	[2 pts]
</ol>

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

<ol>
<li>
</ol>
-->

</body>
</html>

@


1.1
log
@Initial revision
@
text
@d226 1
a226 1
This assignment is worth 50 points.
d229 1
a229 1
Part B is worth 40 points, broken down as follows.
d241 1
a241 1
	Uo 5 points for placing useful and
@
