IUP Computer Science
COSC 300 Spring 2001

Project #6
(Due 30 April 2001)

Write four utility input/output macros that make the program in file I:\jlwolfe\cosc300\survey.asm and other similar programs work correctly. This program uses macros named NIN, NOUT, CIN, and COUT to input and output numbers and characters. You are to write these four macros and put them into a file named yourinitials-macs.inc Copy the SURVEY.ASM file to your own disk; change the include statement in SURVEY.ASM to refer to your file; assemble and execute SURVEY.

Each macro must be written so that it does reasonable checking of its argument(s) and generates only the instructions and/or data necessary to do the task with the actual arguments. (Or it may generate an error message, if something is found to be wrong.) You must NOT write the macros so that they always generate all possible instructions that might be used and generate decision instructions to decide between which set of instructions to use. Assembly-time decisions should be made about what to generate, rather than execution-time decisions about what to execute.

NIN symbolname

This macro reads an integer from the keyboard; it takes a single argument, symbolname, which is the name of a variable that can hold a signed integer value. The symbolname may be associated with a byte, a word, or a doubleword. If necessary, this macro is allowed to leave the contents of any of the A registers (AL, AH, AX, or EAX) changed when it finishes. Other registers should be unchanged when the macro finishes.

NOUT symbolname

This macro displays an integer on the screen (current cursor position); it takes a single argument, symbolname, which is the name of a variable that holds an unsigned integer value. The symbolname may be associated with a byte, a word, or a doubleword. This macro should not leave any register changed when it finishes.

CIN form, symbolname, numchars

This macro reads a character or string from keyboard input and puts it into memory at variable symbolname. Form is the letter C to indicate a single character is to be read; it is the letter S to indicate a string is to be read. Numchars is used only when reading a string - to specify the maximum length of the string; numchars is required to be an immediate value. A string should be stored at symbolname with a null character terminating it; a character should be stored as a single byte. If necessary, this macro is allowed to leave the contents of any of the A registers (AL, AH, AX or EAX) changed when it finishes. Other registers should be unchanged when the macro finishes.

COUT form, symbolname/literal

This macro displays on the screen a character or string from memory at symbolname or the given literal string. If the second argument is a symbolname, get a character or string from memory; if it is an immediate value string, display the argument itself. Form is the letter C to indicate symbolname holds a single character; it is the letter S to indicate that symbolname holds a null-terminated string; and it is the letter L to indicate that the second argument is a string literal that should be displayed as is. This macro should not leave any register changed when it finishes.

You may use procedures from Irvine's library freely in your macros. You may assume that anyone using your macros would declare the needed procedures as external, as is done in SURVEY.ASM

Hand in a printout of the file yourinitials-macs.inc You may make this printout using NotePad or a wordprocessor; but it must be readable, with no wrapped lines - print in landscape format if necessary. Construct this file so that its source is not displayed in SURVEY.LST, but so that the expanded (generated) text for each macro does appear in SURVEY.LST. Hand in a printout of SURVEY.LST Print it in landscape format so that there are no wrapped lines - you may need to reduce the font size to 10 or even 8 to make this happen. In addition to using your macros in SURVEY.LST, I will test them with another program that tries to use the macros in many incorrect ways; this is to see what error detection you are building into the macros.

Extra Credit Possibilities:
  • Make NOUT display signed integer values, including signed bytes, signed words, and signed doublewords.

  • Make both NIN and NOUT accept registers as arguments (in addition to variable names). Any register must be allowed. If you implement this option, the requirement for NIN and NOUT should change to "not leave any register changed, except for the argument register when a register is used as the argument." You should also make sure that CIN does not change any register, if you do this option.