CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to copy arrays quickly ??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

How to copy arrays quickly ??
PostPosted: Wed Jan 17, 2007 11:00 am     Reply with quote

Hi,

How do I quickly copy arrays in PCM 3.228 ??

I use a for loop to run through the arrays, but are there any faster methods than this ???

thanks
arunb
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 17, 2007 11:23 am     Reply with quote

Use memcpy(). It's in the CCS manual.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jan 17, 2007 5:49 pm     Reply with quote

Memcpy() is indeed a better solution than a for-loop. Something not mentioned in the manual is that the CCS compiler is using an internal optimized memcpy() routine, not the memcpy routine you will find in one of the standard include files. The internal routine is so fast because it uses the index register which has an auto increment feature.

For PIC18 only:
One limitation of the CCS generated code is that it uses only 1 of the 3 available index registers. There are some situations where you have to copy data from one array to another but memcpy is not flexible enough. In these situations you can achieve higher speeds by writing your own (assembler) code using two index registers.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 18, 2007 10:01 am     Reply with quote

Any chance either of you fellows could post that type of assembly code.
I know this isn't a forum for assembly code, but now you have my interest peeked. I would love to see how this is done.
You could use a #asm #endasm and claim it to be ccs related. : )
Are both of you also on the Microchip forum??
I could ask for it there.
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Jan 18, 2007 12:53 pm     Reply with quote

Code:
#byte FSR0H = 0xFEA
#byte FSR0L = 0xFE9
#byte FSR1H = 0xFE2
#byte FSR1L = 0xFE1
#byte POSTINC0 = 0xFEE
#byte POSTINC1 = 0xFE6

void memcpy_asm(int8 *src, int8 *dest, int8 n)  {   // n number of bytes to copy
  #asm
  movff &dest+1, FSR1H
  movff dest, FSR1L
  movff &src+1, FSR0H
  movff src, FSR0L
  loop:
  movff POSTINC0, POSTINC1
  decfsz n
  goto loop
  #endasm
}

...not tested.

PS. Though I don't know how safe it is to use the FSR0-2 registers without the compiler being aware of their corrupted contents. (you might want to save/restore them, or as mentioned above knowing the compiler uses FSR0, using FSR1-2 would be safer..)
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 18, 2007 2:03 pm     Reply with quote

thanks, I'll test it out.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jan 18, 2007 8:20 pm     Reply with quote

Hi Ttreitmey,

No, I'm not on the Microchip forum. This forum is taking all my spare time. Wink

Does someone know if the LFSR assembly instruction is supported by CCS? I only get compiler errors.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 18, 2007 9:00 pm     Reply with quote

Funny, I thought they all were. Surprised
How can you find out which are/are not?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 18, 2007 9:15 pm     Reply with quote

This compiles OK with vs. 3.249:
Code:

#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000) 

#define FSR0  0xFE9

//================================
void main()
{
#asm
LFSR  FSR0, 0x0100
#endasm

while(1);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group