|
|
View previous topic :: View next topic |
Author |
Message |
shaned
Joined: 13 May 2006 Posts: 3
|
Assembly & array access confusion |
Posted: Mon May 22, 2006 6:28 pm |
|
|
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
|
|
Posted: Tue May 23, 2006 2:49 am |
|
|
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
|
|
Posted: Tue May 23, 2006 6:44 am |
|
|
Thanks for confirming that I'm not out of my mind - at least in this case.
Shane |
|
|
|
|
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
|