Assignment 4, due Jun 21
Part of
the homework for CS:2630, Summer 2018
|
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!
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)
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)
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)