Jump to content
Sign in to follow this  
shaihalud

16 bit variables on 8 bit targets

Recommended Posts

I was just wondering if 16 bit variables are supported by the C2C compiler when targetting 8 bit MCU's, like for example the PIC 16F628? Does the compiler generate code to do 16 bit "software arithmetic" on 8 bit hosts?

 

When I initially began using the C2C compiler I got the impression I could not use 16 bit variables on 8 bit targets but maybe I goofed somewhere in my code.

 

shaihalud

Share this post


Link to post
Share on other sites
I was just wondering if 16 bit variables are supported by the C2C compiler when targetting 8 bit MCU's, like for example the PIC 16F628? Does the compiler generate code to do 16 bit "software arithmetic" on 8 bit hosts?

Yes. I think C2C doesn't even support any 16 bit MCU's, and thus doesn't provide any support for "native" 16 bit instructions. Be careful with the 16 bit operations in C2C, as they might not always work as supposed.

Share this post


Link to post
Share on other sites

Yes, the C2C will do 16-bit, unsigned int arithmetic -- you can add, increment, decrement, pass as parameters, and return int values.

 

You CAN'T pass " int * " elements, but since you can return int, that shouldn't be a problem.  Also, I've found you can get the value of an int modified inside a subroutine with the #define:

 

// Having called a routine, get the modified parm into 'MyVal'.

// GetVal for CHAR quantities,  GET_IVAL for INT quantities.

// Expected: MyVal is __

//           ParmNum is ParamNN_

// NOTE!  when Macro's written this way, PIC compiler automatically

//        inserts RP0 and RP1 bank selection.

#ifdef _PIC

#define GETVAL( MyVal, ParmNum ) \

 asm { movf ParmNum,w } asm { movwf MyVal }

 

#define GET_IVAL( MyVal, ParmNum) \

   asm {movf ParmNum,w} \

asm {movwf MyVal} \

asm {movf ParmNum + 1,w} \

asm {movwf MyVal + 1}

#endif

 

Which you use as:

 

    increment(i);

         GETVAL (_i_main, param00_increment);

 

Note that the compiler will automatically handle RB0 and RB1 variable page selects when you use the ',w' syntax.

Note this code was in 'main', so the local var assembly name is "_i_main", and the first parameter to the function call 'increment' is "param00_increment".

Share this post


Link to post
Share on other sites

Oh, and I forgot to say, the C2C will also do SX programming.  The #define MUST be modified for the SX, as the SX does not automatically insert the proper variable 'BANK' selection values (yet).  I do have a comment in on that.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...