Assignment 6, due Jun 28

Part of the homework for CS:2630, Summer 2018
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 (Tuesday or Thursday). 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: the Hawk LOAD and STORE instructions, in both long and short form, ignore the least significant 2 bits of the effective address and operate on aligned words in memory. Occasionally, there is a real need to access non-aligned data, for example, to load a non-aligned word. A non-aligned word is a sequence of 4 bytes starting at any address in memory.

    A problem: Write SMAL Hawk code for a subroutine called LOADS because it does the same thing as the instruction with that name, except that it works for non-aligned memory addresses. It takes an address in R3 and returns the value of the word at that memory location in R3.

    Your code should be neat and appropriately commented. Note that all the computation it does can be done in R3 to R7 without any calls to other subroutines, so it does not need an activation record to hold a return address or local variables. This can be done in 16 instructions, but you are more likely to take closer to 20 instructions. (1.0 points)

  2. Background: Another string routine that you could write is strcmp(s1,s2). This takes two memory addresses, s1 and s2 as parameters, where each points to a null-terminated character string. The return value is zero if the two strings are equal, positive if s1 comes alphabetically after s2 and negative if if s1 comes alphabetically before s2.

    In more detail, it returns zero if all characters of s1 and s2 are identical up to the trailing null. Otherwise, they must differ at some character i, which is to say s1[i]-s2[i] is not zero. In this case, it returns a positive value if s1[i]-s2[i] > 0, and a negative value if s1[i]-s2[i] < 0.

    a) Write code in a high level language notation for strcmp. You can safely act as if strings are simply arrays of characters. (0.5 points)

    b) Write SMAL Hawk code for STRCMP. As much as is possible, use the algorithm you documented above, and make sure your code incorporates comments that convey that algorithm and explain any optimization involved. (1.0 points)

  3. Background: The LOADSCC and LOADCC instructions load a value from memory and set the condition codes. For signed operands, it would be the same to just use LOADS or LOAD followed by CMPI 0 and then use one of BLT, BLE, BEQ, BNE, BGT or BGE to do the comparison.

    On the other hand, if the operands are unsigned and we set the condition codes with LOADSCC or LOADCC and then test them with one of BLTU, BLEU, BEQ, BNE, BGTU or BGEU the result will sometimes be wrong.

    a) Which of the above branches will produce wrong results? To answer this question, look up which condition codes these inspect and look at how the instruction sets those condition codes. (0.3 points)

    b) What useful purpose is solved by the way the LOADSCC or LOADCC instructions set the condition code or codes that cause the problems you discovered in part a? The answer to this is in Chapter 7 of the notes. (0.2 points)