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

How to use the symbol ?STACK in another file

In start.a51, there is defined a idata segment ?STACK.

?STACK  SEGMENT   IDATA


Now, in my asm file, I want to use the ?STACK to reset the SP,when using it directly as follows,

mov SP, #STACK-1


but there is an error: "error A45: UNDEFINED SYMBOL"

How can I do it, thanks.

Parents Reply Children
  • As the limit area of stack, I store the stack when access the ISR.
    So, I need to renew SP, and at the end of ISR I'll get back the SP.

  • For a very specific requirement, I once needed to do something similar.

    The stack segment was specified as this:

    ?STACK Segment Idata
    
             Rseg ?STACK
    
    Stack:   Ds   1             ;System stack area
    

    With the start of stack labelled like this, I could make it public/extern and access it in a separate module.

    So the code to initialise the stack was then this:

             MOV  SP,#Stack-1   ;Initialise 'real' stack
    

  • As the limit area of stack, I store the stack when access the ISR.

    That strongly indicates you're doing way too much inside that interrupt service routine. ISRs should never use so much data (or call other functions) that their stack usage becomes a burden.

  • A very good idea, thanks very much.
    But there is still some trouble, as follows.

    EXTRN IDATA (Stack)
    mov R0, #Stack;
    


    The link error information is:

    *** ERROR L127: UNRESOLVED EXTERNAL SYMBOL
    *** ERROR L128: REFERENCE MADE TO UNRESOLVED EXTERNAL
    


    How could you make "Stack" public/extern, pls tell it in detail. Thanks.

  • The ISR may need a bit of stack space to save some registers. Preferably, the ISR should not make a lot of function calls requiring extra stack - most often, it shouldn't do any function calls at all.

    Try to allocate static variables for the information needed by the ISR - and for any calls you just have to make from the ISR.

    I recommend that you solve your stack usage problem, instead of continuing to play with the stack. Besides - playing with the stack means that the ISR doesn't need to know the start address of the main app stadck. It must save the stack pointer, before switching to a separate stack. After being done, this is the value that you must restore - not the start address of the stack.

  • How could you make "Stack" public/extern, pls tell it in detail

    In the module that has the stack segment just include the line:

    Public  Stack
    

    And in the module that needs to reference the stack segment do (as you have correctly done):

    Extrn  Idata (Stack)
    

    Also, I notice your code snippet of:

    mov R0, #Stack;
    

    If you want to initialise the stack to the base of the block, you would normally use:

    mov R0, #Stack-1
    

    Because the stack pointer (on the 8051) increments before storing the data byte; sometimes referred to as a pre-increment style stack.

  • When adding "public Stack" in start.a51, all is ok.
    Thanks very much.