Ejemplo n.º 1
0
 public void new_cycle() {
   Message msg;
   for (int i = 0; i < msgs.size(); i++) {
     msg = msgs.get(i);
     if (msg.valid) { // valid msg, remove it
       msgs.remove(i);
       i--;
     } else { // invalid msg, make it valid and do store operation
       if (msg.addr != -1) { // a s.d instruction
         System.out.println("Storing " + msg.result + " into mem[" + msg.addr + "]");
         mem[msg.addr] = msg.result;
       } else { // not a s.d instruction
         for (int j = 0; j < 32; j++) {
           if (msg.addr == -1) { // not a s.d instruction
             if (freg.getFregFlag(j) == msg.station_id) { // write register
               System.out.println("F" + j + " is being written");
               freg.setFregFlag(j, Station.READY);
               freg.setFreg(j, msg.result);
               break;
             }
             if (reg.getRegFlag(j) == msg.station_id) { // write register
               System.out.println("R" + j + " is being written");
               reg.setRegFlag(j, Station.READY);
               reg.setReg(j, (int) msg.result);
               break;
             }
           }
         }
       }
       msg.valid = true;
     }
   }
 }