在51单片机中数组的存储位置无非就是RAM和ROM那么什么时候数据会存储到RAM什么时候数据存储到ROM我大致分了一下几种情况。

1:在全局定义的数组: eg: char a [3]={0}; 此时数组a的存储位置为RAM。为什么全局变量会存储到RAM里?因为全局变 量在程序里面随时可能会被修改,比如自己调用,所以不能存储到ROM里。如下图:



如上图我们定义一个数组text可以看到其存储的位置为RAM。
2:code +全局数组 eg: code char a[3]=0{};此时a的存储位置为ROM。



可以看到此时数组text的存储位置为ROM。
3:局部数组 。此时数组的存储位置为ROM



从图中可以看到数组a的数据被存储到 ROM里0137H的位置。
4:static +局部数组。此时数组的存储位置为RAM。



如图,当加上static后数组存储位置变为RAM里的08H。
网友评论