hi, I'm a C51 beginner,I writen a C51 program which generated binary code about 30Kbytes, but in .asm program,it generated binary code only about 16Kbyte. How can I save the C51 program's code size? thanks!
The 8051 prefered integer size is unsigned 8 bits or unsigned 1 bit. 1)When ever possible use bit then unsigned char, then use char. 2) Use the no integer promote option. This keeps intemediate calculation 8 bits. You might have to change your code to accomadate this. 3) Avoid generic pointers, i.e. always prefer data*, idata*, pdata*, xdata*, or code* over a plain *. 4) If you have the resources, store fequently use variable first in data, then in idata & pdata, and finally in xdata.
You can also reduce some code, especially PUSH and POP instructions, using the using x keyword. Take a look in the C51 User's Manual for more details. There're also a good piece of code about the using keyword posted here in this forum a couple of months ago.