I've attached the file test.c which contains the function "dostuff". When I compile it with the medium memory model, the line "y = (size - x);" in this function generates assembly code that appears to puts the result of that calculation on the stack (as I understand _bp to be the stack frame pointer). This doesn't seem to be the correct behavior, as the next line "if (y == 2)" then appears to get the value of y from #_dostuff_y_1_1 (which has not previously been modified). Here is the relevant section of the assembly generated by SDCC, which appears to be wrong:
; test.c:13: y = (size - x);
mov b,a ; put x in b
movx a,@r0 ; put size in a
mov @r0,a ; put result (y) at frame pointer?
; test.c:15: if (y == 2)
mov r0,#_dostuff_y_1_1 ; get y from PSEG
I would expect the y to be stored something like this instead:
I've tried to simplify the problematic code as much as I could - a lot of it looks superfluous, but I couldn't find anything else I could remove that didn't eliminate the problem.
My compile command was `sdcc -c test.c --model-medium`. I am running version 3.0.0 on Windows 7 x64 (the problem was also present in 2.9.0):
SDCC : mcs51/gbz80/z80/ds390/pic16/pic14/TININative/ds400/hc08 3.0.0 #6037 (Oct 31 2010) (MINGW32)