poke function ....
Art Berggreen
art@acc.com
Tue Sep 22 08:42:00 GMT 1998
>What will happen in stack whenever the function pokeb
>is being called?? Is the same like Intel where the frame pointer
>being pushed to the stack?? If it is, that means during
>that time my stack will be like this :
>
> MSB LSB
> +0 +1 +2 +3
> +-------+-------+-------+-------+
> SP+16 | data (extended to 32 bits) |
> +-------+-------+-------+-------+
> SP+12 | offset |
> +-------+-------+-------+-------+
> SP+8 | base_addr |
> +-------+-------+-------+-------+
> SP+4 | return PC addr |
> +-------+-------+-------+-------+
> SP-> | old A6 value |
> +-------+-------+-------+-------+
The m68k C compilers tend to use A6 for a stack frame pointer (FP).
Normally the calling function sets up the stack as pictured above.
If the called function wishes to establish a stack frame it uses
the link instruction specifying A6 and the number of bytes for local
variables being allocated on the stack. The unlink instruction is
used just before the function exits to restore the stack. If a stack
frame is set up by the called function, things will look like:
MSB LSB
+0 +1 +2 +3
+-------+-------+-------+-------+
FP+16 | data (extended to 32 bits) |
+-------+-------+-------+-------+
FP+12 | offset |
+-------+-------+-------+-------+
FP+8 | base_addr |
+-------+-------+-------+-------+
FP+4 | return PC addr |
+-------+-------+-------+-------+
FP-> | old FP value |
+-------+-------+-------+-------+
FP-4 | |
+ stack based +
| local variables |
+ +
SP-> | |
+-------+-------+-------+-------+
Passed arguments are then referenced using positive offsets from FP
and local variable referenced using negative offsets from FP. The
compiler can allow the stack to grow down with arguments for called
functions and clean them allow up in a single instruction when needed.
Because of this it is much easier to reference arguments and variables
using the FP. FPs are useful when debugging to "unwind" the stack.
Much of this compiler behavior can be changed with runtime switches
(or even when the compiler is built).
Art
More information about the crossgcc
mailing list