NASM 说“操作码和操作数的无效组合" [英] NASM says "Invalid combination of opcode and operands"

查看:56
本文介绍了NASM 说“操作码和操作数的无效组合"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习汇编编程.我在 linux 上使用 NASM.我写了这段代码,基本上是为了计算某事物的幂,我知道它可能不是很好,但我现在真的不在乎,我想要的只是一些想法为什么我一直收到那个错误,因为我试图修改和切换操作数和操作以及问题所在部分中的所有内容,但如果有的话只会给我更多的错误消息.正如我所说,我对这一切真的非常陌生,我可能只是愚蠢.问题必须在这些行之一.如果你需要它,当然我会发布更多的代码,我只是不想让你不得不浏览 70-80 行奇怪的、不必要的复杂代码.我只是想知道发生这种情况的可能原因是什么,因为我现在真的,真的很绝望,而且我已经达到了思考它并且没有任何新想法只会让一切变得更糟的地步.我就把这部分放在这里.但我会给你任何你需要知道的帮助.

I just started learning assembly programming. I am using NASM on linux. I wrote this code that's basically meant to calculate the somethingth power of something and I know it's probably not exactly good, but I really don't care at this point, all I want is just SOME idea why I keep getting that error, because I have tried to modify and switch operands and operations and everything in the section where the problem is, but if anything that only gave me more error messages. As I said, I'm really, really new to this whole stuff and I might just be stupid. The Problem must be in one of these lines. If you need it, of course I'll post more of the code, I just don't want you to have to go though 70-80 lines of weird, unnecessarily complicated code. I just want to know what COULD be a possible reason for this happening, because I'm really, really desperate right now and also I have reached the point where thinking about it and not having any new thoughts just makes everything worse. I'll just leave this part here. But I'll give you whatever you need to know to help.

    mov dword [power], 2
    mov ecx, 0

while:
    mov eax, [neededforloop]
    cmp eax, ecx
    je endwhile

    mov eax, [power]
    mul eax, 2
    mov [power], eax

    mov eax, ecx
    add eax, 1
    mov ecx, eax

    jmp while

推荐答案

当然 nasm 已经给了你行号......应该把你指向 mul eax, 2.反过来,您应该在参考手册中查看该指令并注意到没有 mul 指令接受立即数作为操作数.imul 有这样的一个.

Surely nasm has given you the line number ... that should have pointed you at mul eax, 2. In turn, you should have then looked that instruction up in the reference manual and noticed that there is no mul instruction that accepts an immediate as an operand. There is such a one for imul though.

TL;DR: 将 mul eax, 2 更改为 imul eax, 2(实际上是 imul eax, eax, 2 的简写>).

TL;DR: change mul eax, 2 to imul eax, 2 (which is really a shorthand for imul eax, eax, 2).

PS:您应该使用移位乘以 2.

PS: You should use shifts to multiply by 2.

  • https://www.felixcloutier.com/x86/mul only has the one-operand form.
  • https://www.felixcloutier.com/x86/imul has imul r, r/m and imul r,r/m,imm forms that you can use for signed or unsigned. As well as widening one-operand signed multiply.

这篇关于NASM 说“操作码和操作数的无效组合"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆