Beispiel #1
0
 /*
  * - ADD $m	Add the value in memory to the accumulator
  * - ADD #$val     Add the value to the accumulator
  */
 private static void ADD(CPU cpu, Boolean immediate, short operand)
 {
     short acc = cpu.getRegisterValue(2);
     if (immediate)
     {
         cpu.setRegisterValue(2, (short)(acc + operand));
     }
     else
     {
         short value = (short)cpu.getMemory().getMemoryLocation(operand);
         cpu.setRegisterValue(2, (short)(acc + value));
     }
 }
Beispiel #2
0
 /*
  * - LDA #$val Sets the accumulator with the value
  * - LDA $m	Sets the accumulator from a memory location
  */
 private static void LDA(CPU cpu, Boolean immediate, short operand)
 {
     if (immediate)
     {
         cpu.setRegisterValue(2, operand);
     }
     else
     {
         cpu.setRegisterValue(2, (short)cpu.getMemory().getMemoryLocation(operand));
     }
 }
Beispiel #3
0
 /*
  * - STA $m  Store the accumulator to a memory location
  */
 private static void STA(CPU cpu, short operand)
 {
     int acc = (int)(cpu.getRegisterValue(2)); //Get accumulator value
     cpu.getMemory().setMemoryLocation(operand, acc);
 }
Beispiel #4
0
 /*
  * - HLT           Quit the program (not needed if the last line of the program is the end)
  */
 private static void HLT(CPU cpu)
 {
     cpu.setPC((short)(cpu.getMemory().getInstructionCount()+1));
 }