NASM says “Invalid combination of opcode and operands”

北战南征 提交于 2021-02-05 11:36:26

问题


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

回答1:


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: change mul eax, 2 to imul eax, 2 (which is really a shorthand for imul eax, eax, 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.


来源:https://stackoverflow.com/questions/30336074/nasm-says-invalid-combination-of-opcode-and-operands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!