Skip to main content
John F.
Associate III
June 19, 2012
Question

How to fill the stack with a constant?

  • June 19, 2012
  • 2 replies
  • 1058 views
Posted on June 19, 2012 at 11:21

How do I modify (startup*.s ?) to fill the stack with a constant value? Example assembler code would be appreciated. I want to check stack usage. I posted a similar question to this in the Keil forum

http://www.keil.com/forum/docs/thread21045.asp#msg109678

Looking for a quick solution - no lectures please!
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    June 19, 2012
    Posted on June 19, 2012 at 14:22

    Reset_Handler PROC
    EXPORT Reset_Handler [WEAK]
    IMPORT __main
    LDR R0, =__initial_sp
    LDR R1, =0x20010000 ; Top of mem
    LDR R2, =0x6B6B6B6B
    Clear_Heap
    STR R2, [R0, #0]
    ADD R0, #4
    CMP R0, R1
    BNE Clear_Heap
    ; The __main routine resets the stack pointer, and then initialize the static area
    ; it then CLEARS all the space between there and the stack.
    LDR R0, =__main
    BX R0
    ENDP

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    John F.
    John F.Author
    Associate III
    June 19, 2012
    Posted on June 19, 2012 at 14:36

    Thanks Clive. It looks like for the Keil IDE it's also necessary to create a modified copy of the scatter file (*.sct). Please see the link to the Keil forum for full details.

    For anyone else who might help ... I still don't know how to get a view of the stack in the Keil IDE's memory window apart from getting the stack address from the *.map file and typing it in. How to use a symbolic name such as ''STACK''? Don't know.