Hi ,
I have one question for keil compiler.
Originally, in the compile result for my project, CONST size is 0 and all of variables with prefix of code are put in CODE area by compiler.
But now, I did some changes in my project and found some of variables with prefix of code are put in CONST area.
Could you pls explain it. thanks a lot.
So what, exactly, did you change?
Are you using LX51?
Actually I changed DEBUG Macro definition as below
Old: #define DBG_LOG1(DBG_LEVEL, DBG_STR_IDX, P0) SiiDbgLogSend(DBG_LEVEL, DBG_STR_IDX, P0)
New: #define DBG_LOG1(DBG_LEVEL, DBG_STR_IDX, STR_FORMAT, P0) SiiDbgLogSend(DBG_LEVEL, DBG_STR_IDX, 1, P0)
at the beginning, I only changed such in 2 c files and no constant size allocated. but after all of c files(~30) applied, constant size become several hundred bytes.
so far, I suspect, in keil complier, when hardcode(numbers) size increased to MAX number, the left code data would be allocated to constant area.
what relation between code and constant in keil? thanks
Yes, I'm using LX51
I have some updates.
My code change is actually to skip string format parameter in debug function so that code size saved.
But I found, as for a C file/module, if no any string format, which is located in code segment, their variables declared with code would be located in const segment by lx51. Interestingly, at this moment, if adding such one simple line code as "printf("hello world")" in one c file, then those code variables in this file would be restored to code segment.
I'm not sure you understand my change now? if yes, pls explain the deeds of lx51. thanks
For "My code change is actually to skip string format parameter in debug function so that code size saved."
I explain more.
for example, DBG_LOG(dbg_level, ID, "hello,test") dbgprint(dbg_level, ID)
By such debug macro, for some c file/module, all of strings happens to disappear. in such case, those variables declared with code in this file/module would be put in const memory class by LX51.
I know, actually code and const memory class are all in ROM, but don't know why
who can help explain it? thanks
But LX51 has the facility to map some of your "ROM" (did you mean "Flash") for constants into XDATA space - thus saving CODE address space.
Could this be what's happening...?
I think it's NOT the case you said.
for const in keil, seems a lot confusing. let me explain more.
by Keil manual, if variables are declared by "const", they would be assigned to xdata.
Besides, "const" also exists in memory class, shown as below. here "const", the same as "code", also put in ROM.
Program Size: data=143.1 xdata=3694 const=26 code=61164
My question is how Lx51 decide to put variables declared with "code" in const or code memory class? thanks
By keil manual again, if variables declared with code, then they would be assigned to code memory class.
But I found, under some conditions, those code variables are put in const memory class instead of code class, though they both are put in ROM. who can help explain deeds of lx51? thanks