diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-21 09:01:27 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-21 09:01:27 -0400 |
commit | 60c8f4c34194fcec0e9e7d8da9cd1ad8b38707e7 (patch) | |
tree | 3f984457c20da8804479b2370a307a53efba80d9 | |
parent | 348697548884b8f1943fe4545df7f34adb79b0ae (diff) |
oemu: cpu: Decode ADD instructions
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | usr.bin/oemu/cpu.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/usr.bin/oemu/cpu.c b/usr.bin/oemu/cpu.c index 61568f2..9b8c622 100644 --- a/usr.bin/oemu/cpu.c +++ b/usr.bin/oemu/cpu.c @@ -100,6 +100,29 @@ cpu_dec(struct oemu_cpu *cpu, inst_t *inst) } /* + * Decode the INST_ADD instruction + * + * @cpu: CPU that is executing + * @inst: Instruction dword + */ +static void +cpu_add(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 'add'\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 @@ -135,6 +158,9 @@ cpu_kick(struct oemu_cpu *cpu, struct sysmem *mem) case INST_DEC: cpu_dec(cpu, inst); break; + case INST_ADD: + cpu_add(cpu, inst); + break; } if (regs->ip >= MEMORY_SIZE) { |