William "Chops" Westfield wrote: > On Jun 23, 2011, at 8:29 PM, Harold Hallikainen wrote: >=20 >> Is it possible to read the current stack pointer in C? If so, what >> would the instruction be? >=20 > Exactly or approximately? >=20 > void *returnsp() > { > int a; > return &a; > } >=20 > Should be pretty close (on almost any processor that uses stack frames > for local variables.) That's probably close, but at the caller's location almost certainly off by an int, possibly by an int and a return address and possibly some stack frame overhead (if the function didn't get inlined).=20 > Otherwise you get to look at inline assembler and/or assembler =20 > subroutines. And the compiler docs and generated code for how the compiler uses the stack.=20 Gerhard --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .