I realised that though intel chips are little endian when it comes to storing data in data segment, but same chips are big endians when it comes to store machine code in code segment. An opcode for MOV AL,57 is B057. B0 is stored in low byte and 57 is stored in next higher byte. Is it that the convention of little or big endian only applies to the data segment only?
Asked
Active
Viewed 4,776 times
0
-
Basically a duplicate of [Is emitting x86 instructions depended on Endianness?](https://stackoverflow.com/q/61503200) - and especially [How to interpret objdump disassembly output columns?](https://stackoverflow.com/q/60905135) which goes into detail about (lack of) endianness: x86 machine code is a byte stream, except for little-endian word / dword immediates. – Peter Cordes Mar 06 '21 at 03:10
2 Answers
2
endianess concern itself with how the bytes are stored to make up larger data types, such as whether the least significant byte is stored first or last in memory of e.g. a 16 bit integer.
that piece of machine code consists of several individual parts, it's not combined to be treated as an integer, so it doesn't make senese to talk about endianess there. Now, if you have an op code operating on an immediate integer that's larger than a byte, that integer will be stored in little endian though as part of the code.

Lyke
- 4,575
- 6
- 27
- 26
1
Endianness refers to representation of data types. Opcodes are not data (at least, not in this sense), so endianness is not relevant.

Oliver Charlesworth
- 267,707
- 33
- 569
- 680
-
Instructions with multi-byte immediates, like `mov eax, 12345` stores the imm32 as little-endian 4 bytes, following the opcode byte. The instruction in this question just has `opcode imm8` so there's no endianness, just a byte stream of two single byte elements, and you're right that opcodes don't have endianness, but this question is asking about whole *instructions* not just the opcode byte. – Peter Cordes Jun 14 '21 at 10:06