Machine Problem 3, due Oct 26

Part of the homework for 22C:60, Fall 2008
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Submit the source file mp3.a for your solution using the submit command, documented at:
-- http://www.divms.uiowa.edu/help/msstart/submit.html

The Problem

The Hawk monitor contains a routine, KBGETC, to read one character from the keyboard (returning it in R3) and a routine KBGETS that reads a line of text, terminated with ASCII CR or LF (the return or enter key produces one of these key codes).

The problem is, KBGETS has ho length limit on the line of text it is willing to read. This is dangerous.

The Assignment

Write a new routine, KBNGETS, that conforms to the following interface specification:

KBNGETS:                        ; get null terminated string from keyboard
				; expects R3 - pointer to string
				; expects R4 - size of string buffer
				; may wipe out R3-7
				; does not change R2

Your routine should call KBGETC to get each character. If the character is CR or LF, your routine should return. If the character is a control character (less than space or greater than or equal to DEL, it should be ignored. If the character does not fit in the user's buffer, it should be ignored.

In addition, the program must guarantee that the terminating NUL on the input string fits in the buffer. That means that for a buffer of length 1, the routine must ignore all input until the end of line, and then put a NUL in the buffer and return.

Note that this assignment does not ask you to duplicate the handling of backspace found in KBGETS. That code uses SMAL features that we have not yet discussed.

A Main Program to Test Your Code

Write an assembly language version of this code to test yours:

{
        char buffer[16]; /* a 15 character buffer, local to the main program*/
        int i;      
        do {
                dspat( 1, 1 );
                dspst("-                -"); /* 16 blanks between dashes */
                dspat( 2, 1 );
                kbngets( buffer, 16 );
                i = 1;
                while (buffer[i] != NUL) {
                        if (buffer[i] == ' ') buffer[i] = '-';
                        i = i + 1;
                }
                dspat( 1, 2 );
                dspst("-                 -"); /* 16 blanks between dashes */
                dspat( 2, 2 );
                dspst(buffer);
        } while (buffer[0] != q)
        exit();
}

Half credit will be given for cleanly formatted properly commented source code, regardless of whether it works correctly. Half credit will be given for the correct operation of your program, regardless of looks.

Note: You can test your main program using the dangerous veresion of KBGETS in the Hawk monitor. With that, if you type more than a safe number of characters, your program will go haywire, but you will be able to use backspace to correct input errors.