View previous topic :: View next topic |
Author |
Message |
thomasj50
Joined: 23 Aug 2006 Posts: 19
|
'Endianness' of multibyte variables |
Posted: Wed Aug 23, 2006 10:40 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 23, 2006 11:30 pm |
|
|
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:
|
|
![](templates/subSilver/images/spacer.gif) |
thomasj50
Joined: 23 Aug 2006 Posts: 19
|
Endianness |
Posted: Thu Aug 24, 2006 12:18 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Thu Aug 24, 2006 2:41 am |
|
|
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");
...
|
|
|
![](templates/subSilver/images/spacer.gif) |
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Tue Sep 05, 2006 8:45 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|