Byte-order
The AVR uses the little endian Byte-order, e.g. the lower byte is located at the lower memory address. A 32 Bit value(4 Bytes) has this order in memory:
Memory → | |||
---|---|---|---|
&h00 | &h01 | &h02 | &h03 |
byte0 | byte1 | byte2 | byte3 |
Important Note
As constants in the source code hexadecimal or dual (binary) written values are always in Big-endian notation (they are then better readable for humans). Eg if you wrote the word „MOON“ in wrong notation, then the bytes are stored in reverse (wrong) order in memory:
Written: 0x4c4f4f41 (wrong) | |||
---|---|---|---|
0x4d | 0x4f | 0x4f | 0x4e |
„M“ | „O“ | „O“ | „N“ |
Written: 0x414f4f4e (correct) | |||
0x4d | 0x4f | 0x4f | 0x4e |
„N“ | „O“ | „O“ | „M“ |
Memory → | |||
0x00 | 0x01 | 0x02 | 0x03 |
0x4e | 0x4f | 0x4f | 0x4d |
„M“ | „O“ | „O“ | „N“ |
The Little-endian Byte-order has some advantages for the AVR controller. Only two zeros have to be added to convert a 2 Byte number into a 4 Byte number, without modifiying the memory address. With Big-endian Byte-order; the memory address must be moved by 2. See also: Byte-order (Wikipedia)