2021年5月5日星期三

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

I am new to assembly programming. I wrote a small program to add two numbers.

; 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    

My question is why does this program fails to compile with the following error:

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  

As far as I understand r8d, r9d and eax are all 32 bit registers and not preserved.
https://www.cs.uaf.edu/2017/fall/cs301/reference/x86_64.html
Subroutine iprintLF (written in libasm/numbers.asm and works fine) is used to print integer stored in eax. I am using Ubuntu in WSL

Distributor ID: Ubuntu  Description:    Ubuntu 20.04.2 LTS  Release:        20.04  Codename:       focal  

and my nasm version is

NASM version 2.14.02  
https://stackoverflow.com/questions/67411137/nasm-error-invalid-operands-in-non-64-bit-mode May 06, 2021 at 10:41AM

没有评论:

发表评论