From 42421b7710c0897baa44e696144165fb9e9880d3 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 13 Nov 2017 20:08:07 -0500 Subject: [PATCH] Added RCR/RCL Instructions #7. --- .../assembly/instruction/RclInstruction.java | 70 +++++++++++++++++++ .../assembly/instruction/RcrInstruction.java | 69 ++++++++++++++++++ .../assembly/instruction/RolInstruction.java | 4 +- 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 Server/src/net/simon987/server/assembly/instruction/RclInstruction.java create mode 100644 Server/src/net/simon987/server/assembly/instruction/RcrInstruction.java diff --git a/Server/src/net/simon987/server/assembly/instruction/RclInstruction.java b/Server/src/net/simon987/server/assembly/instruction/RclInstruction.java new file mode 100644 index 0000000..753fe2d --- /dev/null +++ b/Server/src/net/simon987/server/assembly/instruction/RclInstruction.java @@ -0,0 +1,70 @@ +package net.simon987.server.assembly.instruction; + + +import net.simon987.server.assembly.Instruction; +import net.simon987.server.assembly.Status; +import net.simon987.server.assembly.Target; + +/** + * +---------------------+ + * | | + * CF < 0<0<0<0<0<0<0<0 <-+ + */ +public class RclInstruction extends Instruction { + + private static final int OPCODE = 39; + + public RclInstruction() { + super("rcl", OPCODE); + } + + @Override + public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { + + int count = src.get(srcIndex) % 17; + + int destination = dst.get(dstIndex); + int signBit = (destination & 0x8000); + + if (status.isCarryFlag()) { + destination |= 0x10000; + } + + destination = (destination << count) | (destination >>> (17 - count)); + + status.setCarryFlag((destination & 0x10000) == 0x10000); + + if (count == 1) { + status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed + } + dst.set(dstIndex, destination & 0xFFFF); + + + return status; + } + + @Override + public Status execute(Target dst, int dstIndex, int src, Status status) { + + int count = src % 17; + + int destination = dst.get(dstIndex); + int signBit = (destination & 0x8000); + + if (status.isCarryFlag()) { + destination |= 0x10000; + } + + destination = (destination << count) | (destination >>> (17 - count)); + + status.setCarryFlag((destination & 0x10000) == 0x10000); + + if (count == 1) { + status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed + } + dst.set(dstIndex, destination & 0xFFFF); + + + return status; + } +} diff --git a/Server/src/net/simon987/server/assembly/instruction/RcrInstruction.java b/Server/src/net/simon987/server/assembly/instruction/RcrInstruction.java new file mode 100644 index 0000000..2e98462 --- /dev/null +++ b/Server/src/net/simon987/server/assembly/instruction/RcrInstruction.java @@ -0,0 +1,69 @@ +package net.simon987.server.assembly.instruction; + +import net.simon987.server.assembly.Instruction; +import net.simon987.server.assembly.Status; +import net.simon987.server.assembly.Target; + +/** + * +---------------------+ + * | | + * CF < 0<0<0<0<0<0<0<0 <-+ + */ +public class RcrInstruction extends Instruction { + + private static final int OPCODE = 40; + + public RcrInstruction() { + super("rcr", OPCODE); + } + + @Override + public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { + + int count = src.get(srcIndex) % 17; + + int destination = dst.get(dstIndex) << 1; + int signBit = (destination & 0x10000); + + if (status.isCarryFlag()) { + destination |= 1; + } + + destination = (destination >>> count) | (destination << (17 - count)); + + status.setCarryFlag((destination & 1) == 1); + + if (count == 1) { + status.setOverflowFlag((destination & 0x10000) != signBit); //Set OF if sign bit changed + } + dst.set(dstIndex, destination >> 1); + + + return status; + } + + @Override + public Status execute(Target dst, int dstIndex, int src, Status status) { + + int count = src % 17; + + int destination = dst.get(dstIndex) << 1; + int signBit = (destination & 0x10000); + + if (status.isCarryFlag()) { + destination |= 1; + } + + destination = (destination >>> count) | (destination << (17 - count)); + + status.setCarryFlag((destination & 1) == 1); + + if (count == 1) { + status.setOverflowFlag((destination & 0x10000) != signBit); //Set OF if sign bit changed + } + dst.set(dstIndex, destination >> 1); + + + return status; + } +} diff --git a/Server/src/net/simon987/server/assembly/instruction/RolInstruction.java b/Server/src/net/simon987/server/assembly/instruction/RolInstruction.java index 3afbf27..b17a491 100644 --- a/Server/src/net/simon987/server/assembly/instruction/RolInstruction.java +++ b/Server/src/net/simon987/server/assembly/instruction/RolInstruction.java @@ -5,8 +5,8 @@ import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Target; /** - * +-----------------+ - * | | + * +-----------------+ + * | | * CF < 0<0<0<0<0<0<0<0 <-+ */ public class RolInstruction extends Instruction {