### Question:
AndInstruction 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); int result = (a & b); status.setSignFlag(Util.checkSign16(result)); status.setZeroFlag((char) result == 0); status.setOverflowFlag(false); status.setCarryFlag(false); dst.set(dstIndex, result); return status; } AndInstruction(); @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; }### Answer:
@Test public void executeTargetTarget() { int memorySize = ConfigHelper.getConfig().getInt("memory_size"); Memory memory = new Memory(memorySize); memory.clear(); Status status = new Status(); status.clear(); AndInstruction andInstruction = new AndInstruction(); memory.clear(); memory.set(0, 0xF010); memory.set(1, 0xF111); andInstruction.execute(memory, 0, memory, 1, status); assertEquals(0xF010, memory.get(0)); assertEquals(true, status.isSignFlag()); assertEquals(false, status.isZeroFlag()); assertEquals(false, status.isOverflowFlag()); assertEquals(false, status.isCarryFlag()); memory.clear(); memory.set(0, 0x1010); memory.set(1, 0x0101); andInstruction.execute(memory, 0, memory, 1, status); assertEquals(0, memory.get(0)); assertEquals(false, status.isSignFlag()); assertEquals(true, status.isZeroFlag()); assertEquals(false, status.isOverflowFlag()); assertEquals(false, status.isCarryFlag()); }
@Test public void executeTargetImm() { int memorySize = ConfigHelper.getConfig().getInt("memory_size"); Memory memory = new Memory(memorySize); memory.clear(); Status status = new Status(); status.clear(); AndInstruction andInstruction = new AndInstruction(); memory.clear(); memory.set(0, 0x1010); andInstruction.execute(memory, 0, 0x0101, status); assertEquals(0, memory.get(0)); assertEquals(false, status.isSignFlag()); assertEquals(true, status.isZeroFlag()); assertEquals(false, status.isOverflowFlag()); assertEquals(false, status.isCarryFlag()); }