summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-22 01:39:53 -0400
committerIan Moffett <ian@osmora.org>2025-07-22 01:40:22 -0400
commitaf93dd2857940d2f0a19481f37ccdb25656ae15d (patch)
treeb18c253aa9f07b53a1293cd3988fee296cfe5209
parentdf9f396017f92ad4647697d461bb5475d6596cfb (diff)
oemu: cpu: Introduce decoding logic for SUB
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--usr.bin/oemu/cpu.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/usr.bin/oemu/cpu.c b/usr.bin/oemu/cpu.c
index 8ec106a..84f04bf 100644
--- a/usr.bin/oemu/cpu.c
+++ b/usr.bin/oemu/cpu.c
@@ -123,6 +123,29 @@ cpu_add(struct oemu_cpu *cpu, inst_t *inst)
}
/*
+ * Decode the INST_SUB instruction
+ *
+ * @cpu: CPU that is executing
+ * @inst: Instruction dword
+ */
+static void
+cpu_sub(struct oemu_cpu *cpu, inst_t *inst)
+{
+ struct cpu_regs *regs = &cpu->regs;
+ imm_t imm;
+
+ if (inst->rd > NELEM(regs->xreg)) {
+ printf("bad register operand for 'sub'\n");
+ return;
+ }
+
+ imm = regs->xreg[inst->rd];
+ regs->xreg[inst->rd] -= inst->imm;
+ printf("%d - %d -> X%d, new=%d\n",
+ imm, inst->imm, inst->rd, regs->xreg[inst->rd]);
+}
+
+/*
* Reset a CPU to a default state
*/
void
@@ -161,6 +184,9 @@ cpu_kick(struct oemu_cpu *cpu, struct sysmem *mem)
case INST_ADD:
cpu_add(cpu, inst);
break;
+ case INST_SUB:
+ cpu_sub(cpu, inst);
+ break;
}
/* Is this a halt instruction? */