-3

What is the assembly syntax to compare if 2 variable are equal?

I've already tried this

but it didn't work.

Community
  • 1
  • 1
MarceloSerrao
  • 11
  • 1
  • 1

1 Answers1

0

In x86 assembly the corresponding instruction is CMPSD. In the Intel Instruction manual it is described as

OpCode bytes: A7 --- instruction: CMPSD --- Encoding:NP --- 64-bit:Valid --- 32-bit:Valid

  • For legacy mode, compare dword at address DS:(E)SI with dword at address ES:(E)DI;
  • For 64-bit mode compare dword at address (R|E)SI with dword at address (R|E)DI. The status flags are set accordingly.

CMPSD compares two memory operands and sets the status flags in EFLAGS accordingly for consumption of Jcc/CMOVcc/....

So, for comparing two DWORD/4-byte variables you setup ESI and EDI like this

lea esi, var1     ; ESI = address of var1 
lea edi, var2     ; EDI = address of var2
cmpsd             ; compare them
Jcc...            ; use (E)FLAGS

For other variable sizes like 1,2,4,8 bytes use CMPS(B,W,D,Q) respectively.

zx485
  • 28,498
  • 28
  • 50
  • 59