Mehmet Fide

Ohh no, big-endian :-(

Discussion created by Mehmet Fide on Jan 2, 2007
Latest reply on Jan 3, 2007 by bigmac
Hi,
 
I'm porting my fully ansi-c compatible Microchip PIC project to HCS08. I need to convert some structs to little endian. I don't like this at all.
 
Can we say 8 bit MCUs such as HCS08s are little-endian or big-endian? They are just 8 bit. How can we talk about endianizm for them?
 
I'm using Hitech PICC18 that is little endian compiler for PIC. But CodeWarrior generates big-endian code for HCS08. Can't CW support little endian code generation for HCS08 family?
 
I have found some conversion functions on the google such as below. I wonder if 32 bit double type conversion is same with long? And I couldn't find anything about array conversion. I need to convert a struct such as
typedef struct
{
 unsigned long  A;
 unsigned int   B;
 unsigned char  C[3];
 double         D[3];
 unsigned char  E;
} TFoo;
 
////////////////////////////////
short convert_short(short in)
{
 short out;
 char *p_in = (char *) ∈
 char *p_out = (char *) &out;
 p_out[0] = p_in[1];
 p_out[1] = p_in[0]; 
 return out;
}

long convert_long(long in)
{
 long out;
 char *p_in = (char *) ∈
 char *p_out = (char *) &out;
 p_out[0] = p_in[3];
 p_out[1] = p_in[2];
 p_out[2] = p_in[1];
 p_out[3] = p_in[0]; 
 return out;
}
////////////////////////////////
 
Regards.

Outcomes