??? 08/21/05 18:02 Modified: 08/21/05 18:04 Read: times |
#99780 - Keil C51-optimization & Pointers |
Hi all, I am using Keil uVision 2 IDE with c51 V 7.20 compiler. I am developing a project called Vehicle Info System, which has now grown to almost 7800bytes of hex file from C code. Now the problem is, I use 89S52 which has 8KB of flash, so I stand in the edge of Flash. More sorrow is, I am yet to add some more functionalities, which would obviously increase the code size.
The C51 compiler, when operated at optimization level 9 generates just 5300bytes of codes, but most of my pointers are behaving weirdly. Sometimes, the whole chip gets into a weird loop which just puts garbage in the display. Optimisation level 1 does the job fine, my code is running properly yet it ends up with 7.8kB of asm. I searched for keil compiler optimization here but dint find something to solve my problem. What is happening? What am I supposed to do? I suspect the problem is with pointers and accessing methods. My strings are located in the direct 128 byte ram and I am declaring a pointer simply as: char buf[6]="abcde"; char* ptr=buf; What should I do? I am putting those erratic string related functions here for your reference: /*give integer as input get a string as output. returned strlen is fixed,=5*/ char* tostr(unsigned int num) { unsigned int base; unsigned char rem,x; char buff[6]; char *ptr=buff; for(x=4;x>0;--x) { base=rpt(10,x); rem=num/base; *ptr=(char)rem+0x30; num-=rem*base; ptr++; } *ptr=(char)num+0x30; buff[6]=' '; return buff; } /* function used for generating 10000, 1000, 100, 10 successively must be used in conjuction with tostr function*/ unsigned int rpt(unsigned int x,unsigned char y) { unsigned char i; unsigned int temp=1; for(i=1;i<=y;i++) temp*=x; return temp; } /*give string as input string will have 5 charaters get the string with leading zeros blanked returned strlen is constant and =5*/ char* rippleinsert(char* str) { unsigned char i=0; while((*str==(char)0x30)) { *str=(char)' '; str++;i++; } return(str-i); } /*str= 5 byte wide string given as input pos=number of positions required from lsb eg: str=01000, pos=4, returns=1000 eg: str=23456, pos=2, returns=56 same as rippleinsert but we can specify the string length*/ char* ripplepos(char *str,unsigned char pos) { pos=5-pos; while(pos--) str++; return str; } Had this issue raised here before, I am sorry for the redundancy. Thanks and Regards, Vignesh |
Topic | Author | Date |
Keil C51-optimization & Pointers | 01/01/70 00:00 | |
Bad array index | 01/01/70 00:00 | |
oops!! | 01/01/70 00:00 | |
buff[] is auto, not static | 01/01/70 00:00 | |
Back to basics | 01/01/70 00:00 | |
Don't shoot the pianist! | 01/01/70 00:00 | |
Hex file size | 01/01/70 00:00 | |
Optimization pointers | 01/01/70 00:00 | |
sprintf() is fairly large | 01/01/70 00:00 | |
So start a new thread, then! | 01/01/70 00:00 | |
pls...help | 01/01/70 00:00 | |
I disagree![]() | 01/01/70 00:00 | |
My dear Watson ! | 01/01/70 00:00 | |
One size fits all | 01/01/70 00:00 | |
bin = hex / 2.8 | 01/01/70 00:00 | |
hexmap | 01/01/70 00:00 | |
A bit of a sweeping generalisation!! | 01/01/70 00:00 | |
Keil C51-optimization & Pointers | 01/01/70 00:00 |