| ||||||||
Technical Support Support Resources Product Information | C51: PORTING CODE FROM PL/M-51Information in this article applies to:
QUESTIONI 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? ANSWERThe 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
SEE ALSOLast Reviewed: Friday, April 28, 2006 | |||||||
| ||||||||