CSCI 2321 (Computer Design), Spring 2017:
Homework X1

Credit:
Up to 30 extra-credit points. (But be advised that you can't get more than 50 extra-credit points on this assignment and Homework X2 combined.)

Overview

This set of extra-credit problems covers material from the first part of the course. You can do as many as you like, but you can only receive a total of 50 extra points on this assignment and Homework X2 combined.

NOTE that the usual rules for collaboration do not apply to this assignment. More in the following section.

Honor Code Statement

Please include with each part of the assignment the Honor Code pledge or just the word ``pledged'', and the statement ``This assignment is entirely my own work'' (where ``my own work'' means ``except for anything I got from the assignment itself, such as starter code, or from the course Web site or sample solutions to other assignments). For this assignment you should not work with or seek help from other students or from tutors, but you can consult other sources (other books, Web sites, etc.), as long as you identify them.

Problems

Answer the following questions. You may write out your answers by hand or using a word processor or other program, but please submit hard copy, either in class or in one of my mailboxes (outside my office or in the ASO).

  1. (Optional: Up to 10 extra-credit points.) For this problem your mission is to reproduce by hand a little of what an assembler and linker would do, as you did in the last problem of Homework 3. So you are to do two phases: The input files are these: and for the link step you should assume:

Programming Problems

Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) by sending mail to bmassing@cs.trinity.edu with each file as an attachment. Please use a subject line that mentions the course and the assignment (e.g., ``csci 2321 hw X1'' or ``computer design hw X1''). You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department's Linux machines, so you should probably make sure they work in that environment before turning them in.

  1. (Optional: Up to 10 extra-credit points.) For this problem, you are to write a MIPS procedure that, given a (null-terminated) string, tries to convert it to a signed integer and reports success/failure. More explicitly, this procedure should get the address of the string as the first argument (in $a0) and produce two results: So ``10'', ``-20'', and ``2147483647'' ($ 2^{31}-1$ ) are all valid, but ``10-'', ``abcd'', ``10ab'', and ``2147483648'' ($ 2^{31}$ ) are not. To get maximum points you need to detect both kinds of errors, but you can get up to 8 points if you do everything except the check for overflow. Other ``corner cases'' include the empty string and ``-'', both of which should produce an error result (-1), but here too if you don't make that work you won't lose many points.

    Starter program test-convert-int.s contains code to prompt the user for a text string, read it, call the convert procedure, and print the results. Your mission is to fill in the body of the convert procedure so it works as described.

    Sample executions:

    % spim  -f test-convert-int.s 
    Loaded: /usr/share/spim/exceptions.s
    Enter a line of text:
    10
    Input 10
    Result 10
    
    % spim  -f test-convert-int.s 
    Loaded: /usr/share/spim/exceptions.s
    Enter a line of text:
    -20
    Input -20
    Result -20
    
    % spim  -f test-convert-int.s 
    Loaded: /usr/share/spim/exceptions.s
    Enter a line of text:
    abcd
    Input abcd
    Error -1
    
    % spim  -f test-convert-int.s 
    Loaded: /usr/share/spim/exceptions.s
    Enter a line of text:
    1000000000000
    Input 1000000000000
    Error -2
    

    HINTS:

  2. (Optional: Up to 10 extra-credit points.) For this problem, you are to write a MIPS procedure that, given a memory address p and a number of bytes n, prints hexadecimal representations of n bytes starting at p. So for example if the p points to a ``ab'' and n is 2, the procedure should print ``61 62'' (hexadecimal representations of ASCII values for 'a' and 'b'), while if p points to an integer (in memory) with value 5 and n is 4, the procedure should print ``05 00 00 00'' (why is the 5 first? SPIM is little-endian, so bytes in integer types are stored in reverse order). More explicitly, this procedure should get p as the first argument (in $a0) and n as the second argument (in $a1) and print (to the ``console'', using SPIM system calls) as described. It doesn't need to return anything in $v0 and $v1.

    Starter program test-print-hexbytes.s contains code to prompt the user for a text string, read it, call the procedure to print the whole buffer, and then prompt for an integer, read it, and call the procedure to print the 4-byte result. Your mission is to fill in the body of the print procedure so it works as described. Sample execution:

    % spim -f test-print-hexbytes.s
    Loaded: /usr/share/spim/exceptions.s
    Enter a line of text:
    abcd
    Input abcd
    Result 61 62 63 64 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    Enter an integer:
    20
    Input 20
    Result 14 00 00 00 
    

    HINTS:



Footnotes

... footnote1
You could do it in C thus, assuming p starts out pointing to the beginning of the string (note that this doesn't do any error checking, but you can figure that out?
    /* put result of conversion in "work", ignoring errors */
    int work = 0;
    while (*p != '\0') {
        work = work*10 + (*p - '0');
        ++p;
    }
 


Berna Massingill
2017-04-25