Keil Logo

C51: Porting Code from PL/M-51


Information in this article applies to:

  • C51, all versions

QUESTION

I am porting code from Intel PLM51 to Keil C51 and have a problem with the following construct:

declare loop_ptr_1 word;
declare loop_ptr_1_byte     byte public at ( .loop_ptr_1 + 1 );

I have translated this PL/M-51 statement into the following C construct:

unsigned short loop_ptr_1;
unsigned char data loop_ptr_1_byte _at_ (loop_ptr_1 + 1);

However, the Keil C51 does not allow an _at_ statement to be a variable.

How can I solve this problem?

ANSWER

The Intel PL/M-51 statement:

declare loop_ptr_1 word;
declare loop_ptr_1_byte     byte public at ( .loop_ptr_1 );

can be represented by the following C variable definition:

unsigned char xdata *loop;

To access the elements you need to write:

char xdata array[100];

loop = &array[0];    // is identical with PL/M  loop_ptr_1_word = OFFSET (array[0]);
value = *loop;       // is identical with PL/M   value = loop_ptr_1_byte;

Instead of having two variables that represent the memory address and its contents, the C language needs just one. With ptr the memory address is accessed. With *ptr the memory content is accessed.

In PL/M you might use a 'BASE' variable to address more than just one variable. This can be represented by a union in C.

Example:

union v {
  unsigned char uc[2];
  unsigned int  ui;
}

union v xdata *vptr;

vptr->uc[0];    // byte at memory location 'vptr'
vptr->uc[1];    // byte at memory location 'vptr+1'
vptr->ui;       // word value at memory location 'vptr'

In the beginning, the C constructs look a bit odd to a PL/M programmer, but after a while, you will see the benefits of the pointer constructs. The pointer has an associated type, and therefore it is a lot easier to maintain programs and view memory contents in a debugger.

MORE INFORMATION

  • ANSI C Books like the "The C Programming Language" by Kernigan & Ritchie.

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


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.