user4407915
user4407915

Reputation:

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?

Upvotes: 0

Views: 11724

Answers (3)

rcgldr
rcgldr

Reputation: 28818

You can compare a single immediate value with a register or with a value in memory.

Upvotes: 0

AmirSojoodi
AmirSojoodi

Reputation: 1340

In x86 assembly according to your assembler(e.g 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.

Upvotes: 8

Ondrej Tucny
Ondrej Tucny

Reputation: 27962

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.

Upvotes: 0

Related Questions