向 BX 寄存器写入值对 ES 寄存器有影响吗?

Does writing a value to the BX register have an effect on the ES register?

[org 0x7c00]
    mov bp, 0x8000 ; set the stack safely away from us
    mov sp, bp

    mov bx, 0x9000 ; es:bx = 0x0000:0x9000 = 0x09000

正如您在评论中看到的那样:es:bx = 0x0000:0x9000 = 0x09000。寄存器ESBX有关系吗?该代码仅设置寄存器 BX 但评论显示寄存器 ES is also set?

TL;DR : 设置 BX 寄存器 不影响 ES段寄存器.


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 涵盖了这个主题:

  1. 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.

您正在查看的 specific OS 教程代码应该是:

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

如果您考虑到上面引用的引导加载程序提示,那么引导加载程序的启动应该类似于:

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

引导加载程序教程中包含不准确或误导性信息的情况并不少见。