Understanding cmp in assembly

wundermahn

I am looking at an assembly code that looks like the following:

cmp dword [rbp-0x4 {var_c}], 0x0
jne 0x12c0

To me, that reads:

Compare the value of something and null, and if there is no error (i.e. they match), jump to 0x12c0.

Is that correct? I don't understand what [rbp-0x4 {var_c}] is or why we would be comparing that to null.

I did try and follow a graph to learn what these variables were and I got the following:

  • 0x4 = uint8_t file_class = 0x2
  • var_c = In Set of Values {0, 1}
  • rbp seems to be what is pushed in from main

Any help on understanding this would be appreciated. I am looking for clarification on what is being compared in the cmp statement.

paxdiablo

Not quite, it's more:

Compare the value of something with zero and, if they are not equal, jump.

Assembly language has no concept of "null" and a cmp is generally the same as a sub (subtract) but without actually changing the value. Basically, it's:

Set the flags as if I had subtracted zero from something.

In more pseudo-code fashion, your two instructions amount to:

if var_c <> 0 then goto label_12c0

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related