From 121b632fb0813a1db6b56482ef515042a369fe35 Mon Sep 17 00:00:00 2001 From: mrbobbyguy <84521318+somerandomviolinkid@users.noreply.github.com> Date: Mon, 7 Sep 2026 12:45:49 -0500 Subject: [PATCH] correct bit mask for and/add + fix not to be bitwise instead of logical --- main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index dca8d02..325d8eb 100644 --- a/main.c +++ b/main.c @@ -199,7 +199,7 @@ void execute() { case NOP: break; case ADD: - switch ((cpu.ir >> 7) & 0x7) { + switch ((cpu.ir >> 7) & 0x3) { case 0: if (cpu.ir & 0b1) { printf("bad instruction: %X\n at memory address %X\n", cpu.ir, ram.memory[cpu.pc - 1]); @@ -226,7 +226,7 @@ void execute() { break; case AND: - switch ((cpu.ir >> 7) & 0x7) { + switch ((cpu.ir >> 7) & 0x3) { case 0: if (cpu.ir & 0x1) { printf("bad instruction: %X\n at memory address %X\n", cpu.ir, ram.memory[cpu.pc - 1]); @@ -258,10 +258,10 @@ void execute() { exit(-1); } - if (!(cpu.ir & 0x100)) { - cpu.alu.accumulator = !cpu.regFile[(cpu.ir >> 5) & 0x7]; + if (cpu.ir & 0x100) { + cpu.alu.accumulator = ~cpu.regFile[(cpu.ir >> 9) & 0x7]; } else { - cpu.alu.accumulator = !cpu.regFile[(cpu.ir >> 9) & 0x7]; + cpu.alu.accumulator = ~cpu.regFile[(cpu.ir >> 5) & 0x7]; } break;