diff --git a/Server/src/net/simon987/server/assembly/DefaultInstructionSet.java b/Server/src/net/simon987/server/assembly/DefaultInstructionSet.java index c1cd47b..7fa0171 100755 --- a/Server/src/net/simon987/server/assembly/DefaultInstructionSet.java +++ b/Server/src/net/simon987/server/assembly/DefaultInstructionSet.java @@ -41,6 +41,9 @@ public class DefaultInstructionSet implements InstructionSet { add(new NotInstruction()); add(new RorInstruction()); add(new RolInstruction()); + add(new RclInstruction()); + add(new RcrInstruction()); + add(new SarInstruction()); } /** diff --git a/Server/src/net/simon987/server/assembly/instruction/SarInstruction.java b/Server/src/net/simon987/server/assembly/instruction/SarInstruction.java new file mode 100644 index 0000000..76ecf52 --- /dev/null +++ b/Server/src/net/simon987/server/assembly/instruction/SarInstruction.java @@ -0,0 +1,67 @@ +package net.simon987.server.assembly.instruction; + +import net.simon987.server.assembly.Instruction; +import net.simon987.server.assembly.Status; +import net.simon987.server.assembly.Target; + +/** + * + */ +public class SarInstruction extends Instruction { + + private static final int OPCODE = 41; + + public SarInstruction() { + super("sar", OPCODE); + } + + @Override + public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { + + int count = src.get(srcIndex) % 16; + + int destination = dst.get(dstIndex); + + if (count == 1) { + status.setOverflowFlag(false); //sign doesn't change + } + + if ((destination & 0x8000) == 0x8000) { + destination |= 0xFFFF0000; + } + + destination = destination >> (count - 1); + status.setCarryFlag((destination & 1) == 1); + destination = destination >> 1; + status.setZeroFlag(destination == 0); + + dst.set(dstIndex, destination); + + return status; + + } + + @Override + public Status execute(Target dst, int dstIndex, int src, Status status) { + int count = src % 16; + + int destination = dst.get(dstIndex); + + if (count == 1) { + status.setOverflowFlag(false); //sign doesn't change + } + + if ((destination & 0x8000) == 0x8000) { + destination |= 0xFFFF0000; + } + + destination = destination >> (count - 1); + status.setCarryFlag((destination & 1) == 1); + destination = destination >> 1; + status.setZeroFlag(destination == 0); + + dst.set(dstIndex, destination); + + return status; + } +}