This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Writing a Stack Underflow with the C51 compiler

I am attempting to do something that seemed simple, but it is turning into a mess. I want to write a stack underflow monitor in main that both checks the stack pointer to insure it is at the bottom, and checks a byte under the stack bottom for a pattern (to better insure that the stack never went under when it was outside of main).

I've come to find that you cannot compile the following statement:

unsigned char * data StackPtr _at_ 0x81;
(because it is an sfr address)

It seems like this should be the same thing as:
sfr SP = 0x81;
..but with the added benefit of being able to dereference StackPtr to get at what it is pointing at.

The plan was to enter main at power-up, get the address SP is pointing at, stuff a pattern in there like 0xAA, then increment the SP. Later, when it returns to main, the test verfies the SP is still pointing at the SP++ address, and the original SP pattern is still 0xAA.

Assembler seems my only way out.

Parents Reply Children
  • I know what you mean. The guys here in the office all said to write it in assembler. So this was a challenge more than anything.

    I also enjoy bending the compiler to my will. You learn a lot about how it works.

    ..now if I could only get lint to not have a cow. I need to tell it that the sfr is not a 3-byte pointer.
    *eye roll*