<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C166 Var verses immediate as index value</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/14657/c166-var-verses-immediate-as-index-value</link><description> Hi All, I&amp;#39;m having a real hard time coming up with a reason why using a local var as an index into a struct fails but that same line with an immediate value specified works properly. Here&amp;#39;s what I mean.. 
 
 
void main(void)
	{
	unsigned char cTemp,</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: C166 Var verses immediate as index value</title><link>https://community.arm.com/thread/94992?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2002 18:19:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2e244e2f-f427-4ff0-a121-3834d5a6400a</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;I just compiled the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
unsigned char lsr = 12;
unsigned char txrx = 34;

struct ct_st
  {
  unsigned char *lsr;
  unsigned char *txrx;
  };


volatile struct ct_st port [] =
  {
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
    { &amp;amp;lsr, &amp;amp;txrx },
  };


void main(void)
	{
	unsigned char  cTemp, cValue;

// Do whats required to get under way.
//----------------------------------------------------------------------------
// 	MAIN_System_Init();


// Endless While loop that the micro runs forever (hopefully).
//----------------------------------------------------------------------------
	while(1)
		{
		cValue = 0x0C;

		cTemp = *port[0x0C].lsr;
		cTemp = *port[0x0C].txrx;

		cTemp = *port[cValue].lsr;
		cTemp = *port[cValue].txrx;

		}
	}
&lt;/pre&gt;
&lt;br /&gt;
and got the following output:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
             ; FUNCTION main (BEGIN  RMASK = @0x4022)
                                           ; SOURCE LINE # 33
                                           ; SOURCE LINE # 34
                                           ; SOURCE LINE # 44
0000         ?C0003:
                                           ; SOURCE LINE # 46
                                           ; SOURCE LINE # 48
0000 F2F13000 R    MOV       R1,port+030H
0004 A9A1          MOVB      RL5,[R1]
;---- Variable &amp;#39;cTemp&amp;#39; assigned to Register &amp;#39;RL5&amp;#39; ----
                                           ; SOURCE LINE # 49
0006 F2F13200 R    MOV       R1,port+032H
000A A9A1          MOVB      RL5,[R1]
                                           ; SOURCE LINE # 51
000C F2F13000 R    MOV       R1,port+030H
0010 A9A1          MOVB      RL5,[R1]
                                           ; SOURCE LINE # 52
0012 F2F13200 R    MOV       R1,port+032H
0016 A9A1          MOVB      RL5,[R1]
                                           ; SOURCE LINE # 54
0018 0DF3          JMPR      cc_UC,?C0003
             ; FUNCTION main (END    RMASK = @0x4022)
&lt;/pre&gt;
&lt;br /&gt;
These look AOK to me.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C166 Var verses immediate as index value</title><link>https://community.arm.com/thread/54260?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2002 14:03:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3c43d5d9-2bc4-4c92-bf39-168f72be6916</guid><dc:creator>Mik Kleshov</dc:creator><description>&lt;p&gt;The first thing I would do is look at the generated code. I think it&amp;#39;s much easier than looking at external bus accesses and gives much more information.&lt;br /&gt;
And another thing. Once I had this weird problem when display in my target worked in debugger mode (running off external RAM) and refused to work when running from internal flash. The reason was that the microcontroller does not release chip select between two accesses to external bus if it runs off internal flash. It&amp;#39;s perfectly correct and documented. I had two insert dummy accesses two XRAM to release the chip select. Maybe that&amp;#39;s the reason why you can&amp;#39;t see enough transitions on chip select?&lt;br /&gt;
Regards,&lt;br /&gt;
- Mike&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C166 Var verses immediate as index value</title><link>https://community.arm.com/thread/38519?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2002 12:05:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8daa7da1-c00a-455f-a7c0-a8144b8de3a2</guid><dc:creator>Tim Hutchinson</dc:creator><description>&lt;p&gt;Thanks for the replies. The struct is declared as volatile and I had reduced optimization all the way to zero with no change. After a day of beating on it and talking to Boniface at Keil I decided on a whim to just create a new project reusing in the exact same source code files and that cured it. I was suspicious of hardware (i.e. external ram) problems causing this but no matter which module I put those 4 lines of code in the result was the same (no external read for the second two). Thanks again for the replies..&lt;br /&gt;
&lt;br /&gt;
~Tim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C166 Var verses immediate as index value</title><link>https://community.arm.com/thread/54261?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2002 04:22:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d244ff56-e8ad-4bd9-b1e0-f2a3b7ad60fa</guid><dc:creator>Mik Kleshov</dc:creator><description>&lt;p&gt;To be sure, try an immediate value that is different from that of cValue. In this case, the compiler would not have an excuse for omitting the piece of code.&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C166 Var verses immediate as index value</title><link>https://community.arm.com/thread/38511?ContentTypeID=1</link><pubDate>Thu, 14 Mar 2002 15:43:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c5a7ccc2-148d-432c-bd14-8fc559fe4c2c</guid><dc:creator>Mark Odell</dc:creator><description>&lt;p&gt;From the code you provide, I cannot tell if *port is declared volatile. If not, the compiler simply says, &amp;quot;Why bother doing this again?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
- Mark&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>