Fix 32-bit OR immediate handling and memory corruption
authorRobert Pengelly <robertapengelly@hotmail.com>
Sat, 24 Oct 2026 02:15:26 +0000 (03:15 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sat, 24 Oct 2026 02:15:26 +0000 (03:15 +0100)
cpu.c

diff --git a/cpu.c b/cpu.c
index ffe5602e06be944495399f862770a45aa1010e4d..abb8f601a26da29f6c2cfa79b154276778be4800 100644 (file)
--- a/cpu.c
+++ b/cpu.c
@@ -2288,11 +2288,14 @@ fetch_instruction:
         
         }
         
-        case 0x0D: {                    /* OR AX, imm16 */
+        case 0x0D: {                    /* OR AX/EAX, imm16/imm32 */
         
-            uint16_t imm16 = fetch16 (cpu);                 /* Fetch the 16-bit immediate value */
+            if (cpu->has_operand_override) {
+                set_reg32 (cpu, REG_AX, or32 (cpu, get_reg32 (cpu, REG_AX), fetch32 (cpu)));
+            } else {
+                cpu->regs[REG_AX] = or16 (cpu, cpu->regs[REG_AX], fetch16 (cpu));
+            }
             
-            cpu->regs[REG_AX] = or16 (cpu, cpu->regs[REG_AX], imm16);           /* Perform OR and update flags */
             break;
         
         }