ARM Technical Support Knowledge Articles


Applies to: C51 C Compiler


Information in this article applies to:


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?


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.


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.



Article last edited on: 2006-04-28 06:58:22

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential