为什么这条汇编线是“寄存器的无效使用”?

Jac*_*ert 1 x86 assembly memory-mapping

我正在阅读一些操作系统开发教程,并且经常看到以下代码段:

.intel_syntax noprefix

do_e820:
    xor ebx, ebx        # ebx must be 0 to start
    xor bp, bp      # keep an entry count in bp
    mov edx, 0x0534D4150    # Place "SMAP" into edx
    mov eax, 0xe820
    mov [es:di + 20], dword 1   # <<<this is the line I don't get
    mov ecx, 24     # ask for 24 bytes
    int 0x15
    jc short .failed    # carry set on first call means "unsupported function"
    mov edx, 0x0534D4150    # Some BIOSes apparently trash this register?
    cmp eax, edx        # on success, eax must have been reset to "SMAP"
    jne short .failed
    test ebx, ebx       # ebx = 0 implies list is only 1 entry long (worthless)
    je short .failed
    jmp short .jmpin
Run Code Online (Sandbox Code Playgroud)

当我尝试为我自己的内核组装它Error: invalid use of register时,汇编器在我标记的行中抱怨。如果它有助于理解情况,我正在使用 gcc i686-elf 交叉汇编程序。

usr*_*301 5

在 32 位代码中使用 16 位寄存器表明这是一段古老的“魔法”代码,在可怕的仪式中从父亲传给儿子。在那段时间里,汇编器支持的语法发生了变化,因此您正在使用的现代汇编器不再接受这条曾经完全有效的行。

这条线

mov [es:di + 20], dword 1
Run Code Online (Sandbox Code Playgroud)

更常写为

mov dword ptr es:[di + 20], 1
Run Code Online (Sandbox Code Playgroud)

这是英特尔在其手册中使用的符号。