Hello all, In my application I need to access to the value that Stack is initialized, in general C51 does it in the startup code: MOV SP,#?STACK-1 What I need is to be able to use later on in my code the value "?STACK-1" and copy it to other variable. Thanks for your help in advance! Alfredo M.
SP is a register you can access by name.
#include "reg52.h" unsigned char sp; void main(void) { sp = SP; for (;;); }
Hi, thanks for your reply. Sorry, maybe I did not explain well my question... As you know the stack is changed after initialization from 0x07 to something else depending of the number of variables that we have in our project, I need to know this first value given for the stack and be able to used it later on in my project. For example is sp is initialized to 0x42 (in startup routine) after power up, I need to put this value (0x42) in some variables later on in my proyect. Do you know the way to do so? Thanks, Alfredo.
"the stack is changed after initialization ... to something else depending of the number of variables that we have in our project" Err, no! The stack has nothing to do with the number of variables in your project! If you don't understand this, you are probably far better off leaving the Stack Pointer alone! If you mess with the SP without a thorough understanding of precisely what it's doing, you are almost certain to really mess-up your application Big Time!! What exactly is it that you are trying to achieve here?
"For example is sp is initialized to 0x42 (in startup routine) after power up, I need to put this value (0x42) in some variables later on in my proyect." Yep, I'm with you so far (although I have no idea why one would want to do this). What I told you before still stands. main() is LJMP'ed to by my runtime startup (maybe yours doesnt'), so this works:
sp = SP;
sp = SP - 2;