<?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>help!why not use Rx as loop counter?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/23231/help-why-not-use-rx-as-loop-counter</link><description> 
I have a problem. I write a function in another c source file not
main file, in this function nothing do, and I declare the function as
extern. In main function I invoke it 200 times. However, the compiler
does not use registerbank as counter. Why?</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/101388?ContentTypeID=1</link><pubDate>Wed, 03 Dec 2008 00:15:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:576bd1c5-dc32-43c0-8710-cd45534a985b</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Why was it a &amp;quot;problem&amp;quot; to you in the first place?&lt;/p&gt;

&lt;p&gt;
As Per says, your &amp;quot;solution&amp;quot; is storing up potentially far more
real problems for you in the future...&lt;/p&gt;

&lt;p&gt;
Again: if you &lt;i&gt;&lt;b&gt;really&lt;/b&gt;&lt;/i&gt; need to worry about
register-level detail like this, then &lt;b&gt;you should be writing in
assembler!&lt;/b&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/101389?ContentTypeID=1</link><pubDate>Tue, 02 Dec 2008 17:51:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:137753b5-4ef6-497b-931f-5ff0ae3c1798</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
And you are sure that func1() really does not modify any
registers?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/76933?ContentTypeID=1</link><pubDate>Tue, 02 Dec 2008 17:03:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9346109c-c26f-46a1-9732-db5a2004a97b</guid><dc:creator>huang faqian</dc:creator><description>&lt;p&gt;&lt;p&gt;
I read the Keil C51 user manual. I find that the &lt;b&gt;REGUSE&lt;/b&gt;
directive specifies which registers are modified by the specified
function. So I add following code in func1() source file:&lt;br /&gt;
#pragma asm&lt;br /&gt;
$REGUSE func1()&lt;br /&gt;
#pragma endasm&lt;br /&gt;
and I get the assembly code:&lt;/p&gt;

&lt;pre&gt;
    61:         MOV     R7,#0C8H
    62: ?C0002:
    63: ;       {
    64:                         ; SOURCE LINE # 27
    65: ;             func1();
    66:                         ; SOURCE LINE # 28
C:0x0003    7FC8     MOV      R7,#TMR2CN(0xC8)
    67:         LCALL   func1
    68: ;       }
    69:                         ; SOURCE LINE # 29
C:0x0005    120022   LCALL    FUNC1(C:0022)
    70:         DJNZ    R7,?C0002
&lt;/pre&gt;

&lt;p&gt;
and the problem fixed. Many thanks,everybody.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/52972?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2008 10:51:02 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ee462016-acef-464d-8b4a-2de742aa4a38</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;in another c source file not main file, in this function
nothing do,&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
You know that --- but the compiler doesn&amp;#39;t. It has to assume that
func1() modifies &lt;b&gt;all&lt;/b&gt; the registers. So it can&amp;#39;t assume that
the value stored in a general-purpose register like R6 will still be
the same after func1() has been called.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;However, the compiler does not use registerbank as counter.
Why?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Because it wouldn&amp;#39;t work.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/125097?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2008 04:56:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f4837e90-7040-4623-9503-bfa5ab8a5a39</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
As you might have guessed from my replies, I also missed it
initially!&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;I never use the first one, precisely because someone quiclky
scanning the code might make a bad assumption.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Absolutely. Plus all the other good reasons equivalent to always
using the braces on an &amp;#39;if&amp;#39; even when not strictly necessary...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/114471?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2008 04:33:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:78256e1f-7541-49d4-a67e-ecd378620798</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Keil has somehow forgotten to specify if &amp;quot;data&amp;quot; binds to the left
or to the right, but their own placement of the keyword does give an
indication that it binds to the variable and not to the type, i.e.
that it follows Andys example.&lt;/p&gt;

&lt;p&gt;
Compare with * for pointesrs, i.e.&lt;/p&gt;

&lt;pre&gt;
unsigned char * i,j;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
may look like&lt;/p&gt;

&lt;pre&gt;
unsigned char* i;
unsigned char* j;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
but is actually:&lt;/p&gt;

&lt;pre&gt;
unsigned char *i;
unsigned char j;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/114472?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2008 04:30:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:dc316b82-b636-4391-9746-3f3cf094222f</guid><dc:creator>Non Keil Related</dc:creator><description>&lt;p&gt;&lt;p&gt;
Sorry, I missed that bit.&lt;/p&gt;

&lt;p&gt;
Anyway, yes, I think you are correct ...&lt;/p&gt;

&lt;pre&gt;
unsigned char *i, j;
&lt;/pre&gt;

&lt;p&gt;
is equivalent to:&lt;/p&gt;

&lt;pre&gt;
unsigned char *i;
unsigned char  j;
&lt;/pre&gt;

&lt;p&gt;
Is it not???&lt;/p&gt;

&lt;p&gt;
I never use the first one, precisely because someone quiclky
scanning the code might make a bad assumption.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/101385?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2008 04:10:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9a88b5bd-47e8-4d95-9aba-bead42d0eba3</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Or is it?&lt;/p&gt;

&lt;p&gt;
Maybe&lt;/p&gt;

&lt;pre&gt;
unsigned char data i,j;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
Is equivalent to&lt;/p&gt;

&lt;pre&gt;
unsigned char data i;
unsigned char      j;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/89407?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2008 04:08:43 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f73e732f-32d1-4e69-bca2-f9c93965ea40</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
But that is true of both of them - so why did the compiler just
put one of them in a Register...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/52983?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2008 04:04:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bdcb16c2-04cb-4e4b-a5a5-d5e122ea126a</guid><dc:creator>Non Keil Related</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;However, the compiler does not use registerbank as
counter.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I assume you&amp;#39;re asking why (for example) R7 isn&amp;#39;t being used as
your counter?&lt;/p&gt;

&lt;p&gt;
Probably something to do with the fact that you&amp;#39;ve explicitly told
the compiler to store the variables in &lt;b&gt;data&lt;/b&gt; space.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help!why not use Rx as loop counter?</title><link>https://community.arm.com/thread/52975?ContentTypeID=1</link><pubDate>Mon, 01 Dec 2008 02:21:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ae220636-fff2-41a0-b621-307b5e0705af</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Why do you have separate variables - &amp;#39;i&amp;#39; and &amp;#39;j&amp;#39; - to index the
two loops?&lt;/p&gt;

&lt;p&gt;
If it really matters to you how the code is implemented at the
register level, then you need to be using assembler!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>