Assignment 4, due Jun 21

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: Look at the Hawk program skeleton distributed with Machine Problem 1.

    a) The program uses R8 to store the variable n. The choice of R8 was somewhat arbitrary — that is, the program would have worked just as well if any of several other registers had been used, but there are others that cannot be used to hold n. Which registers cannot be used? (Hint: Read Chapter 5, or experiment and see what happens) (0.5 points)

    b) The program skeleton contains a loop. That loop ends with a CMPI instruction followed by a BLE instruction. What change to the CMPI instruction would you need to make if you changed the BLE to BLT? (0.5 points)

  2. Background: About 3/5 of the way through Chapter 5, three different solutions are given to the problem of loading a register with the address of the string HELLO in the hello world program.

    a) Which of these use PC-relative addressing? (0.5 points)

    b) Why is the ALIGN directive needed in the rightmost alternative? (0.5 points)

    c) In the discussion of PC-relative addressing, the expression X-(.+4) shows up as the displacement for the LEA instruction. Where did the +4 come from. That is, why isn't the displacement just X-.? (0.5 points)

  3. Background: The Hawk offers two ways to do an unconditional control transfer, the BR instruction, that can go to any instruction within a 256 half-word window centered on the instruction itself, and JUMP, that can go to any instruction within a 64K byte range (32K half words).

    In contrast, the only instructions on the Hawk that test the condition codes are branch instructions. There are no conditional variants of the JUMP instruction. This is justified by the fact that most conditional control structures in real programs are small loops.

    Suppose your program had BGT THERE in it, and it used to work until you added a few more lines of code, and the next time you assembled the program you got an "out of bounds" error message because THERE was too far from the conditional branch instruction.

    A question: What code could you use to replace BGT THERE that would accomplish the same behavior. Hint: It is more than 1 instruction and one of these instructions is a JUMP instruction. (0.5 points)