/* * - 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)); } }
/* * - 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)); } }
/* * - 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); }
/* * - 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)); }