Assignment 6, due Feb 24

Part of the homework for 22C:60 (CS:2630), Spring 2012
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: One approximation for π is 333/106. In a high level language, you could write a function to (approximately) multiply an integer by π as follows:
    unsigned int timespi( unsigned int i ) {
        return (i * 333)/106;
    }
    

    The Hawk monitor provides tools for multiplication and division. The definitive documentation for the monitor is in the monitor.h file which you can download or inspect at
    -- http://homepage.cs.uiowa.edu/~dwjones/arch/hawk/monitor_h.txt

    A Problem: Write a SMAL Hawk subroutine equivalent to the timespi routine given above. It should take its argument in R3 and return its result in R3, while conforming to the Hawk calling conventions. (1.0 points)

  2. Background: To convert from text to binary, each digit must be converted and then they must be combined. This is easy with the decimal digits in ASCII:
            char digit = ... (whatever)
            int value = digit - "0";
    

    This only works because the ASCII representations of the digits are in the right numerical order. The situation is harder when this is not true. Consider the system of hexadecimal digits that was used on the Illiac I computer:

    	0 1 2 3 4 5 6 7 8 9 K S N J F L
    

    a) Give SMAL Hawk code to define a constant array of integers indexed by the character code, with all of the array elements set to 16 except for the elements corresponding to Illiac I hexadecimal digits -- each of these should have its corresponding integer value, so, for example, A['7'] should hold seven. (1.0 points)

    Suggestion: The answer can be an aligned array initialized by W directives. If you write 16 values per line, the solution would be only 8 W directives.

    b) Write a subroutine, based on the array you defined in part a), that takes a character passed in R3 and returns the corresponding value from the array in R3, conforming to the Hawk calling conventions. (1.0 points)

Machine Problem 3

Due Mar. 5

In the future, when the ternary system replaces the binary system in computer architecture, people will use heptavintimal (base 27) instead of hexadecimal. When there are more than about 18 digits, some of the letters in the alphabet are dangerous. The upper-case i and the lower case L, for example, look like the numeral 1, and the upper-case o looks like the numeral 0. As a result, heptavintimal numbers use the following letters as digits:

       0 1 2 3 4 5 6 7 8 9 A B C D E F G H K M N P R T V X Z

On input, upper and lower case are equivalent, so users are free to type in "a0" instead of "A0" to mean 270. In addition, if users type in letters that can be easily misread, they are interpreted as the numeral they are most similar to. Both visual and phonetic similarities are counted for this, not only in English, but in other european languages. Here are the legal input equivalents of all of the heptavintimal digits:

       0 1 2 3 4 5 6 7 8 9 A B C D E F G H K M N P R T V X Z
       O I       S         a b c d e f g h k m n p r t v x z
       o i       s                                     U
       Q L                                             u
       q l                                             W
         Y                                             w
         y

Your assignment is to write a Hawk program that repeatedly prompts for a heptavigintimal number and then outputs the decimal equivalent. The screen should look like this while you are typing the number "a0" number:

        Heptavigintimal: a0

The screen should look like this after you hit the enter key:

        Heptavigintimal: a0
        Decimal:         270
        More? (y/n)

If you type y, it should do another conversion. If you type n, it should exit.

You are free to use any routines from the Hawk Monitor. PUTAT, PUTS and PUTDEC are useful ways to output things. To clear previous output from some part of the screen, just use PUTS with a string of blanks. To wait for a character without echoing it, use GETCHAR. You can echo characters yourself with PUTCHAR. You can get a string (into an array of characters) using GETS but you are not required to do so, or are you required to support backspace or other input correction keys.

Submission Instructions

Your source file must be named mp3.a all lower case. This file must exist on the departmental linux cluster. Use the division of math-sciences coursework submission tools to submit this file. For instructions, see:

-- http://www.divms.uiowa.edu/help/msstart/submit.html

Grading

The grader will assemble and run your code, and will comment, on your assembly listing, about any deficiencies in your work. You will be penalized for any of the following errors:

A suggestion: Work incrementally and note that problem 2 on the homework above is closely related to this assignment. First, get your program to prompt repeatedly for y or n and quit when n is typed. Then make it output a value. Then start working on making it translate heptavigintimal to binary. Steal code from the notes.