diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-22 02:35:05 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-22 02:35:05 -0400 |
commit | d3f8d2baa9e2cd8d35187d0e22155b5437947bf7 (patch) | |
tree | c39a9fb9e1776ae603cdd78185f347098ed10e9e | |
parent | ea521725a7739ec568eb6961edabf71d8169ef9e (diff) |
oemu: cpu: Introduce decoding for MUL instruction
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 84f04bf..ccac0b1 100644 --- a/usr.bin/oemu/cpu.c +++ b/usr.bin/oemu/cpu.c @@ -146,6 +146,29 @@ cpu_sub(struct oemu_cpu *cpu, inst_t *inst) } /* + * Decode the INST_MUL instruction + * + * @cpu: CPU that is executing + * @inst: Instruction dword + */ +static void +cpu_mul(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 'mul'\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 @@ -187,6 +210,9 @@ cpu_kick(struct oemu_cpu *cpu, struct sysmem *mem) case INST_SUB: cpu_sub(cpu, inst); break; + case INST_MUL: + cpu_mul(cpu, inst); + break; } /* Is this a halt instruction? */ |