Help translating from assembly to C

I have a code from a function

subl $24, %esp
movl 8(%ebp), %eax
cmpl 12(%ebp), %eax

Before the code is just an 'ENTER' command, then an if statement will appear to return 1 if ebp> eax or 0 if it is less. I assume cmpl means comparison, but I cannot say what the specific values ​​are. Can someone tell me what is going on?

+3
source share
3 answers

Yes cmplmeans comparison (with 4-byte arguments). Suppose a piece of code is followed by jg <addr>:

movl 8(%ebp), %eax
cmpl 12(%ebp), %eax
jg <addr>

Then the code is like

eax = ebp[8];
if (eax > ebp[12])
   goto <addr>;
+18
source

, . - , .

, , . . EBP ESP, ( ).

, ( ), . , :

movl 8(%ebp), %eax

8- EAX, 8 ( , EBP ).

:

subl $24, %esp

, 24 . . . .

: :

void Unknown_Function(long param1, long param2, long param3)
{
  unsigned int local_variable_1;
  unsigned int local_variable_2;
  unsigned int local_variable_3;

  if (local_variable_2 < local_variable_3)
  {
   //...
  }
}

, .

+2

(EBP + 8) (EBP + 12). cmpl , .

On Mac OS X 32, ABI EBP + 8 is the first parameter of the function, and EBP + 12 is the second parameter.

0
source

Source: https://habr.com/ru/post/1744278/


All Articles