Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2579260
  • 博文数量: 320
  • 博客积分: 9650
  • 博客等级: 中将
  • 技术积分: 3886
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-27 21:05
文章分类

全部博文(320)

文章存档

2024年(1)

2017年(5)

2016年(10)

2015年(3)

2014年(3)

2013年(10)

2012年(26)

2011年(67)

2010年(186)

2009年(9)

分类: 嵌入式

2013-03-23 17:47:24

QUESTION
How can I determine the maximum stack size of my program?

ANSWER
There is no automatic way the tools can tell you the maximum stack depth or stack utilization. Because of asynchronous events and interrupts, the automation is too difficult.

However, you can use the ?Vision Simulator which provides the sp_max value in the register window. When you execute all features of your application, this gives you the maximum sp value that has been reached by your application. Make sure that your assumptions about the available stack are correct. Some 8051 variants have just 128 bytes on-chip RAM and therefore the stack space ends at 0x7F.

You should have more bytes available for executed interrupts. As a guideline, there should be enough space to execute the most complex interrupt of your application.

If you cannot use the ?Vision Simulator, use the following method, which works in any debugging tool. You may use the Monitor, the ISD51 In-system debugger, or any in-circuit emulator. The results should be similar.

Locate the beginning of the stack. If you use the C51 compiler, look for the ?STACK symbol. that is listed in the linker map file (*.M51 or *.MAP) 
Fill the stack area with a known value or string. Something like "STACK---", since it's 8 characters long, displays nicely in a memory dump. 
Run your program and make sure you execute every line of code (or as much as makes sense). Make sure you generate interrupts so that they are included in the profile. If your emulator has a code coverage feature, use it to make sure that every path is taken. You can do this with dScope's code coverage feature. 
After your program runs a while, stop it and look at the stack area. You should see garbage for the part of the stack that has been used and the "STACK---" strings in the remainder of the stack. Count the number of complete strings, multiply by 8 (since "STACK---" is 8 bytes long), and you have the number of bytes of remaining stack space. 



参考文章:
阅读(1383) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~