03-18-2010, 08:11 AM
Ok, I will try: in function calls, local variables and parameters are mostly managed using (ix+n) indirections. So, when doing var = var + 1, the compiler will emmit this code (if var is declared as Ubyte/Byte):
The compiler does successive optimizations. The first one is obvious. ADD A, 1 ==> INC A
The 2nd one is less obvious: This block can be replaced by
... but only if A register is not used later; this is the hard part for the compiler, because "later" is something we must define.
The problem is the latter condition was not being checked, so A register was not being preserved when it was required.
Code:
ld a, (ix + n)
add a, 1
ld (ix + n), a
Code:
ld a, (ix + n)
inc a
ld (ix + n), a
Code:
inc (ix + n)
The problem is the latter condition was not being checked, so A register was not being preserved when it was required.