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

Switching from CC5x to CCS C compiler

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



Joined: 27 Dec 2006
Posts: 28

View user's profile Send private message

Switching from CC5x to CCS C compiler
PostPosted: Wed Sep 05, 2007 4:38 am     Reply with quote

Hi,

I really like the feature rich CCS compiler, but I can't find a quick equivalent for the .low8, .high8 extensions. In CC5x, these allow you to read or write the MSB or LSB of a 16 bit word. It can be really useful to only affect the lower 8 bits or higher 8 bits. I know I can mask and use OR and AND to isolate the bits. There is also the MAKE8, MAKE16 commands.

Is there anything that will do:
int 8 A;
int16 B;

A = A + B.low8; //this is how I would do it in CC5x.
B.high8 ++; // add to MSB only
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Wed Sep 05, 2007 7:14 am     Reply with quote

I thought I saw something like what you want, but can't find it in the help file. But, you can easily define a macro to do it, something like:

#define lobyte(x) (*((int8*) &x + 1)) // These may be backwards
#define hibyte(x) (*((int8*) &x + 0)) // I forget which "endian" ccs uses

int8 A;
int16 B;

A = A + lobyte(B);
hibyte(B)++;

This is off the top of my head, not tested, and likely has errors :(

But something like this Smile

Ken
ckielstra



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

View user's profile Send private message

PostPosted: Wed Sep 05, 2007 7:53 am     Reply with quote

Another thread discussing this topic: http://www.ccsinfo.com/forum/viewtopic.php?t=20793
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Wed Sep 05, 2007 8:02 am     Reply with quote

You can use the #byte directive to map an alias variable name over an existing variable (or any direct address in RAM). Be sure to write no ; at the end of the #byte directive.
Code:
int8 a;
int16 b;
#byte b_low = b
#byte b_hi = b+1

a = a + b_low;
b_hi++;
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