Menu

_bp in SDCC - Need Equivalent For IAR (8051)

John W.
2007-09-30
2013-03-12
  • John W.

    John W. - 2007-09-30

    Hello,

    I've looked in the SDCC source code somewhat - and _bp is defined as a __data char basically - the project I'm working on assigns it as data address 0x12.

    The following macro in SDCC inline assembly has a push _bp statement:

    #define portSAVE_CONTEXT()                                                                        \ {                                                                                                \     _asm                                                                                        \         /* Push ACC first, as when restoring the context it must be restored                    \         last (it is used to set the IE register). */                                            \         push    ACC                                                                                \         /* Store the IE register then disable interrupts. */                                    \         push    IE                                                                                \         clr        _EA                                                                                \         push    DPL                                                                                \         push    DPH                                                                                \         push    b                                                                                \         push    ar2                                                                                \         push    ar3                                                                                \         push    ar4                                                                                \         push    ar5                                                                                \         push    ar6                                                                                \         push    ar7                                                                                \         push    ar0                                                                                \         push    ar1                                                                                \         push    PSW                                                                                \     _endasm;                                                                                    \         PSW = 0;                                                                                \     _asm                                                                                        \         push    _bp                                                                                \     _endasm;                                                                                    \ }

    I need to be able to do the equivalent in IAR which doesn't support (directly anyway) the stack frame pointer assembly instruction - _bp.

    I've found the _bp.c source code file in the SDCC source - but it is just declared as a __data char as mentioned above.
    Any help on how the assembler handles push _bp and pop _bp much appreciated as I need to try and clone it in IAR, if possible.

    Thanks In Advance,
    John W.

     
    • Maarten Brock

      Maarten Brock - 2007-10-01

      Why do you think IAR uses a stack frame pointer? And if they do, what is the name it goes by?
      Remember the 8051 does not have a hardware stack frame pointer, so SDCC created _bp for that purpose in software.

      Maarten

       
    • John W.

      John W. - 2007-10-01

      Hello,

      IAR does not use a stack frame pointer per se as does SDCC - hence the post.

      I want to know how the stack frame pointer in SDCC operates so I can hopefully 'clone' the operation in IAR.

      Does the stack frame pointer point to the word immediately after the last argument passed on the stack?

      If I can understand how this is used in SDCC - then I can possibly clone the operation in IAR.

      I looked in the SDCC docs but didn't find a clear definition of a stack frame.

      Thanks In Advance,
      John W.

       
    • Maarten Brock

      Maarten Brock - 2007-10-02

      Have a look in mcs51/gen.c genFunction().

      On function entry all sorts of registers might be saved and then the old _bp is pushed onto the stack (fReentrant) and the SP is copied to _bp. If there are local variables on the stack they are allocated by incrementing the SP. So _bp points to the first local variable on stack. The parameters are at (much) lower addresses.

      But I still do not understand why you would want to clone this behaviour. This is very dependent on the compiler implementation.

      Maarten

       
    • John W.

      John W. - 2007-10-04

      Maarten,

      Thanks for this response - I looked at the gen.c file and the genFunction().

      I just want to know how the stack frame pointer is defined and what defines the stack frame so I can try to build the equivalent functionality with the IAR tools.

      Best Regards,
      John W.

       
    • Maarten Brock

      Maarten Brock - 2007-10-05

      John,

      I don't know what else to tell you. Besides, as I already told you, stuff like this is very compiler dependent. You can't just mix SDCC behaviour with the IAR compiler. Why would you want to build the equivalent functionality? Doesn't the IAR compiler handle all this for you? Maybe even better than using a frame pointer.

      Maarten

       

Log in to post a comment.