Multi-Byte Quantities (Endianess)

Most users of high level programming languages will not have encountered the endian issue because when they use a number, it always comes out looking the same as it went in. If they enter the number 10000 and then print it, it comes back out as 10000. Sometimes the user may dable with a debugger and still see the numbers expressed as expected (unaware that they are accutally stored in memory in reversed order). The way in which values too big to fit into an 8 bit byte are broken down and split across multiple bytes is called the byte order (often refered to the endianess of the machine).

The order in which multi-byte quantities (such as 16 bit and 32 bit words) are stored on the PIC is upto the user since the PIC CPU does not handle multi-byte quantities natively. However the XCASM compiler assumes and is restricted to little endian byte order. The user may mix and match big and little endianess within the same program BUT the compiler will only work correctly with little endianess quantities.

Endian description

BIG ENDIAN

This is where a 16, 24 or 32 bit value is stored as most significant byte first, and least significant byte last.

e.g.

the hexadecimal number 0x12345678 would be stored at memory address N as

VALUE     ADDRESS
0x12N+0
0x34N+1
0x56N+2
0x78N+3

LITTLE ENDIAN

This is where a 16, 24 or 32 bit value is stored as least significant byte first, and most significant byte last.

e.g.

the hexadecimal number 0x12345678 would be stored at memory address N as

VALUE     ADDRESS
0x78N+0
0x56N+1
0x34N+2
0x12N+3

There is a certain elegance about little endianess that has prompted the adoption of little endianess as the endianess of the compiler. Consider how 8, 16, 24 and 32 bit values overlay each other when stored at address N.

e.g.

the hexadecimal number 0x12345678 would be stored at memory address N as

little endianess overlay

BYTE
VALUE    
WORD
VALUE    
24bit
VALUE    
LONG
VALUE    
ADDRESS
0x780x780x780x78N+0
 0x560x560x56N+1
  0x340x34N+2
   0x12N+3

big endianess overlay

BYTE
VALUE    
WORD
VALUE    
24bit
VALUE    
LONG
VALUE    
ADDRESS
0x780x560x340x12N+0
 0x780x560x34N+1
  0x780x56N+2
   0x78N+3
So to calculate the address of the least significant byte of any 8, 16, 24 or 32 bit quantity stored in little endian format is the same regardless of size. Whereas it is not the same for quantities stored in big endian format. This complicates maters greatly when trying to do mixed size (8 bit / 16 bit) calculations on CPUs with limited indexing capabilities. This translates to more instructions and decreased performance.