| ||||||||
Technical Support Support Resources Product Information | C51: STATIC DATA VARIABLESQUESTIONWhen I declare variables in DATA space, they are declared as static. Subsequently, I have run out of internal data space. What's going on? Why are my variables being declared as static? ANSWERThis happens when you define your application using a memory model other than SMALL. As only one area is overlaid by the linker, all other areas are static. So when you then declare a variable as DATA, it is declared static. Look at this example:
#pragma LA
void main ( void )
{
data unsigned char loop;
for (loop = 0 ;loop <= 10;loop++)
{
}
}
In this example, the variable loop would normally be allocated in external data due to the LARGE memory model declaration. However, the programmer has over ridden the default and specified the data area for the loop variable. This listing shows:
C51 COMPILER V5.50, 499
DOS C51 COMPILER V5.50, COMPILATION OF MODULE 499
OBJECT MODULE PLACED IN 499.OBJ
COMPILER INVOKED BY: E:\C51\BIN\C51.EXE 499.C CD SB DB OE ROM(COMPACT) MOD517
stmt level source
1 #pragma LA
2
3 void main ( void )
4 {
5 1 data unsigned char loop;
6 1
7 1 for (loop = 0 ;loop <= 10;loop++)
8 1 {
9 2 }
10 1 }
11
C51 COMPILER V5.50, 499
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION main (BEGIN)
; SOURCE LINE # 3
; SOURCE LINE # 4
; SOURCE LINE # 7
0000 E4 CLR A
0001 F500 R MOV loop,A
0003 ?C0001:
; SOURCE LINE # 8
; SOURCE LINE # 9
0003 0500 R INC loop
0005 E500 R MOV A,loop
0007 B40BF9 CJNE A,#0BH,?C0001
; SOURCE LINE # 10
000A ?C0004:
000A 22 RET
; FUNCTION main (END)
C51 COMPILER V5.50, 499 17/11/98 12:49:16 PAGE 3
NAME CLASS MSPACE TYPE OFFSET SIZE
==== ===== ====== ==== ====== ====
main . . . . . . . . . . . . . . . . . PUBLIC CODE PROC ----- -----
loop . . . . . . . . . . . . . . . . STATIC DATA U_CHAR 0000H 1
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 11 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
Notice that the variable loop is declared as static. To prevent this follow the instructions in Application Note 101. Last Reviewed: Tuesday, March 28, 2006 | |||||||
| ||||||||