I've been trying to get SDCC working for a PIC 16F819. I can't seem to
get functions to work. I'm just working on a simple 1 parameter
function right now. It appears that the compiler allocates a global
register for the parameter then optimizes it away by mistake. I haven't
been able to trace through the code enough to figure this out. Looks
like it's either:
1. Compiler is assuming that since it's using the W reg to pass the
value that the whole function can use W. The initial move from W to the
allocated register is optimized out but none of the other references to
that reg are changed to access W.
2. The asm ops that use that reg are not properly incrementing it's use
count and so the optimizer is just removing it.
Adding an immediate return from Remove1pcode in pcoderegs.c will leave
in the move from w to the parameter register but the register is still
never allocated in the udata section. Perhaps due to #2 above.
I added a tidbit in src/pic/device.c to support the 16F819. Some
additional support needs to go into inc2h.pl script to deal with the
memmap stuff. That memmap pragma code took quite a long time to figure
out and doesn't appear to be well documented anywhere. It just fails to
have space to allocate any registers without it. ;)
Another oddity is using static functions. In that case it allocates
another register _func_param_1_1 but never uses it in preference to the
same non-static automatic register.
I've attached a small 16F819 device.c patch. (haven't done the inc2h.pl
patch yet) Also attached the .c and the pruned .asm that was generated
that shows lack of register allocation. Note that r0x68 is not in the
udata section but is used in the sed_leds function. The r0x69 register
is for i in main (asm cut out).
Any hints on where to fix this? The PIC code is rather scary and seems
full of non-PIC related code. Same error occurs when compiling for
other pic14 targets.
Other code generation looks pretty good so far. Good work. ;)