简体   繁体   English

我可以在装配体中比较(CMP)立即值吗?

[英]Can I compare (CMP) immediate values in Assembly?

I tried to assemble the following instruction: 我尝试汇编以下指令:

cmp 5, 6

But I got the following error: 但我收到以下错误:

invalid combination of opcode and operands

So I edited the previous instruction into this: 因此,我将前面的指令编辑为:

cmp DWORD 5, DWORD 6

But still I got the same error, so is comparing immediate values illegal in Assembly? 但是我仍然遇到相同的错误,所以在汇编中比较立即值是非法的吗?

In x86 assembly according to your assembler(eg tasm, masm or nasm ) you cannot compare immediates or variables with each other. 在根据汇编器的x86汇编中(例如tasm,masm或nasm ),您不能将立即数或变量彼此进行比较。 You have to put one or both of them in a register. 您必须将其中一个或两个都放入寄存器中。 like this: 像这样:

mov ax, 5
cmp ax, 6

or 要么

mov ax, 5
mov bx, 6
cmp ax, bx

There you go. 妳去

No, this is not possible. 不,这是不可能的。 The x86 instruction set doesn't have opcodes for such operations on immediate values and assembly compilers aren't here to interpret them. x86指令集没有针对立即数的此类操作的操作码,并且汇编编译器也无法在此处解释它们。

您可以将单个立即数与寄存器或内存中的值进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM