简体   繁体   中英

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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