Keil Logo

C51: WHY NUMBER OF BYTES PASSED TO PRINTF IS LIMITED


Information in this article applies to:

  • C51 Version 5.50

QUESTION

According to the Cx51 User Guide, it mentions "The total number of bytes that may be passed to printf is limited due to the memory restrictions imposed by the 8051." What does it mean? Could you explain it in detail?

ANSWER

The 8051 only has 128 bytes of directly addressable DATA memory.

C functions that use variable length argument lists normally have arguments passed on the stack.

With the 8051, using stack frames for function arguments uses up the memory very quickly. Simulating a stack frame in XDATA memory is VERY SLOW.

The best alternative is overlaying and re-using DATA memory by creating a call tree of the program at link time. However, one problem with this method is that variable length argument lists must be limited to some predetermined size.

By default, we limit that to 15 bytes of arguments for memory models that use DATA memory. The limit is 40 bytes for memory models using XDATA.

The MAXARGS compiler directive lets you change the default limit to whatever you desire. Note that since the limit if DATA space is 128 bytes (including register banks and the bit area) you can't just set MAXARGS to 128.

This is what is meant when the compiler manual refers to the limited number of bytes that may be passed to printf.

MORE INFORMATION

  • Refer to MAXARGS in the Cx51 User's Guide.

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Tuesday, October 24, 2006


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.