Added Inc and Dec instructions based off Add code

This commit is contained in:
Hayden Kroepfl 2018-01-06 18:53:35 -07:00
parent f68027bb4d
commit eaef30eb49
3 changed files with 66 additions and 0 deletions

View File

@ -44,6 +44,8 @@ public class DefaultInstructionSet implements InstructionSet {
add(new RclInstruction());
add(new RcrInstruction());
add(new SarInstruction());
add(new IncInstruction());
add(new DecInstruction());
}
/**

View File

@ -0,0 +1,32 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
import net.simon987.server.assembly.Util;
public class DecInstruction extends Instruction {
public static final int OPCODE = 0x2B;
public DecInstruction() {
super("dec", OPCODE);
}
@Override
public Status execute(Target dst, int dstIndex, Status status) {
char a = (char) dst.get(dstIndex);
int result = a - 1;
// Like x86 Carry flag is preserved during INC/DEC
// (Use ADD x, 1 to have carry flag change)
// Other flags set according to result
status.setSignFlag(Util.checkSign16(result));
status.setZeroFlag((char) result == 0);
status.setOverflowFlag(Util.checkOverFlowSub16(a, 1));
dst.set(dstIndex, result);
return status;
}
}

View File

@ -0,0 +1,32 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
import net.simon987.server.assembly.Util;
public class IncInstruction extends Instruction {
public static final int OPCODE = 0x2A;
public IncInstruction() {
super("inc", OPCODE);
}
@Override
public Status execute(Target dst, int dstIndex, Status status) {
char a = (char) dst.get(dstIndex);
int result = a + 1;
// Like x86 Carry flag is preserved during INC/DEC
// (Use ADD x, 1 to have carry flag change)
// Other flags set according to result
status.setSignFlag(Util.checkSign16(result));
status.setZeroFlag((char) result == 0);
status.setOverflowFlag(Util.checkOverFlowAdd16(a, 1));
dst.set(dstIndex, result);
return status;
}
}