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

size of reentrant stack of compact model

The user manual of Cx51 describes that maximum size of reenterant stack in compact memory model is 256 Bytes. While in STARTUP.A51 sets its top to 0xFFFFh which is 64 KBytes.
Can any body tell me what is the exact size of the reenterant stack in compact model

  • The user manual of Cx51 describes that maximum size of reenterant stack in compact memory model is 256 Bytes. While in STARTUP.A51 sets its top to 0xFFFFh which is 64 KBytes. Can any body tell me what is the exact size of the reenterant stack in compact model

    Well, the COMPACT reentrant stack is stored in PDATA which is accessed usingR0/R1 in the MOVX @R0 and MOVX @R1 instructions. Since R0 and R1 are 8-bit registers, one can infer that the maximum addressed space is 256 bytes.

    As for the top of the stack, from the STARTUP.A51 file:

    ;  Stack Space for reentrant functions in the COMPACT model.
    PBPSTACK        EQU     0       ; set to 1 if compact reentrant is used.
    PBPSTACKTOP     EQU     0FFFFH+1; set top of stack to highest location+1.
    

    as you can see, PBPSTACKTOP must be set to the top of the stack plus 1. COMPACT mode uses P2 to contain the upper address byte. So, if you set P2=0xFF, then this is correct. If you set P2=0xAA, this must be changed as follows:

    PBPSTACKTOP     EQU     0AAFFH+1
    

    Note that you'll also need to enable the PDATA page (in STARTUP.A51) as follows (assuming you're using page 0xAA):

    ;------------------------------------------------------------------------------
    ;
    ;  Page Definition for Using the Compact Model with 64 KByte xdata RAM
    ;
    ;  The following EQU statements define the xdata page used for pdata
    ;  variables. The EQU PPAGE must conform with the PPAGE control used
    ;  in the linker invocation.
    ;
    PPAGEENABLE     EQU     1       ; set to 1 if pdata object are used.
    ;
    PPAGE           EQU     0xAA    ; define PPAGE number.
    ;
    PPAGE_SFR       DATA    0A0H    ; SFR that supplies uppermost address byte
    ;               (most 8051 variants use P2 as uppermost address byte)
    ;
    ;------------------------------------------------------------------------------
    

    Jon