C251 User's Guide

Tips for Porting C51 Code

When porting existing C51 code, there are a number of minor differences between C51 and C251 that you must consider. Following is a list of typical problems you may encounter:

  • The code generated by C251 is independent of the current registerbank selected and the C51 directives NOAREGS and REGISTERBANK are no longer necessary. If these directives are used, C251 generates a WARNING or ERROR message.
  • The memory type specifier must be given after the variable type as shown in the following example:
    int xdata value;    /* correct in both C51 and C251                */
    xdata int value;    /* illegal: old C51 form not supported by C251 */
    
  • The pdata memory type usually gives problems in the PAGE mode of the 251 MCU and should not be used for new applications.
  • The printf library function and the variable argument list makes default promotion to int even for char and unsigned char variables. The following printf statement generates incorrect results in C251.
    unsigned char c1;
    
         /* works in C51, but gives wrong output in C251:        */
    printf ("%bx %bi", c1, 1);
    
         /* C251 defaults to int and does not need the b prefix: */
    printf ("%x %i", c1, 1);
    
         /* the following two forms work in both C51 and C251:   */
    printf ("%bx %bi", (unsigned char) c1, (char) 1);  /* optimal code */
    printf ("%x %i", (unsigned int) c1, (int) 1);      /* passes int   */