Assignment 5, due Jun 29

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

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated, and unless there is what insurance companies call "an act of God" - something outside your control; the only exceptions to this rule will be by advance arrangement.

Remember, summer session goes very quickly! Midterm Exam 1 is on the same date that this assignment is due.

 
 

  1. Background: Here are some fragments of code from a C or C++ program:
    	int a(5); /* a is a global array of 5 integers */
    
            int f( int p )
            /* the integer function f takes an integer parameter p */
    	{
    		int b(5); /* b is a local array of 5 integers */
    
    		/* code to initialize b has been omitted */
    
    		b[p] = a[p];
    
    		/* more code here has been omitted */
    

    a) Give appropriate SMAL assembly code to create a variable equivalent to a in the above code fragment. (1/2 point)

    b) Give appropriate SMAL Hawk assembly code for entry to the function f given above. This should include declarations for the activation record of f. (1/2 point)

    c) Give appropriate SMAL Hawk assembly code for the assignment statement in the above code fragment. (1/2 point)

     

  2. Background: The original C definiton of strcmp was as follows:
    strcmp( char * s, char * t )
    /* compare two strings, s and t for their alphabetical ordering
       returns <0 if s<t, 0 if s==t, >0 if s>t */
    {
            while (*s == *t) {
                    if (*s == NULL ) return 0;
                    s++;
                    t++;
            return (*s - *t);
    }
    

    Assignment: Write equivalent SMAL Hawk code. (1 point)

     

  3. Problem: Incorporate the program body from MP2 into the necessary boilerplate and submit a SMAL asseembly listing of the result. It will be judged worthless if it is not runnable and properly commented. (1/2 point)

Machine Problem 2, Due July 1

Here is a small SMAL Hawk program body (minus the boilerplate) that echoes the keyboard input to the screen until you press the q key on the keyboard.

LOOP:                           ; for (;;) {
        LOAD    R1,PKBGETC
        JSRS    R1,R1           ;   R3 = kbgetc()
        CMPI    R3,'q'
        BEQ     EX              ;   if (R3 == 'q') break
        LOAD    R1,PDSPCH
        JSRS    R1,R1           ;   dspch( R3 )
        BR      LOOP
EX:                             ; }

Expand on this program so that, at startup, it displays an asterisk in the center of the Hawk emulator's output display area. As in the above, the q key should terminate the program. In addition, your program should support the following "commands":

An attempt to move the asterisk off the edge of the screen should be detected and prevented (the asterisk won't move in that case). Note that the cursor movement keys for this assignment are the ones centered on the "j" key of the keyboard.

Hint: To move the asterisk, plot a space at the location where it was formerly, then plot the asterisk at its new location. You might consider making a subroutine that takes an X and Y coordinate pair plus a character (3 parameters) and then uses DSPAT and DSPCH to move to those coordinates and display the character.

Submitting your result: Usee the submit command on the department linux cluster to submit your solution. Your program must be in a file named mp2.a, submit it for the course c060 and in the directory mp2. See the assignment for MP1 for details.

Grading: Failure to include an appropriate TITLE directive will be penalized as in MP1. Up to half credit will be deducted for each of the following, depending on severity: Assembly errors, illegible or badly formatted code, poorly thought out logic of the solution, or failure of your program to perform as required. Poorly thought out commentary that belabors the obvious or fails to explain the obscure will cost at most one point. Errors in handling off-screen motion will cost up to 1/2 point, with "off by one" errors at each screen border costing 0.1 points each.