@Test public void addTargetTarget() { int memorySize = ConfigHelper.getConfig().getInt("memory_size"); Memory memory = new Memory(memorySize); memory.clear(); RegisterSet registerSet = new RegisterSet(); registerSet.put(1, new Register("T1")); registerSet.put(2, new Register("T2")); registerSet.clear(); Status status = new Status(); status.clear(); AddInstruction addInstruction = new AddInstruction(); memory.set(0, 10); memory.set(1, 10); addInstruction.execute(memory, 0, memory, 1, status); assertEquals(20, memory.get(0)); assertEquals(10, memory.get(1)); assertEquals(10, memory.get(1)); assertFalse(status.isSignFlag()); assertFalse(status.isZeroFlag()); assertFalse(status.isCarryFlag()); assertFalse(status.isOverflowFlag()); assertFalse(status.isBreakFlag()); memory.clear(); memory.set(memorySize - 1, 10); memory.set(1, 10); addInstruction.execute(memory, memorySize - 1, memory, 1, status); assertEquals(20, memory.get(memorySize - 1)); assertEquals(10, memory.get(1)); assertFalse(status.isSignFlag()); assertFalse(status.isZeroFlag()); assertFalse(status.isCarryFlag()); assertFalse(status.isOverflowFlag()); assertFalse(status.isBreakFlag()); memory.clear(); memory.set(0, 2); memory.set(1, 0xFFFF); addInstruction.execute(memory, memorySize, memory, 1, status); assertEquals(1, memory.get(0)); assertEquals(0xFFFF, memory.get(1)); assertFalse(status.isSignFlag()); assertFalse(status.isZeroFlag()); assertTrue(status.isCarryFlag()); assertFalse(status.isOverflowFlag()); assertFalse(status.isBreakFlag()); memory.clear(); memory.set(0, 1); memory.set(1, 0xFFFF); addInstruction.execute(memory, memorySize, memory, 1, status); assertEquals(0, memory.get(0)); assertEquals(0xFFFF, memory.get(1)); assertTrue(status.isCarryFlag()); assertTrue(status.isZeroFlag()); assertFalse(status.isSignFlag()); assertFalse(status.isOverflowFlag()); assertFalse(status.isBreakFlag()); memory.clear(); memory.set(0, 0x8000); memory.set(1, 0xFFFF); addInstruction.execute(memory, 0, memory, 1, status); assertEquals(0x7FFF, memory.get(0)); assertEquals(0xFFFF, memory.get(1)); assertTrue(status.isCarryFlag()); assertFalse(status.isZeroFlag()); assertFalse(status.isSignFlag()); assertTrue(status.isOverflowFlag()); assertFalse(status.isBreakFlag()); registerSet.set(1, 10); registerSet.set(2, 10); addInstruction.execute(registerSet, 1, registerSet, 2, status); assertEquals(20, registerSet.get(1)); assertEquals(10, registerSet.get(2)); assertFalse(status.isSignFlag()); assertFalse(status.isZeroFlag()); assertFalse(status.isCarryFlag()); assertFalse(status.isOverflowFlag()); assertFalse(status.isBreakFlag()); }
@Override public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { int a = (char) dst.get(dstIndex); int b = (char) src.get(srcIndex); return add(a, b, status, dst, dstIndex); }
AddInstruction extends Instruction { @Override public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { int a = (char) dst.get(dstIndex); int b = (char) src.get(srcIndex); return add(a, b, status, dst, dstIndex); } }
AddInstruction extends Instruction { @Override public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { int a = (char) dst.get(dstIndex); int b = (char) src.get(srcIndex); return add(a, b, status, dst, dstIndex); } AddInstruction(); }
AddInstruction extends Instruction { @Override public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { int a = (char) dst.get(dstIndex); int b = (char) src.get(srcIndex); return add(a, b, status, dst, dstIndex); } AddInstruction(); @Override Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status); @Override Status execute(Target dst, int dstIndex, int src, Status status); }
AddInstruction extends Instruction { @Override public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { int a = (char) dst.get(dstIndex); int b = (char) src.get(srcIndex); return add(a, b, status, dst, dstIndex); } AddInstruction(); @Override Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status); @Override Status execute(Target dst, int dstIndex, int src, Status status); static final int OPCODE; }