This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Writing defined data to my stack

Genius 4170 points

Other Parts Discussed in Thread: MSP430F2274

Hello,

 

How can i write defined data to my stack.

I am using the MSP430F2274 with 1 kB ob RAM, the RAM lies in the area between 0x0200 and 0x0600.

 

I defined my stack size to be 80 Bytes, so it starts at 0x 05B0:

 

0x5B0 stack


3E4F    3B97    BFF3    B39B    A869    FC6A    B11B    A50E    A887    B9DF    DD79    697B    DD79    697B    8F18    4E20
0101    7A11    0000    909E    0002    0101    9600    0000    0000    8BB6    05EE    9200    8178    9454    0000    0000
838E    0000    0002    0000    916E    DD79    697B    93B0

0x0600 _STACK_END

 

This i can read out in the memory view, while debugging. I got the tip that i could write predefined values into the stack lie 0xAD, and then in the running code i can see how many of my stack fields are used and how many stay untouched, to get a better feeling on how much stack memory gets used by my program.

 

Question now is, how can i predefine my stack values to e.g. 0xAD??

 

Thanks for your time and help.

Seb

  • you can do this in IAR memory view. just select the memory address(es) you want to change and then write a value to them.

    are you using IAR? you can also look at the stack under the view menu and it will show you the max size the stack ever got too

  • Dan-o said:

    you can do this in IAR memory view. just select the memory address(es) you want to change and then write a value to them.

    are you using IAR? you can also look at the stack under the view menu and it will show you the max size the stack ever got too

    Aside from that, IAR debugger will also fill the RAM reserved for stack with 0xCD initially or after you click the RESET. I do not know CCV, (cannot afford it).

     

  • seb said:
    I defined my stack size to be 80 Bytes, so it starts at 0x 05B0:

    No. It starts at the end of ram (0x600) and grows down as it is being used.

    The '80 bytes stack size' defintion is jsut a trick to cause a linker error if there is not enough memory for all your variables and the stack and a hint to the debugger to trigger a warning if it detects the stack pointer being outside the assumed range.

    If you change this setting, it will not change the generated binary by a single bit. Only the debugging information.

    seb said:
    Question now is, how can i predefine my stack values to e.g. 0xAD?

    Not at all. If you place somehting there, it occupies space there and teh linker will complain that there is no space for the stack.
    You can fill the memory inside your main loop (but local variable sin main are already written on teh stack, so don't overwrite them).

    Or you can tell the debugger to fill the memory are with data. Which needs to be done on each debugging session start.

    Or you write an assembly function that is linked into the C++ startup code and initializes all ram memory to a certain value before the normal startup code initializes the global variables and the stack pointer.

**Attention** This is a public forum