Re: [PIC] Learning C
"Forrest Christian (List Account)" <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.pic |
|---|---|
| Message-ID | <CAKsZx=1Wx1mnrSDNBcQeot4Wf1ip-SeuAE8rXGg10rd1XX7bfw@mail.gmail.com> |
With many embedded compilers, x may or may not be on the stack, as the compiler will, in some cases, use non-stack memory for local variables. This is especially true on smaller microcontrollers with limited stack space. One would need to read the compiler manual to determine if x will always be on the stack, whether there is a way to force x to be on the stack, or if there is a compiler specific way to get the stack pointer. On Sat, Nov 16, 2024, 4:09 AM smplx <[email protected]> wrote: > write a function: > > void * get_stack_ptr(void) > { > int x; > > return &x; > } > > This will return the address of the local variable x which will be on the > stack. > > use it as: > > if ((unsigned long)get_stack_ptr() == (unsigned long)fixed_value+N) > > // where N is a constant TBD (around +/- 4 to 12) > > > On Fri, 15 Nov 2024, David VanHorn wrote: > > > Same here. I can work with c fairly well, but some things seem unusually > > difficult in c. Like comparing the current value of the stack pointer > to a > > fixed value ( used in my sanity check routine) I assume there is a way > to > > get there. > > > > On Sun, Nov 10, 2024, 11:34 AM David C Brown <[email protected]> wrote: > > > >> Although I enjoy programming in Assembler, the fact that so many > libraries > >> abd code examples are in C I think that the time has come for me to > learn > >> that language. > >> > >> Any advice on how to do that would be welcomed, be it a book or online > >> resources. > >> I am a competent programmer having programmed in with Forth, Fortran. > >> \Pascal, Visual basic > >> __________________________________________ > >> David C Brown > >> 43 Bings Road > >> Whaley Bridge > >> High Peak Phone: 01663 733236 > >> Derbyshire eMail: [email protected] > >> SK23 7ND web: www.bings-knowle.co.uk/dcb > >> <http://www.jb.man.ac.uk/~dcb> > >> > >> > >> > >> *Sent from my etch-a-sketch* > >> -- > >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > >> View/change your membership options at > >> https://mailman.mit.edu/mailman/listinfo/piclist > >> > > -- > > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > > View/change your membership options at > > https://mailman.mit.edu/mailman/listinfo/piclist > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > https://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at https://mailman.mit.edu/mailman/listinfo/piclist