Re: A89: Re: C sources


[Prev][Next][Index][Thread]

Re: A89: Re: C sources




> >Strangely, CNibbles is only 5885 bytes on my calculator (as downloaded
> >from ticalc.org).  And, you can actually save a few dozen more bytes by
> >compiling with the -fomit-frame-pointer option.
>
> What does that do, out of curiosity.

A C program generally allocates variable memory on the stack. This is
accomplished with the LINK/UNLK mnemonics. LINK stores the value of a6 on the
stack, then loads a6 with the new stack pointer value, and finally decreases the
SP with the amount of memory needed. This can be repeated when the current C
function calls other functions, creating a chain of  _stack frames_.
UNLK does the reverse, i.e. loads the SP with a6 and restores a6 from the stack,
leaving things the way they where before LINK.

The advantage here is that while you still use the stack (the stack frame) for
variables you can still use the stack as you normally would, to push/pop
function arguments and store temporary data, since you still have a reference
point (a6). The disadvantage is that you occupy a register to do it.

Now, sometimes a function doesn't need a stack frame (i.e. it is zero bytes
big), maybe because all variables fit in registers. Unfurtunately the compiler
still outputs LINK/UNLK, but with a zero size (don't ask me why). This will be
removed with -fomit-frame-pointer, saving us a few bytes and freeing a register.
I'm not sure what it does when the stack frame is not zero bytes, but it should
make the compiler use the "conventional" assembly way of dealing with the stack
and registers for variable storeage, like we all do when programming directly in
asm (and where many many bugs are created - by us, not the compiler). This might
also make a program smaller, but it makes it harder to debug, and the
debugger-program has no chain of stack frames to follow to determine, among
other things, where a call came from and the current value of the local
variables.

Make any sense?

(Gah - don't start answering questions 5 minutes before you have to go to work -
I'm late!)

--
 / Niklas Brunlid
Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
Random PQF Quote follows:

It became apparent that one reason why the Ice Giants were known as the Ice
Giants was because they were, well, giants. The other was that they were
made of ice.
        -- (Terry Pratchett, Sourcery)






Follow-Ups: References: