NASM error: invalid operands in non-64-bit mode

NASM error: invalid operands in non-64-bit mode

我是汇编编程的新手。我写了一个小程序来添加两个数字。

; A test program

%include    'libasm/system.asm'
%include    'libasm/numbers.asm'
%include    'libasm/string.asm'

SECTION     .text
global      _start
_start:
    mov     r8d,    12    ;First number
    mov     r9d,    15    ;Second number
    add     r8d,    r9d   ;Adding two numbers and storing result in r8d
    mov     eax,    r8d   ;Moving the result in eax so that it can be printed
                          ;with iprintLF 
    call    iprintLF      ;Displaying the result
    call    quit          ;Exiting the program

我的问题是为什么这个程序编译失败并出现以下错误:

nasm -f elf test.asm
test.asm:10: error: invalid operands in non-64-bit mode
test.asm:11: error: invalid operands in non-64-bit mode
test.asm:12: error: invalid operands in non-64-bit mode
test.asm:13: error: invalid operands in non-64-bit mode

据我了解r8d、r9d、eax都是32位寄存器,没有保留。
https://www.cs.uaf.edu/2017/fall/cs301/reference/x86_64.html
子程序 iprintLF(写在 libasm/numbers.asm 中并且工作正常)用于打印存储在 eax 中的整数。 我在 WSL

中使用 Ubuntu
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal

我的 nasm 版本是

NASM version 2.14.02

As far as I understand r8d, r9d and eax are all 32 bit registers and not preserved.

是的,但您不能在非 64 位模式下使用 r?d 寄存器。因为在32位模式下,只有8个通用寄存器:eaxebxecxedxediesi, ebp, esp。 x86-64专门新增了8个64位寄存器r8-r15,其低32位为r8d-r15d