diff --git a/emu/cpu/instruction.c b/emu/cpu/instruction.c index 12fa1b5..f8e0328 100644 --- a/emu/cpu/instruction.c +++ b/emu/cpu/instruction.c @@ -16,18 +16,20 @@ void LogInstructionData(CpuInstructions instruction, ArgumentInfo arg1Info, *hReadA1 = malloc(sizeof(char) * 32), *hReadA2 = malloc(sizeof(char) * 32); - sprintf(actArg1, "0x%X", arg2Val.u); + sprintf(actArg1, "0x%X", arg1Val.u); sprintf(actArg2, "0x%X", arg2Val.u); switch (arg1Info) { case value: + free(hReadA1); hReadA1 = "~"; break; case valueInRam: sprintf(hReadA1, "0x%X", arg1.u); break; case valueInRegister: + free(hReadA1); hReadA1 = CpuRegistersHumanReadable[arg1.u]; break; case pointerInRegister: @@ -38,12 +40,14 @@ void LogInstructionData(CpuInstructions instruction, ArgumentInfo arg1Info, switch (arg2Info) { case value: + free(hReadA2); hReadA2 = "~"; break; case valueInRam: sprintf(hReadA2, "0x%X", arg2.u); break; case valueInRegister: + free(hReadA2); hReadA2 = CpuRegistersHumanReadable[arg2.u]; break; case pointerInRegister: @@ -111,6 +115,11 @@ void ExecuteInstruction(CpuInstructions instruction, ArgumentInfo arg1Info, break; case DIV: GetAllArgVal(arg1Info, arg2Info, arg1, arg2, &actArg1, &actArg2); + if (actArg2.s == 0) + { + fprintf(stderr, "DIV by 0\n"); + exit(-1); + } SetRegister(ACU, (r16_int){ actArg1.s / actArg2.s }); LogInstructionData(instruction, arg1Info, arg2Info, arg1, arg2, actArg1, actArg2); break;