Example #1
0
 /** write */
 public void write(SequentialInstruction currentInstruction) {
   switch (currentInstruction.getAddressingMode()) {
     case Globals.IMMEDIATE_ADDRESSING:
       outputTape.addElement(currentInstruction.getAddress());
       break;
     case Globals.INDIRECT_ADDRESSING:
       outputTape.addElement(
           memoryRegister.getRegister(
               memoryRegister.getRegister(currentInstruction.getAddress())));
       break;
     case Globals.REFERENCE_ADDRESSING:
       outputTape.addElement(memoryRegister.getRegister(currentInstruction.getAddress()));
       break;
     default:
       break;
   }
   currentInstructionIndex++;
 }
Example #2
0
 /** load */
 public void load(SequentialInstruction currentInstruction) {
   switch (currentInstruction.getAddressingMode()) {
     case Globals.IMMEDIATE_ADDRESSING:
       memoryRegister.setAccumulator(currentInstruction.getAddress());
       break;
     case Globals.INDIRECT_ADDRESSING:
       memoryRegister.setAccumulator(
           memoryRegister.getRegister(
               memoryRegister.getRegister(currentInstruction.getAddress())));
       break;
     case Globals.REFERENCE_ADDRESSING:
       memoryRegister.setAccumulator(memoryRegister.getRegister(currentInstruction.getAddress()));
       break;
     default:
       break;
   }
   currentInstructionIndex++;
 }
Example #3
0
 /** read */
 public void read(SequentialInstruction currentInstruction) {
   switch (currentInstruction.getAddressingMode()) {
     case Globals.IMMEDIATE_ADDRESSING:
       System.out.println(
           "Error. Line: "
               + (currentInstructionIndex + 1)
               + "Invalid addressing: "
               + currentInstruction.getName()
               + " ="
               + currentInstruction.getAddress());
       break;
     case Globals.INDIRECT_ADDRESSING:
       int aux =
           memoryRegister.getRegister(currentInstruction.getAddress())
               + 1
               - memoryRegister.getSize();
       if (checkMemoryRegisterOverflow(
           memoryRegister.getRegister(currentInstruction.getAddress()))) {
         for (int i = 0; i < aux; i++) memoryRegister.addRegister(0);
       }
       memoryRegister.setRegister(
           memoryRegister.getRegister(currentInstruction.getAddress()),
           inputTape.getCurrentPointerElement());
       inputTape.incrementPointer();
       break;
     case Globals.REFERENCE_ADDRESSING:
       int aux2 = currentInstruction.getAddress() + 1 - memoryRegister.getSize();
       if (checkMemoryRegisterOverflow(currentInstruction.getAddress())) {
         for (int i = 0; i < aux2; i++) memoryRegister.addRegister(0);
       }
       memoryRegister.setRegister(
           currentInstruction.getAddress(), inputTape.getCurrentPointerElement());
       inputTape.incrementPointer();
       break;
     default:
       break;
   }
   currentInstructionIndex++;
 }