Homework 9

22C:18, Spring 1996

Due Tuesday Apr. 16, 1996 in discussion

Douglas W. Jones
NOTICE: There will be a meeting to reorganize and restart the local ACM chapter, our computer science student organization, on April 16 at 7:00 PM in the Muhley Lounge in Room 5 of MacLean Hall.

Consider the following bit of pseudocode to compile statements of the form "WHILE cond DO statement-list ENDLOOP"

    procedure complewhile
       local variables top, botref, pointers to memory locations
       local variable cc, index into bcc, an array of branch opcodes
    begin
       skipkeyword( "WHILE" )
       top := lc          -- remember address of loop top

       cc := compilecond

       mem[ lc ] := bcc[ cc ] -- conditional branch to loop bottom
       mem[ lc + 1 ] := 0 -- use 16 bit PC relative branch address
       lc := lc + 2
       botref := lc       -- remember where address goes
       lc := lc + 2

       compilestatementlist

    || mem[ lc ] := bra   -- branch back to loop top
    || mem[ lc + 1 ] := 0 -- 16 bit relative mode
    || lc := lc + 2
    || mem[ lc, lc + 1 ] := f( lc, top )
    || lc := lc + 2
       mem[ botref, botref + 1 ] := f( botref, lc )
    end
  1. Consider the function f(a,b) in the above code, where a is the address where a program counter relative 16 bit PC-relative branch displacement should be stored, and b is the destination of the branch instruction. Give a definition of f(a,b) for the M68000.

  2. In the above code, it is quite difficult to make forward branches use 8-bit branch displacements, but the backward branch at the end of the loop (marked with ||) can be easily modified to use the short when the distance from branch to destination is short enough. Write pseudocode to replace the marked code that uses short form addresses when possible. This should use a function g(a,b) analogous to the function f used above, but returning an 8 bit short displacement.

  3. Define the function g(a,b) analogous to the function f used above, but returning an 8 bit short displacement.

  4. The MOVE USP instruction (page A160) is a privileged instruction on the M68000. This means it cannot be executed by user programs! Suppose a user wanted to use this instruction, but was confined to using some combination of ADDA, LEA and normal arithmetic operations on address registers. How could a user fake a MOVE USP instruction with a sequence of these non-privileged instructions?

  5. The MOVE SR instruction (pages A158 and A159) and the MOVE CCR instruction (pages A94 and A95) are very similar. What are the differences?