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 CCS Technical Support

Built-in assembler missing pseudo operator high & low

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



Joined: 14 Jan 2007
Posts: 20
Location: Hungary

View user's profile Send private message

Built-in assembler missing pseudo operator high & low
PostPosted: Mon May 14, 2007 3:27 am     Reply with quote

Hi, guys,
The following asm code results to an error compiling my project:
...
#asm
...
MOVLW flash_wr_block //get the number of writable bytes constant
MOVWF flash_wr_counter // store it in a data memory location
MOVLW high datbuf // page address of the start of data buffer (HI byte)
MOVWF FSR0H
MOVLW low datbuf // address of start of the buffer within the page (LO byte)
MOVWF FSR0L
...
#endasm
...

The CCS C compiler seems not to understand high & low operators.
The code compiled with MPASM works fine.
CCS C write_flash doesn't work correctly with PIC18F45J10, that's why I have to implement it in asembly.
How can I refer to the higher and lower parts of a data memory location using the built-in assembler? Can anyone help?

bye

tojape
_________________
The computer helps solving the problems which would have never arised without computers
ckielstra



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

View user's profile Send private message

PostPosted: Mon May 14, 2007 3:50 am     Reply with quote

Code:
movff datbuf, FSR0L     // Low byte of pointer
movff &datbuf+1, FSR0H  // High byte of pointer


This works in v3.249. I haven't tested in v4.xxx but because of a changed pointer arithmetic it might be you have to cast the pointer to a char pointer.
tojape



Joined: 14 Jan 2007
Posts: 20
Location: Hungary

View user's profile Send private message

PostPosted: Mon May 14, 2007 4:55 am     Reply with quote

ckielstra wrote:
Code:
movff datbuf, FSR0L     // Low byte of pointer
movff &datbuf+1, FSR0H  // High byte of pointer


This works in v3.249. I haven't tested in v4.xxx but because of a changed pointer arithmetic it might be you have to cast the pointer to a char pointer.


Thanks, but the compiler reports an error that it needs an identifier instead of "&datbuf+1" .
I use v4.22.
I am afraid, you misunderstood me, since datbuf is a name of a variable (array of bytes) and "movff datbuf,FSR0L" would copy the content of the first byte of datbuf to the register FSR0L while I want to load the address of datbuf to FSR0L and H.
However, thank you for taking care of my problem.
Hi,
tojape
_________________
The computer helps solving the problems which would have never arised without computers
ckielstra



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

View user's profile Send private message

PostPosted: Mon May 14, 2007 6:38 am     Reply with quote

You didn't give the definition for datbuf, it must be a pointer.

The syntax is kind of confusing and undocumented, see also http://www.ccsinfo.com/forum/viewtopic.php?t=27114

This should work (tested in v4.032):
Code:
  int8 DatBuf[25];
  int8* p_data;
 
  p_data = DatBuf;
 
  #ASM
  movff p_data, FSR0L      // copy low byte of pointer
  movff &p_data+1, FSR0H   // copy high byte of pointer
  #ENDASM


I've tried several pointer cast variations but could only get it to work when using a _real_ pointer variable.
tojape



Joined: 14 Jan 2007
Posts: 20
Location: Hungary

View user's profile Send private message

PostPosted: Mon May 14, 2007 8:13 am     Reply with quote

Dear ckielstra,

thanks a lot, the solution you suggested works fine.

Heve a nice day,
tojape
_________________
The computer helps solving the problems which would have never arised without computers
Ttelmah
Guest







PostPosted: Mon May 14, 2007 9:12 am     Reply with quote

This was discussed some time ago, in the early days of the V4 compilers. Completely 'non intuitively', you can use a 'cast', but only by casting the _value_, not the pointer!.
Code:

   int16 fred;
   #ASM
   movff fred, FSR0L      // copy low byte of value
   movff &(int8)fred+1, FSR0H   // copy high byte of 16bit value!...
   #ENDASM

Totally silly syntax, but it appears that the internal 'address reference' function inside the assembler, only works with 8bit values. However it happily moves to the next byte of a 16bit value, if you tell it that the value is 8bit!...

This generates:
Code:

....................    #ASM 
....................    movff fred, FSR0L      // copy low byte of pointer 
001E:  MOVFF  28,FE9
....................    movff &(int8)fred+1, FSR0H   // copy high byte of pointer 
0022:  MOVFF  29,FEA
....................    #ENDASM 

Correctly accessing the second byte.
The syntax of the internal assembler, is really silly at times.

Best Wishes
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