From 2ef6f492c474cb12b2cd535c6ca69be993dcbf95 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 30 Dec 2017 11:14:45 -0500 Subject: [PATCH] Fixes #64 --- .../assembly/instruction/NegInstruction.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/net/simon987/server/assembly/instruction/NegInstruction.java b/Server/src/main/java/net/simon987/server/assembly/instruction/NegInstruction.java index 14b6316..c9638b0 100644 --- a/Server/src/main/java/net/simon987/server/assembly/instruction/NegInstruction.java +++ b/Server/src/main/java/net/simon987/server/assembly/instruction/NegInstruction.java @@ -14,7 +14,23 @@ public class NegInstruction extends Instruction { @Override public Status execute(Target dst, int dstIndex, Status status) { - dst.set(dstIndex, -dst.get(dstIndex)); + //If the operand is zero, the carry flag is cleared; in all other cases, the carry flag is set. + + char destination = (char) dst.get(dstIndex); + + if (destination == 0) { + status.setCarryFlag(false); + status.setZeroFlag(true); + } else { + status.setCarryFlag(true); + } + + //Attempting to negate a word containing -32,768 causes no change to the operand and sets the Overflow Flag. + if (destination == 0x8000) { + status.setOverflowFlag(true); + } else { + dst.set(dstIndex, -destination); + } return status; }