View previous topic :: View next topic |
Author |
Message |
anestho
Joined: 27 Dec 2006 Posts: 28
|
Switching from CC5x to CCS C compiler |
Posted: Wed Sep 05, 2007 4:38 am |
|
|
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
|
|
Posted: Wed Sep 05, 2007 7:14 am |
|
|
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
Ken |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Wed Sep 05, 2007 8:02 am |
|
|
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++; |
|
|
|
|