【问题标题】:Nasm Error: invalid combination of opcode and operandsNasm 错误:操作码和操作数的组合无效
【发布时间】:2013-02-14 00:33:15
【问题描述】:

在学习 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】:

    我经常看到这个表格:div 3, 15这不是任何有效的 INTEL 助记符!

    将 15 除以 3:

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

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

    xor     ecx, ecx
    mov     cx, ax
    

    或者:

    movzx   ecx, ax
    

    【讨论】:

    • 你能把 32 位寄存器移到 16 位吗?
    • 你能在 1/2 加仑的水壶里放 1 加仑的水吗?
    • 其中一些...这就是我正在使用的逻辑,因为我挠头想知道为什么不能将 16 位寄存器放入 32 位寄存器中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多