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

'Endianness' of multibyte variables

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



Joined: 23 Aug 2006
Posts: 19

View user's profile Send private message Send e-mail

'Endianness' of multibyte variables
PostPosted: Wed Aug 23, 2006 10:40 pm     Reply with quote

Hi,

I seems that the CCS compiler uses 'little endian' encoding of 16 and 32 bit variables, i.e. the least significant byte is stored first (at the lowest address), which Intel/Microsoft also does. Is there anyone that can confirm this ?

Best Regards,
Thomas Johansson
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 23, 2006 11:30 pm     Reply with quote

You can confirm it yourself by compiling a test program and looking
at the .LST file.

Code:
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)

//========================
void main()
{
int32 temp;

temp = 0x44332211;

while(1);   
}   


Note the 0x11 is the LSB and 0x44 is the MSB.
Code:

.................... int32 temp;
.................... temp = 0x44332211;
000C:  MOVLW  44
000D:  BCF    03.5
000E:  MOVWF  24

000F:  MOVLW  33
0010:  MOVWF  23

0011:  MOVLW  22
0012:  MOVWF  22

0013:  MOVLW  11
0014:  MOVWF  21


From the symbol table:
Code:
021-024 main.temp
thomasj50



Joined: 23 Aug 2006
Posts: 19

View user's profile Send private message Send e-mail

Endianness
PostPosted: Thu Aug 24, 2006 12:18 am     Reply with quote

Well, perhaps I could have confirmed it myself if I had understood the PIC assembler :-) I guess I am one of the few that went directly to C programming with this processor, after having spent 30 years digging trough assembler listings.

It is confirmed then ?

Best Regards.
Thomas J
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Aug 24, 2006 2:41 am     Reply with quote

Yes, confirmed. You can also check it understanding pure C only:
Code:
...
long temp;
int *ptr;

temp = 0x2211;
ptr = &temp;
if (*ptr == 0x11) printf("LSB is stored first\r\n");
...
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Tue Sep 05, 2006 8:45 pm     Reply with quote

How would you solve the problem to read little endian streams mapped to a struct?

I have some programs with hard-coded offsets and I am willing to make them more readable...

Thank you.
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