From 784bc81a4a8e09341d6858ab8eeb8a1e4768d5ad Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 2 Feb 2022 18:57:33 -0400 Subject: [PATCH] fix(cpu): account for overflow in THUMB alu MUL --- src/cpu/thumb/format4.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cpu/thumb/format4.zig b/src/cpu/thumb/format4.zig index 80af863..ee8964a 100644 --- a/src/cpu/thumb/format4.zig +++ b/src/cpu/thumb/format4.zig @@ -90,7 +90,8 @@ pub fn format4(comptime op: u4) InstrFn { }, 0xD => { // MUL - const result = cpu.r[rs] * cpu.r[rd]; + const temp = @as(u64, cpu.r[rs]) * @as(u64, cpu.r[rd]); + const result = @truncate(u32, temp); cpu.r[rd] = result; cpu.cpsr.n.write(result >> 31 & 1 == 1);