From: <no...@so...> - 2002-07-26 16:00:58
|
Bugs item #586918, was opened at 2002-07-26 03:18 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=586918&group_id=599 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: Optimization error: external RAM... Initial Comment: Dear Sir, I send to You 3 small 'C' sources compiled with SDCC version 'mcs51 2.3.1-pj3 (Jan 20 2002) (MINGW)'. In each of those sources, I try to make this: 'nb = _CMD_BUF[0];' In source 1, I wrote: nb = _CMD_BUF[0]; In source 2, I wrote: nb = (xdata unsigned char) _CMD_BUF[0]; In source 3, I wrote: nb = (xdata) _CMD_BUF[0]; Only source 3 is encoded correctly from C to assembler. _CMD_BUF is a buffer of 256 bytes starting in external RAM from address 0x0000 and has been declared as follows: xdata at 0x0000 unsigned char _CMD_BUF[256]; nb is a local variable. I use the small memory model. Source 1: (See attachment METHOD1.ZIP) -------------------------------------------------------------- nb = _CMD_BUF[0]; // (from line 14 in ng7.c1) The encoding is: (see ng7.ls1) mov _dummy_process_parm_2,__CMD_BUF. My conclusion is: due to optimizations, the compiler forgot that _CMD_BUF[0] was a byte in external RAM. The compiler encoded it as a byte from internal RAM. Source 2: (See attachment METHOD2.ZIP) -------------------------------------------------------------- nb = (xdata unsigned char) _CMD_BUF[0]; // (from line 14 in ng7.c2) Same as source 1 but with a casting; same results than from source 1. Source 3: (See attachment METHOD3.ZIP) -------------------------------------------------------------- nb = (xdata) _CMD_BUF[0]; // (from line 14 in ng7.c3) By adding (xdata) before _CMD_BUF[0], the encoding is now correct: _CMD_BUF[0] is seen by the compiler as coming from external RAM. My question is: Is it an optimization problem? Do You have a solution? Is it correct to use this work around? (xdata before _CMD_BUF[0]). Best Regards, Leon GODET. ---------------------------------------------------------------------- Comment By: Paul Stoffregen (pjs) Date: 2002-07-26 09:00 Message: Logged In: YES user_id=104682 Leon, No files ended up attached to this bug report. I tried to reproduce this, and all three cases were compiled correctly with a MOVX instruction. Here's what I tried: xdata at 0x0000 unsigned char _CMD_BUF[256]; char test1(void) { unsigned char nb; nb = _CMD_BUF[0]; return nb; } char test2(void) { unsigned char nb; nb = (xdata unsigned char)_CMD_BUF[0]; return nb; } char test3(void) { unsigned char nb; nb = (xdata)_CMD_BUF[0]; return nb; } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=586918&group_id=599 |