CPU: Fix overflowed register written back in add instruction

This commit is contained in:
Connor McLaughlin 2019-09-14 13:33:29 +10:00
parent 459db392e7
commit 1afa02d475
1 changed files with 6 additions and 0 deletions

View File

@ -342,7 +342,10 @@ void Core::ExecuteInstruction(Instruction inst, u32 inst_pc)
const u32 add_value = ReadReg(inst.r.rt);
const u32 new_value = old_value + add_value;
if (AddOverflow(old_value, add_value, new_value))
{
RaiseException(inst_pc, Exception::Ov);
return;
}
WriteReg(inst.r.rd, new_value);
}
@ -525,7 +528,10 @@ void Core::ExecuteInstruction(Instruction inst, u32 inst_pc)
const u32 add_value = inst.i.imm_sext32();
const u32 new_value = old_value + add_value;
if (AddOverflow(old_value, add_value, new_value))
{
RaiseException(inst_pc, Exception::Ov);
return;
}
WriteReg(inst.i.rt, new_value);
}