S12XDP512 more efficient between char and int

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S12XDP512 more efficient between char and int

1,880 Views
calou
Contributor III
Hello,
 
I use CW 4.5 for s12x
 
if i declare a function like it
 
void f(char i, char j)
{
 return(i+j)
}
 
and the same function like that
 
void f(int i, int j)
{
 return(i+j)
}
 
What is the best déclaration for the micro (for speed)? I don't really need 16 bit variables but i am translating old functions to a new application for 9s12x and a lot of functions are declared with int for char really needed. If i change all my declarations functions, will my program will work faster?
 
Regards 
Labels (1)
0 Kudos
3 Replies

494 Views
calou
Contributor III
Thank you for help
 
Regards
0 Kudos

494 Views
Alban
Senior Contributor II
Hello,

To know the exact speed, you need to refer to the assembly generated.
The number of instruction will depend on where your values are stored.
S12XCPUVx will give a decomposition of instructions used.

With a char (byte), values can be stored in CPU registers A and B.
But int (word), values will not fit.

As the Guru said, an int will take more memory space.
If it is practical, I advise you to .use the smallest side.
After all, an addition between two "int" can give a "long".

Cheers,
Alban.
0 Kudos

494 Views
CompilerGuru
NXP Employee
NXP Employee
I'm not sure, but my feeling is that for the HC12, using unsigned char or unsigned int wont differ a lot in speed.
Some arithmetic operations (or, and,) are faster with unsigned char's but on the other side C rules often require int arithmetic so char's may have to be explicitly zero extended in other cases.
Probably you wont see a huge difference in speed (but in memory usage :smileyhappy:

Daniel
0 Kudos