CDA4101 Summer A, Assignment 5 Solutions

  1. (3 points) The instruction ISHR (arithmetic shift right) exists in JVM but not in IJVM. It uses the top two values on the stack, replacing the top with a single value, the result. The second from top word of the stack is the operand to be shifted. Its content is shifted right by a value between 0 and 31 inclusive, depending on the value in the 5 least significant bits of the top word on the stack (the other 27 bits of the top word are ignored). The sign bit is replicated to the right for as many bits as the shift count. Extend the microcode to include this instruction as part of IJVM.
    1. For the exrta credit
      ishr1  MAR = SP - 1; rd
      ishr2  OPC = 1
      ishr3  OPC = OPC << 8
      ishr4  OPC = OPC >> 1
      ishr5  OPC = OPC >> 1
      ishr6  OPC = OPC >> 1
      ishr7  OPC = OPC - 1
      ishr8  H = TOS
      ishr9  TOS = MDR
      ishr10 OPC = H AND OPC; if (Z) goto (Main1)
      ishr11 TOS = TOS >> 1
      ishr12 OPC = OPC - 1; if (Z) goto (Main1); else goto (ishr11)
    2. Without extra credit. There is no actual way to load the constant in this architecture, without knowing the offset of the constant in the constant pool. This begs the question: how do you load the offset to find  where the constant is located in the constant pool? So, assume that somehow the value of the constant ThirtyOne has been loaded into OPC. In other architectures, constants that are need by the microcode are hardwired into a special register.
      ishr1  MAR = SP - 1; rd
      ishr2  H = TOS
      ishr3  TOS = MDR
      ishr4  OPC = H AND OPC; if (Z) goto (Main1)
      ishr5  TOS = TOS >> 1
      ishr6  OPC = OPC - 1; if (Z) goto (Main1); else goto (ishr5)
  2. (2 points) The JVM INVOKEVIRTUAL instruction needs to know how many parameters it has. Why?
    In order to find the locatation of OBJREF.
  3. (2 points) Explain in detail why INVOKEVIRTUAL is only 11 instructions in Mic-2, but 22 instructions in Mic-1. Indicate why some instructions could be combined, and why some instructions could be eliminated altogether.
  4. (3 points) Draw a finite state machine for branch prediction that uses three bits. It should only change predictions after three consecutive mispredictions.
  5. (3 points) Mic-3. Figure 4-33 on page 258 shows how the SWAP instruction from Mic-2 would be sequenced in Mic-3. Create a similar table for ISTORE.
    istore1 istore2 istore3 istore4 istore5
    A = MBR1U, B = LV
    C = A + B B = TOS
    MAR = C C = B B = SP
    MDR = C; wr C = B - 1
    mem = MDR SP = MAR = C; rd
    MDR = mem
    B = MDR
    C = B
    TOS = C; goto(Main1)
  6. (3 points) In Fig. 4-43, suppose that I6 was R5 = R0 - R2. Indicate which instructions could be issued and which could be retired in each cycle from cycle 6 forward. There will be fewer cycles to complete all the instructions.
    Cy # Decoded Iss Ret
    6
    6
    7
    R5=R0-R2
    R3=R3*R1
    6
    7
    7   4
    8
    5
    6
    9 7
    10 8 R1=R4+R4 8
    11
    12 8
  7. (4 points) Consider the direct-mapped cache on page 267.