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

Assembly & array access confusion

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



Joined: 13 May 2006
Posts: 3

View user's profile Send private message

Assembly & array access confusion
PostPosted: Mon May 22, 2006 6:28 pm     Reply with quote

I've searched and found the famous "Interrupting an Interrupt" posting. I'm including a portion of the example code from the posting wherein I find some troubling syntax:

void mymemcpy(char *dest,char *source, int num)
{
if (GIE)
{
disable_interrupts(GLOBAL);
#ASM
MOVFF dest,FSR0L
MOVFF &dest+1,FSR0H
MOVFF SOURCE,FSR1L
MOVFF &source+1,FSR1H


Note the first MOVFF - it looks reasonable (value at register pointed to by address of first byte of dest is moved to FSR0L). But that second MOVFF really blows my mind.

In C syntax this says to take and address of the address of dest, increment it by the size of the storage type (which is 2 bytes for a PIC18 register address), then grab the value at the resulting register and store in FSR0H.

But if this code does work right (and I have no reason to believe it doesn't) then the indirection operator really isn't working like an indirection operator but more like a hint to the compilter to extract the register address of "dest" and increment it by one byte.

Shane
Ttelmah
Guest







PostPosted: Tue May 23, 2006 2:49 am     Reply with quote

This is one of the 'delightful' differences of the C assembler!.
It uses a strange sort of hybrid of C notation, and assembler notation, that is very poorly documented (if at all...).
The syntax for how to access the second byte of something, came from CCS themselves. It appears that the assembler uses a sort of 'implicit' redirection, with an invisible '*' present. Hence the first line, is really saying 'access the contents of the memory addressed by dest'. I you just add one to dest, it increments dest, rather than accessing the contents of the incremented address. The '&' in assembler, seems to work as 'treat dest as an address', so the second line is taken as 'access the contents of dest, treated as an address, and incremented'.
It is a very odd hybrid notation....

Best Wishes
shaned



Joined: 13 May 2006
Posts: 3

View user's profile Send private message

PostPosted: Tue May 23, 2006 6:44 am     Reply with quote

Thanks for confirming that I'm not out of my mind - at least in this case.

Shane
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