From 1972096df3d235d525bcf761ecb460ba952c0ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 12 Dec 2017 20:42:16 +0100 Subject: Fix immediate alu operation There should be a sign extension to 32bit when doing immediate operations. --- qtmips_machine/core.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'qtmips_machine') diff --git a/qtmips_machine/core.cpp b/qtmips_machine/core.cpp index 93b83dd..5f8321d 100644 --- a/qtmips_machine/core.cpp +++ b/qtmips_machine/core.cpp @@ -134,10 +134,14 @@ struct Core::dtExecute Core::execute(struct dtDecode dt) { if (dt.inst.opcode() == 0 && ((dt.inst.funct() == 10 && dt.val_rt != 0) || (dt.inst.funct() == 11 && dt.val_rt == 0))) regwrite = false; + std::uint32_t alu_sec = dt.val_rt; + if (dt.alusrc) + alu_sec = ((dt.inst.immediate() & 0x8000) << 16) | (dt.inst.immediate() & 0x7FFF); // Sign extend to 32bit + return { .regwrite = regwrite, .rwrite = dt.regd ? dt.inst.rd() : dt.inst.rt(), - .alu_val = alu_operate(dt.aluop, dt.val_rs, dt.alusrc ? dt.inst.immediate() : dt.val_rt, dt.inst.shamt(), regs), + .alu_val = alu_operate(dt.aluop, dt.val_rs, alu_sec, dt.inst.shamt(), regs), }; } -- cgit v1.2.3