I'm debugging a code for the Microchip PIC18F4520 using the PROTEUS ISIS. The code was compiled with the C18 compiler. There is a very crazy bug in the code that I don't know whether it is my fault or an ISIS/PIC problem. The imagem below shows the problem.
At the function 'free', before the statement at address 1004 is executed the variable 'i' has the value 0. When the instruction is executed, the variable 'i' magically receives the value 125.
The 'heap_status' is a global variable that has no binding with the variable 'i'.
Why assigning a value to 'heap_status' affects the variable 'i'?
PS.: When the function is executed for the first time, this doesn't happen. The problem arises when the function executes for the second time.