Endianness inside CPU registers

后端 未结 4 1881
暗喜
暗喜 2020-12-08 05:56

I need help understanding endianness inside CPU registers of x86 processors. I wrote this small assembly program:

section .data
section .bss

section .text
          


        
4条回答
  •  长情又很酷
    2020-12-08 06:28

    Endianness makes sense only for memory, where each byte have a numeric address. When MSByte of a value is put in higher memory address than the LSByte, it's called Littte endian, and this is the endianness of any x86 processor.

    While for integers the distinction between LSByte and MSByte is clear:

        0x12345678
    MSB---^^    ^^---LSB
    

    It's not defined for string literals! It's not obvious what part of the WXYZ should be considered LSB or MSB:

    1) The most obvious way,

    'WXYZ' ->  0x5758595A
    

    would lead to memory order ZYXW.

    2) The not not so obvious way, when the memory order should match the order of literals:

    'WXYZ' ->  0x5A595857
    

    The assembler have to choose one of them, and apparently it chooses the second.

提交回复
热议问题