Machine Problem 3, due October 11

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

Given a rectangular area, print ax x in the middle. Then, do the same thing for the rectangular areas making up each quadrant of the area, until your area is just a single x. If the initial area starts out a perfect rectangle of just the right size, you'll get this:

        x   x   x   x   x   x   x   x     
          x       x       x       x
        x   x   x   x   x   x   x   x     
              x               x
        x   x   x   x   x   x   x   x
          x       x       x       x
        x   x   x   x   x   x   x   x
                      x
        x   x   x   x   x   x   x   x     
          x       x       x       x
        x   x   x   x   x   x   x   x     
              x               x
        x   x   x   x   x   x   x   x
          x       x       x       x
        x   x   x   x   x   x   x   x

For other initial area sizes, you'll get less symmetrical results, but elements of this pattern will show up.

In a high level language, the algorithm that produces this is as follows:

plot( int xlow, xhigh, ylow, yhigh ){
    int xmid = (xhigh + xlow)/2;
    int ymid = (yhigh + ylow)/2;
    dspat(xmid,ymiddle);
    dspch('x');
    if ((xlow < xmid) && (ylow < ymid)) {
        plot( xlow, xmid-1, ylow, ymid-1 );
        plot( xmid+1, xhigh, ylow, ymid-1 );
        plot( xlow, xmid-1, ymid+1, yhigh );
        plot( xmid+1, xhigh, ymid+1, yhigh );
    }
}

The main program should start by calling plot(0,width-1,0,height-1) using the width and height of the screen.

Your problem is to write this code in the SMAL Hawk assembly language and test it with a variety of window sizes. You'll find that it produces good looking output only for windows that are sized carefully. Just for fun, what are the good window sizes?

WARNING: Significant parts of the first midterm, which is the Friday before this assignment is due, will be based on this machine problem. Work you do on this before the exam should pay off, so long as you don't ignore other issues we've studied such as binary representations and machine code instruction formats.

Grading Critereia