#Stack Mysteries
01-Aug-90 19:03:55
Sb: #115299-#Stack Mysteries
Fm: Mike Spille/Manx 71545,1466
To: Michael Figg 73777,360
68000 and 8086 stack frames are pretty much the same – the registers used
obviously differ, but that's about it. When a function is called,
arguments are pushed in the reverse order (so that the first argument is
pointed to by the stack pointer). The function is then called, which means
the return address is now where the stack pointer points to. Within the
function, automatic variables are then allocated on the stack. This is
done with the link instruction on the 68K. At this point, the frame
register (a5 on the 68K) is setup so that a5+4 points to the 1st argument
to the function, and negative offsets from a5 point to local variables.
There's no portable way to figure out the contents of the stack frame
register in C – however, taking the address of the top-most local variable
can usually give you an indication. From within a debugger, simply look at
the A5 register.
-Mike