I've tried looking online, but I still haven't quite figured it out - does a number, for example 0x100 saved in a register by some convention like little/big endian like thigs are saved in memory or maybe it is just casting every digit into 4 bytes from lsb to msb? e.g. if I'm writing the following line in assembly:

movq $0x100, %rax

will rax look like this: msb 00000000 00000000 00000001 00000000 lsb

or perhaps something else by little-endian convention or something like that?

thank you for your help

  • 2
    \$\begingroup\$ Little endian and big endian have only to do with how numbers are stored in memory. In registers the numbers can be stored arbitrarily. \$\endgroup\$ – Oldfart Nov 29 '19 at 13:56
  • 2
    \$\begingroup\$ I think its irrelevant because there is no addressing of bytes within a register. \$\endgroup\$ – Meenie Leis Nov 29 '19 at 14:03
  • 1
    \$\begingroup\$ In assembly language you should express immediate values so that they make sense... there's no need for the mental gymnastics of byte re-ordering... the assembler, the instruction set architecture, and the concrete implementation of the central processing unit should conspire to ensure the correct bits end up in the right locations when the instructions are executed \$\endgroup\$ – vicatcu Nov 29 '19 at 19:25

Registers don't have endianness. Endianness is only relevant when data is stored in memory.

The reason endianness is relevant to memory is because you can access the individual bytes of memory, using an address. You generally can't access the individual bytes of a register, and when you can, they have names (like %al is "the lowest byte of %rax") which mean the same thing regardless of endianness.

If you couldn't access individual bytes from memory, or if you used a command like "get me the lowest byte of address 5" instead of "get me address 20", then endianness wouldn't matter for memory either.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.