if (VM.VerifyAssertions) VM.assert(NUM_NONVOLATILE_FPRS == 0);
if (VM.VerifyAssertions) VM._assert(NUM_NONVOLATILE_FPRS == 0);
  private static INSTRUCTION[] generateThreadSwitchInstructions() {    if (VM.VerifyAssertions) VM.assert(NUM_NONVOLATILE_FPRS == 0); // assuming no NV FPRs (otherwise would have to save them here)    VM_Assembler asm = new VM_Assembler(0);    int   ipOffset = VM_Entrypoints.registersIPField.getOffset();    int   fpOffset = VM_Entrypoints.registersFPField.getOffset();    int gprsOffset = VM_Entrypoints.registersGPRsField.getOffset();    int regsOffset = VM_Entrypoints.threadContextRegistersField.getOffset();    // (1) Save hardware state of thread we are switching off of.    asm.emitMOV_Reg_RegDisp  (S0, T0, regsOffset);      // S0 = T0.contextRegisters    asm.emitPOP_RegDisp      (S0, ipOffset);            // T0.contextRegisters.ip = returnAddress    asm.emitPUSH_RegDisp     (PR, VM_Entrypoints.framePointerField.getOffset()); // push PR.framePointer    asm.emitPOP_RegDisp      (S0, fpOffset);            // T0.contextRegisters.fp = pushed framepointer    asm.emitADD_Reg_Imm      (SP, 8);                   // discard 2 words of parameters (T0, T1)    asm.emitMOV_Reg_RegDisp  (S0, S0, gprsOffset);      // S0 = T0.contextRegisters.gprs;    asm.emitMOV_RegDisp_Reg  (S0, SP<<LG_WORDSIZE, SP); // T0.contextRegisters.gprs[#SP] := SP    for (int i=0; i<NUM_NONVOLATILE_GPRS; i++) {      asm.emitMOV_RegDisp_Reg(S0, NONVOLATILE_GPRS[i]<<LG_WORDSIZE, NONVOLATILE_GPRS[i]); // T0.contextRegisters.gprs[i] := i'th register    }    // (2) Set currentThread.beingDispatched to false    asm.emitMOV_RegDisp_Imm(T0, VM_Entrypoints.beingDispatchedField.getOffset(), 0); // previous thread's stack is nolonger in use, so it can now be dispatched on any virtual processor         // (3) Restore hardware state of thread we are switching to.    asm.emitMOV_Reg_RegDisp(S0, T1, fpOffset);        // S0 := restoreRegs.fp    VM_ProcessorLocalState.emitMoveRegToField(asm, VM_Entrypoints.framePointerField.getOffset(), S0); // PR.framePointer = restoreRegs.fp    asm.emitMOV_Reg_RegDisp(S0, T1, gprsOffset);      // S0 := restoreRegs.gprs[]    asm.emitMOV_Reg_RegDisp(SP, S0, SP<<LG_WORDSIZE); // SP := restoreRegs.gprs[#SP]    for (int i=0; i<NUM_NONVOLATILE_GPRS; i++) {      asm.emitMOV_Reg_RegDisp(NONVOLATILE_GPRS[i], S0, NONVOLATILE_GPRS[i]<<LG_WORDSIZE); // i'th register := restoreRegs.gprs[i]    }    asm.emitJMP_RegDisp    (T1, ipOffset);            // return to (save) return address    return asm.getMachineCodes();  }