[org 0x7c00]
mov bp, 0x8000 ; set the stack safely away from us
mov sp, bp
mov bx, 0x9000 ; es:bx = 0x0000:0x9000 = 0x09000
As you can see in the comment it says: es:bx = 0x0000:0x9000 = 0x09000
. Is there any relationship between register ES and BX? The code only sets register BX but the comment shows register ES is also set?
TL;DR : Setting the BX register doesn't affect the ES segment register.
The OS tutorial you are looking at has potential bugs. The author incorrectly assumes that ES is set to zero by the BIOS prior to transferring control to the bootloader. This isn't guaranteed. You need to explicitly set ES to zero yourself. My Bootloader Tips covers this topic:
- When the BIOS jumps to your code you can't rely on CS,DS,ES,SS,SP registers having valid or expected values. They should be set up appropriately when your bootloader starts. You can only be guaranteed that your bootloader will be loaded and run from physical address 0x00007c00 and that the boot drive number is loaded into the DL register.
The specific OS tutorial code you are looking at should have been:
xor ax, ax ; AX=0 (XOR register to itself clears all bits)
mov es, ax ; ES=0
mov bx, 0x9000 ; ES:BX = 0x0000:0x9000 = 0x09000 . Memory location disk read will read to
If you take into account the quoted bootloader tip above, then the start of the bootloader should have looked something like:
mov bp, 0x8000
xor ax, ax ; AX=0 (XOR register to itself clears all bits)
mov es, ax ; ES=0
mov ds, ax ; DS=0
mov ss, ax ; SS=0
mov sp, bp ; SP=0x8000 (SS:SP = stack pointer)
mov bx, 0x9000 ; ES:BX = 0x0000:0x9000 = 0x09000 . Memory location disk read will read to
It is not uncommon for bootloader tutorials to have inaccurate or misleading information.