0x0000000000400507 <main+28>: 74 0c je 0x400515 <main+42>
0x0000000000400509 <main+30>: bf 28 06 40 00 mov $0x400628,%edi
..
0x400507 <main+28>: 0x28bf0c74
I think shows the machine code is big-endian. Is my conclusion right?
0x0000000000400507 <main+28>: 74 0c je 0x400515 <main+42>
0x0000000000400509 <main+30>: bf 28 06 40 00 mov $0x400628,%edi
..
0x400507 <main+28>: 0x28bf0c74
I think shows the machine code is big-endian. Is my conclusion right?
No, Intel CPUs are little endian: http://en.wikipedia.org/wiki/Endianness
First, you need to know that the smallest data unit that nearly all modern CPUs can manipulate is a byte, which is 8 bits. For numbers, we (human beings) write and read from left to right and we write the most significant digit first, so the most significant digit is on the left.
Little-endian byte order implies two things for the CPU:
Suppose that the CPU fetches 4 bytes from the memory, e.g. starting at address 0x00
, and that:
0x00
holds the byte 11111111
, which is 0xFF
;0x01
holds the byte 00111100
, which is 0x3C
;0x02
holds the byte 00011000
, which is 0x18
;0x03
holds the byte 00000000
, which is 0x00
.Then, when the CPU interprets these 4 bytes as an integer, it will interpret them as the integer value 0x00183CFF
. That is, the CPU will consider the byte at the highest address as the Most Significant Byte (MSB). That means, for the CPU, the higher the address is, the more significant the byte on that address is.
memory address: 0x00 0x01 0x02 0x03
binary value at address: 11111111 00111100 00011000 00000000
equivalent value in hex: = 0xFF = 0x3C = 0x18 = 0x00
0x00183CFF
to the memory. It will put 0xFF
at the lowest address, and 0x00
at the highest address. If you (human being) read bytes intuitively from low addresses to high addresses, you read out FF 3C 18 00
, which byte-for-byte is in the reverse order to how 0x00183CFF
is written.For BIG-endianness, the CPU reads and writes MSBs at lower addresses and LSBs at higher addresses.
© 2022 - 2024 — McMap. All rights reserved.