Thomas Bunny
Thomas Bunny

Reputation: 11

How to compare two addresses in x86 assembly?

I am trying to do some byte injection in a program to perform a specific task when ecx+5C is equal to a specific address which I supply an immediate value for. I'm trying to do something like the following: cmp [ecx+5C], 1D59D3BC. However I get an error. Does anyone know how I could compare a register+offset address to an immediate address in x86 assembly?

Upvotes: 1

Views: 4924

Answers (1)

Fifoernik
Fifoernik

Reputation: 9899

I'm trying to do something like the following: cmp [ecx+5C], 1D59D3BC.
However I get an error.

Possible causes why this will fail:

  • You need to specify an hex prefix or suffix for the assembler to accept your instruction.
  • You need to specify the size of the operation. The assembler doesn't guess for you.

Try any of the following (depends on your assembler):

cmp dword ptr [ecx + 5Ch], 1D59D3BCh
cmp dword ptr [ecx + 0x5C], 0x1D59D3BC
cmp dword [ecx + 5Ch], 1D59D3BCh
cmp dword [ecx + 0x5C], 0x1D59D3BC

Does anyone know how I could compare a register+offset address to an immediate address in x86 assembly?

lea eax, [ecx + 5Ch]   ;put the address in EAX
cmp eax, 1D59D3BCh   ;compare with the immediate

But shorter as PaulH showed in a comment:

cmp ecx, 1D59D3BCh - 0000005Ch

Upvotes: 4

Related Questions