CSCI 2321 (Computer Design), Spring 2018:
Homework X

Credit:
Up to 50 extra-credit points.

Overview

You can do as many as you like, but you can only receive a total of 50 extra points.

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'', plus one of the following statements, whichever applies:

(As before, ``entirely my own work'' means that it's your own work except for anything you got from the assignment itself -- some programming assignments include ``starter code'', for example -- or from the course Web site.)

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:

  1. (Optional: Up to 5 extra-credit points.) One of the questions on Exam 2 asks you about additions to the table of ALU control signals in Figure B.5.13 of the textbook: Each line in the table represents a combination of control inputs (Ainvert, Bnegate, and a 2-bit Operation) to the design shown in Figures B.5.10 and B.5.12. The table doesn't include all 16 possibilities for these inputs, perhaps because some of them don't correspond to actual MIPS instructions. What operation would a line for values 1011 represent? (Hint: It may be helpful to review how values 0111 cause the circuit in B.5.12 to compute slt on the two inputs.)

  2. (Optional: Up to 10 extra-credit points each.) One of the homeworks asked you to describe what changes would be needed to the single-cycle implementation sketched in Figure 4.24 of the textbook to allow it to execute additional instructions. For each of the instructions below, describe what would be needed in order to support it. Specifically:

    The instructions:

    (You can do any or all these.)

  3. (Optional: No maximum, though as a rough guideline a page or so of prose will likely get you about 5 points.)

    In this course we focused on the MIPS architecture and its assembly language because it's simple and regular, and in theory once you have this background you should be well-prepared to learn about other architectures and their assembly languages. Choose some other architecture (x86 comes to mind, but there are others) and write a one-page-or-so executive-level summary of how it compares to the MIPS architecture (e.g., does it also have a notion of general-purpose registers, what if any special-purposes registers does it have, how do (some of) the instructions compare to those used in MIPS, etc.). Include a list of the sources you consulted (parts of the textbook, Web sites, etc.) You can even do this more than once for several different architectures.

  4. (Optional: No maximum, though as a rough guideline a page or so of prose will likely get you about 5 points.)

    For testing MIPS assembler programs we used a simple emulator (SPIM). Based on a very quick Google search it appears that there are other tools that provide similar or greater functionality (cross-compilers that generate MIPS assembler or object code from C code. full-fledged virtual machines that implement the MIPS architecture.) Find one or more that seem to you likely to be useful for this course and explain why you think it would be useful and what would be involved in installing it.

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 X'' or ``computer design hw X''). 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:

  1. (Optional: Up to 30 extra-credit points each.) Some of the homeworks and exams had you do things that (should?) seem very automatable. For any or all of the following tasks, write a program in a high-level language to perform it. You can use any high-level language I can easily test from the command line on one of our classroom/lab Linux systems. (For many of you Scala is likely to be your first choice, though C++ might appeal to some, or possibly Python.) Your program must include comments explaining what it does and its limitations (e.g., ``only works for the following list of instructions''), a brief explanation of how to use it, and an example of suitable input. (Some of these are pretty ambitious but all seem interesting?)



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
2018-05-03