As I was studying the BIOS and booting I found that 0xaa55 is used as a signature to check whether the 512-byte boot sector is corrupted or not. Now In some cases, it is mentioned as 0xaa55 and in some 0x55aa. I am confused. I also think it is because of the endianness of the CPU. But shouldn't the endianness should be of the word. Hence either 0000aa55 or 55aa0000 (assuming a 32 bit word). Or is it that inherently the boot sector has 16-bit words?
CodePudding user response:
Historically, that functionality of the PC BIOS predates 32-bit x86 CPUs and the boot process as we know it dates back to the 16-bit 8086. Some elements may be older than that, but that's a bit before my time.
You're right that the confusion is endian related. The last byte of the 512-byte boot sector is aa
and the byte before it is 55
. So it's common to refer to the signature as 55aa
as that's the order it appears byte-wise in the boot sector. It's also the order it appears in memory as individual bytes - when the boot sector is loaded at 0000:7c00
, the byte at 7dff
is aa
.
However, when expressed as a 16-bit word on the little-endian x86, it's aa55
. Because of that ordering, it's common to put the end-of-block signature in an assembly file like this:
.word 0xaa55 # this is AT&T syntax
because it's simpler than two .byte
directives, which would be in reverse order:
.byte 0x55
.byte 0xaa
so people sometimes refer to the signature in that manner.