2

I'm new into using the MSP430 with Code composer and i was doing a lab assignment where i had simple instructions coded in.

I ran this instruction:

mov.w #'ABC', R9

in result, I obtain a #0x4241 in R9.

i understand that the above in quote 'ABC' are ASCII string and when converted, A= 41 B= 42 C=43 and that C is kicked out as only a word is stored, so A and B is stored.

What I don't understand is:
why is it 4241 instead of 4142?
Since A is 41 and B is 42?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Nicholas
  • 21
  • 2
  • 1
    I think this is something to do with Endianness and the MSP430 will use Little Endian, a quick google confirms that is the case. Endianness affects which order bytes are stored. This can be quite important if you are for example Bit Banging the Exif information out of a Jpeg file, you need to make sure you read the bytes in the correct order. – Matt Oct 04 '18 at 13:38

1 Answers1

3

In a word : endianness

Your word is being stored Lest Significant Byte first : 0x4241.

On a "big Endian" machine, it would be stored as 0x4142.

Endianness refers to the sequential order in which bytes are arranged into larger numerical values when stored in memory or when transmitted over digital links. Endianness is of interest in computer science because two conflicting and incompatible formats are in common use: words may be represented in big-endian or little-endian format, depending on whether bits or bytes or other components are ordered from the big end (most significant bit) or the little end (least significant bit).

In big-endian format, whenever addressing memory or sending/storing words bytewise, the most significant byte—the byte containing the most significant bit—is stored first (has the lowest address) or sent first, then the following bytes are stored or sent in decreasing significance order, with the least significant byte—the one containing the least significant bit—stored last (having the highest address) or sent last.

Little-endian format reverses this order: the sequence addresses/sends/stores the least significant byte first (lowest address) and the most significant byte last (highest address). Most computer systems prefer a single format for all its data; using the system's native format is automatic. But when reading memory or receiving transmitted data from a different computer system, it is often required to process and translate data between the preferred native endianness format to the opposite format.

enter image description here

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551