51 single occupancy issues ram of local variables

51 single occupancy issues ram of local variables

First, the problem

Since the basic work does not use 51 or 51 enhanced single-chip type and the like. St. HC89S003F4 recently enhanced debugging core, transplant practical code 32, and found RAM burst! ! !

image

Second, practice

To see the problem, I re-created a simple project.

#include <reg52.h>
int test(void)
{
    char a[20];
    return 1;
}
void main(void)
{
    test();
    while(1);
}

Results a change much, RAM will increase the number of.

Look at STARTUP.A51the papers and found stm32 start the program with not the same, there is no definition of heap heap, stack also be used again at the end of the additional RAM.

Finally, read this post
http://bbs.21ic.com/icview-281857-1-1.html

Is almost certain that no place to store local variables, all in the RAM memory! !


But this is unreasonable ah, would not write a function accounted for part of RAM, do not have dozens of functions, RAM is not enough. So I began to see an assembler generated.

  • Right main.cOpen Configuration Options window, check the SRC

image

  • The compiler will Project\Objectsgenerate a file main.SRC

image

image

image

  • After repeated testing, we found local variables used transfer participants revel R3 ~ R7, participants use the pointer pass R1 ~ R3; parameter passing or greater than two bytes long type using the RAM memory;

CONCLUSIONS

Local variable stack 51 does not exist, save R0 ~ R7, may be associated with the eight small-capacity machine, the addressing slower.

Anyway, when the attention of the incoming parameters need to use less than three, like a big footprint va_list like local variables as much as possible not to use, so space is not enough.

Guess you like

Origin www.cnblogs.com/yywBlogW/p/11511584.html