piclist 2008\07\27\114610a >
Thread: Starting with C
www.piclist.com/techref/microchip/languages.htm?key=c
flavicon
face BY : sergio masci email (remove spam text)

part 0 152 bytes
 This message is in MIME format.  The first part should be readable text,
 while the remaining parts are likely unreadable without MIME-aware tools.

part 1 2516 bytes content-type:TEXT/PLAIN; charset=UTF-8 (decoded quoted-printable)



On Sun, 27 Jul 2008, Tomás Ó hÉilidhe wrote:

> > > sergio masci wrote:
> > This is one reason why the PIC is seen as so C unfriendly, because (until > > MChip made changes to the way FSR could be used) the PIC did not an > > index+offset addressing mode, only an indirect mode. The index+offset > > addressing mode lets you do away with the "stack_frame_pointer+" > > operation.
> > > Is it not a very small minority of machines that have a "index+offset" > address mode?

No, I'd say it is the other way around.

Off the top of my head:
*** index+offset (or base+index etc)
6502
6800
68hc11
6301
6812
6301
6809
68000
tms9900
msp430
TLCS900
C39
32032
x86
TMS7000
ARM
z80
Z8
Z800
z8000
z80k
NSC800

*** indirect only
8080
PIC
T414
8051


> Let's say you want to set every element of an array to 77, > well it's a commonly held belief that the following code is faster:
> >     char unsigned *p = arr;
> >     char unsigned const *const pover = arr + (sizeof(arr) / sizeof(*arr));
> >     do *p++ = 77;
>     while (pover != p);
> > And here's the alternative:
> >     char unsigned i = 0;
> >     do arr[i++] = 77;
>     while (  (sizeof(arr) / sizeof(*arr)     !=     i  );

which is similar to

    char unsigned i = (sizeof(arr) / sizeof(*arr);
     do arr[--i] = 77;
    while (  i != 0 );

which optimises very well (on a CPU that has index+offset addressing) if you want to do something a little less trivial such as:

   do i--;
      arr[i] = arr[i+1];
   while ( i != 0 );

or even

   do i--;
      arr1[i] = arr2[i];
   while ( i != 0 );


Also consider that the condition
   ((sizeof(arr) / sizeof(*arr) != i)
in many cases needs to be a multi precision comparison on a PIC whereas in a lot of cases an index could be less than 256 (in the above example the comparison actually reduces down to a simple "test if zero")

Anyway before someone jumps on me for mixing the meaning of index+offset from my previous post (where the offset was a small constant e.g. the offset of the array relative to the stack frame, and the index was actually the value of the stack frame) to this new meaning (where offset is actually the address of the array and index is the value of the control variable), let me point out that I just trying to answer a different question as I understand it :-)

Regards
Sergio Masci

part 2 35 bytes content-type:text/plain; charset="us-ascii"
(decoded 7bit)


seeking: better designed
<Pine.LNX.4.61.0807271812050.21080@yoda.srts.co.uk>

In reply to: <488C6D17.2040006@lavabit.com>
See also: www.piclist.com/techref/microchip/languages.htm?key=c
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Starting with C

month overview.

new search...