Fall 1997, Professor Yap
V22.0201.002, Machine Organization I

HOMEWORK 4
Due: Wed November 26, 1997


INTRODUCTION

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.

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!

PART A: ASSEMBLY PROGRAMMING KNOWLEDGE

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.
  1. Which of the following instructions are legal?
    	(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
    		
  2. How many bytes are used in the machine code for CMPSW?
  3. 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?
  4. What is wrong with the following macro definition? Further, please say what the assembler error message is.
    		newmac macro n
    		mov ax,n
    		newmac endm
    		

PART B: PROGRAMMING

  1. MACROS. Please collect the following macros from the book (chapter 13) into a file called mymacros.lib (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!).
    	DOS_RTN, NEW_LINE, DISP_STR, SAVE_REGS, RESTORE_REGS, HEX_OUT
    	
    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:
    	IF1
    		INCLUDE MYMACROS.LIB
    	ENDIF
    	
    Whenever you invoke a macro, please add comments saying that you are invoking one. E.g.
    	DOS_RTN		; invoke macro in mymacros.lib
    	
  2. 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.

GRADING

TO BE HANDED IN

  1. A 3.5'' disk containing your program file (named hw4.asm), an executable (named myeditor.exe), and a bat file called db.bat. The db.bat file contains the following lines
    	@rem debug batch file
    	echo DEBUGGING HW4
    	tasm /z /zi hw4
    	tlink /v hw4
    	td hw4
    	echo DONE DEBUGGING HW4
    	
    If you have two modules (hw4.asm and hw4a.asm) then these instructions must be modified appropriately. [2 pts]
  2. A printout of your files mymacros.lib and hw4.asm (and possibly hw4a.asm). [2 pts]
  3. Hand in everything in an envelop (prefer smaller envelops). Please write the following information on the envelop, and also on the diskette:
    (a) your names, IDs and email addresses for each team member.
    (b) ``HW3'',
    (c) class information (``V22.0201.002'').
    Please DO NOT use any of the official NYU envelops. [2 pts]