mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
Added Inc and Dec instructions based off Add code
This commit is contained in:
parent
f68027bb4d
commit
eaef30eb49
@ -44,6 +44,8 @@ public class DefaultInstructionSet implements InstructionSet {
|
||||
add(new RclInstruction());
|
||||
add(new RcrInstruction());
|
||||
add(new SarInstruction());
|
||||
add(new IncInstruction());
|
||||
add(new DecInstruction());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user