This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unused, but reserved data in the overlay data_group

Hello,

i'm using die uvision2, cx51 7.2 for a philips mx chip. In my following example code, keil reserves data, which is assigned to registers und so furthermore not used.
The problem only comes, when i'm using more params as can all be passed through registers.

thanks for help, solving the problem.

the .c file:

#include <REG51M.H>

typedef unsigned char byteT;
typedef unsigned int  shortT;

void test(shortT param1, shortT param2, shortT param3,shortT param4);
shortT sub2(shortT param1, shortT param2 );

void main(void)
{
	test(0x0011, 0x0022, 0x0033, 0x0044);
	while(1){}
}

void test(shortT param1, shortT param2, shortT param3,shortT param4)
{
	shortT param5 =sub2(param1, param2)+ param3;
	param4++;
}

shortT sub2(shortT param1, shortT param2)
{
	return param1+param2;
}

the map
FUNCTION/MODULE              BIT_GROUP   DATA_GROUP
--> CALLED FUNCTION/MODULE  START  STOP  START  STOP
====================================================
?C_C51STARTUP               ----- -----  ----- -----
  +--> ?PR?MAIN?MAIN

MAIN/MAIN                   ----- -----  ----- -----
  +--> ?PR?_TEST?MAIN

_TEST/MAIN                  ----- -----  0008H 0011H
  +--> ?PR?_SUB2?MAIN

_SUB2/MAIN                  ----- -----  ----- -----

and the .src
	RSEG  ?DT?_test?MAIN
?_test?BYTE:
     param1?140:   DS   2
     param2?141:   DS   2
     param3?142:   DS   2
     param4?143:   DS   2
	ORG  8
     param5?144:   DS   2
; #include <REG51M.H>
;
; typedef unsigned char byteT;
; typedef unsigned int  shortT;
;
; void test(shortT param1, shortT param2, shortT param3,shortT param4);
; shortT sub2(shortT param1, shortT param2 );
;
; void main(void)

	RSEG  ?PR?main?MAIN
main:
	USING	0
			; SOURCE LINE # 9
; {
			; SOURCE LINE # 10
; 	test(0x0011, 0x0022, 0x0033, 0x0044);
			; SOURCE LINE # 11
	MOV  	?_test?BYTE+06H,#00H
	MOV  	?_test?BYTE+07H,#044H
	MOV  	R3,#033H
	MOV  	R2,#00H
	MOV  	R5,#022H
	MOV  	R4,#00H
	MOV  	R7,#011H
	MOV  	R6,#00H
	LCALL	_test
?C0001:
; 	while(1){}
			; SOURCE LINE # 12
	SJMP 	?C0001
; END OF main

; }
;
; void test(shortT param1, shortT param2, shortT param3,shortT param4)

	RSEG  ?PR?_test?MAIN
_test:
	USING	0
			; SOURCE LINE # 15
	MOV  	param3?142,R2
	MOV  	param3?142+01H,R3
;---- Variable 'param2?141' assigned to Register 'R4/R5' ----
;---- Variable 'param1?140' assigned to Register 'R6/R7' ----
; {
			; SOURCE LINE # 16
; 	shortT param5 =sub2(param1, param2)+ param3;
			; SOURCE LINE # 17
	LCALL	_sub2
	MOV  	A,param3?142+01H
	ADD  	A,R7
	MOV  	param5?144+01H,A
	MOV  	A,param3?142
	ADDC 	A,R6
	MOV  	param5?144,A
; 	param4++;
			; SOURCE LINE # 18
	INC  	param4?143+01H
	MOV  	A,param4?143+01H
	JNZ  	?C0006
	INC  	param4?143
?C0006:
; }
			; SOURCE LINE # 19
	RET
; END OF _test

;
; shortT sub2(shortT param1, shortT param2)

	RSEG  ?PR?_sub2?MAIN
_sub2:
	USING	0
			; SOURCE LINE # 21
;---- Variable 'param2?246' assigned to Register 'R4/R5' ----
;---- Variable 'param1?245' assigned to Register 'R6/R7' ----
; {
			; SOURCE LINE # 22
; 	return param1+param2;
			; SOURCE LINE # 23
	MOV  	A,R7
	ADD  	A,R5
	MOV  	R7,A
	MOV  	A,R6
	ADDC 	A,R4
	MOV  	R6,A
; }
			; SOURCE LINE # 24
?C0005:
	RET
; END OF _sub2

Parents
  • John,

    This may be a completely out of left-field guess, but there's some inconsistency with your code that might cause the compiler to try and figure out what you're doing. For instance, you're passing param4 by value, not by reference, so really, the line

    param4++;

    in test(...) has no effect. Perhaps the compiler thinks that what you're trying to do with these is generate memory accesses for some peripheral functionality and so it maps them all to memory areas for that purpose. Similarly, the assignment to param5 before the return doesn't really do anything. If I were a compiler, and were guessing, I would assume that these were all already peripherals mapped to memory since there's no other explanation for the fact that the code doesn't do anything.

    Maybe that's just a vestige of the way you contrived the example though? Is there some real code that does this?

    Or for that matter, maybe it's a real bug and I'm way off-base.

Reply
  • John,

    This may be a completely out of left-field guess, but there's some inconsistency with your code that might cause the compiler to try and figure out what you're doing. For instance, you're passing param4 by value, not by reference, so really, the line

    param4++;

    in test(...) has no effect. Perhaps the compiler thinks that what you're trying to do with these is generate memory accesses for some peripheral functionality and so it maps them all to memory areas for that purpose. Similarly, the assignment to param5 before the return doesn't really do anything. If I were a compiler, and were guessing, I would assume that these were all already peripherals mapped to memory since there's no other explanation for the fact that the code doesn't do anything.

    Maybe that's just a vestige of the way you contrived the example though? Is there some real code that does this?

    Or for that matter, maybe it's a real bug and I'm way off-base.

Children
  • Thanks for your replies, but it ist not realy my problem. (Please, the code is only an example.)

    Im passing so many params, because i normaly have to do a call before test(), now i call it direct after entering test(), where i also
    use the correct param order to optimize code.

    you can see in the src file, that there is memory space reserved for param1 and param2

         param1?140:   DS   2
         param2?141:   DS   2
    

    Now, i call from main the test() func and there you see, that these params are assigned to registers

    ;---- Variable 'param2?141' assigned to Register 'R4/R5' ----
    ;---- Variable 'param1?140' assigned to Register 'R6/R7' ----
    

    So the reserved space for these params are not needed an never used.

    If i use only 3x 2byte params and keil assigns params to register, he dont reserve these params, but in this case he does.

    How can tell keil, he optimized this code himself, also not to reserve these params?

  • "So the reserved space for these params are not needed an never used."

    OK, then I accurately guessed what you perceive to be the problem. Now, why do you consider it to be a problem? Are you down to the last few remaining bytes in data memory and are running out? Is nothing else in your "real" code overlaying this area and therefore those couple of unused bytes are a concern?