From: Daniel W. <dan...@ro...> - 2001-07-18 07:05:45
|
> I've been investigating the elusive problem of doing recursion on > these chips. I decided I'd look to see how other compilers did it. > It turns out that NO compilers implement recursion on the PIC chips. > It really isn't that practical in any case. It could probably be > done via some trickery, but the results would be rather useless. > Recursion isn't really a demanded feature for such a small system in > any case. My current thoughts are to issue a warning if a recursive > call is used, and otherwise basically not support recursion for the > PIC. Does this seem like a decent way to go? I have looked into this in the past. You definitely can't do it easily= ,=20 because the PICs are designed to use the hardware stack. To impliment a=20 software stack (which is what is needed for recursion), it is nice to be = able=20 to read the program counter. If you allow your code to be non-relocatabl= e,=20 the compiler will know the absolute address of all the commands, and thus= the=20 program counter for each command. It would then theoretically be possibl= e to=20 save the high bits of the program counter somewhere. This would be quite= =20 tedious, it seems to me. The AVR line, on the other hand, seems to allow reading of the PC in an= =20 indirect way: if you call a function, the address is pushed (in two bytes= )=20 onto the stack. You can then pop the stack into register space and play = with=20 it. This makes a true software stack for both code and data possible. Have you had a chance to look at the AVR datasheets yet? I'm looking a= t=20 the instruction set doc, and the 90S1200 and 90S8535 (doc is the same as=20 90S4433). =20 I'm unsure how hard it would be to make the compiler work for both=20 situations... maybe not that hard. |