diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-13 10:03:53 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-13 10:03:53 -0400 |
commit | 9685552a509ea460c214888443cb1c93adc58e31 (patch) | |
tree | 465915d40f16bd24c9614a706d915f2f90613c2d | |
parent | 99af78ce0657c71071ec85375ede2f60d5b15baa (diff) |
emux64: cpu: Add emulation of DIV instructionmain
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | emux64/src/cpu/cpu_cycle.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/emux64/src/cpu/cpu_cycle.c b/emux64/src/cpu/cpu_cycle.c index 9f30788..dda1794 100644 --- a/emux64/src/cpu/cpu_cycle.c +++ b/emux64/src/cpu/cpu_cycle.c @@ -237,6 +237,26 @@ cpu_do_mul(struct osmx_core *core) return 0; } +static int +cpu_do_div(struct osmx_core *core) +{ + struct arithop ops; + int error; + + error = cpu_arithop(core, &ops); + if (error < 0) { + return error; + } + + if (ops.op2 == 0) { + printf("** DIVIDE ERROR **\n"); + return -1; + } + + core->xn[ops.dest_reg] = ops.op1 / ops.op2; + return 0; +} + int cpu_run(struct osmx_core *core) { @@ -282,6 +302,12 @@ cpu_run(struct osmx_core *core) continue; } break; + case OP_DIV: + if (cpu_do_div(core) < 0) { + core->run = false; + continue; + } + break; case OP_NOP: break; default: |