gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:42:44 25 4
gpt4 key购买 nike

[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也设置了?

最佳答案

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

<小时/>

OS tutorial您正在查看的内容有潜在的错误。作者错误地假设在将控制权转移到引导加载程序之前,BIOS 将 ES 设置为零。这是无法保证的。您需要自己明确地将 ES 设置为零。我的Bootloader Tips涵盖这个主题:

  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您正在查看的操作系统教程代码应该是:

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

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

关于assembly - 向BX寄存器写入值对ES寄存器有影响吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55393637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com