Nasm错误:操作码和操作数的无效组合

问题描述 投票:6回答:1

在我学习NASM的过程中,我试图创建一个非常简单的程序来进行除法并输出结果。

通过书籍,一切都应该运行良好。我将15除以3,它应该自动存储在AX寄存器中,然后我转移到ecx进行输出。

但是,当我尝试编译时,我收到错误

nums.asm:6: error: invalid combination of opcode and operands
nums.asm:7: error: invalid combination of opcode and operands

有谁知道第6和第7行有什么问题吗?

这是我的代码:

segment .text

    global main
main:

    div     3, 15
    mov     ecx, ax
    mov ebx,1       ; arg1, where to write, screen
    mov eax,4       ; write sysout command to int 80 hex
    int 0x80        ; interrupt 80 hex, call kernel



exit:   mov eax, 1
    xor ebx, ebx 
    int 0x80
assembly x86 nasm cpu-registers integer-division
1个回答
14
投票

我经常看到这种形式:qazxsw poi这不是任何有效的INTEL助记符!

将15除以3:

div     3, 15

对于第二个错误,您不能将16位寄存器移动到32位寄存器中。您需要使用以下之一:

xor     edx, edx
mov     eax, 15
mov     ecx, 3
div     ecx

要么:

xor     ecx, ecx
mov     cx, ax
© www.soinside.com 2019 - 2024. All rights reserved.