Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What registers does strcmp evaluate? x86 Assembly

Tags:

x86

assembly

It seems like this is common knowledge, but I can't find it written on the internet (yet).

When a program has

call <JMP.&msvcrt.strcmp>

what values are compared? I'm unsure because with cmp it's stated (cmp eax, ebp).

I know the result of the comparison is returned in the EAX register if that helps.

like image 299
user2059300 Avatar asked Oct 14 '25 09:10

user2059300


1 Answers

You are trying to associate strcmp with the assembly instruction cmp. But they are different things. In the processor level (assembly), the cmp A, B compares 2 different registers, for example, and set the result in some flags. Flags are bits that can be tested by other instructions (like jz, jnz) and then redirect the flow according to the desired intention.

When you do a call strcmp you are actually calling a "high level function" (high level, when compared to assembly) that will perform a lot of stuff to compare 2 C-Style strings. It's not easy to know which registers will be used (many of them will be used probably), once each compiler/platform will give a different result of machine instructions.

And if you understand this, you will see that it doesn't matter in fact, because the paradigm is a little different:

  • cmp is an assembly instruction.
  • strcmp is not an assembly instruction, but a function.
like image 170
Wagner Patriota Avatar answered Oct 19 '25 09:10

Wagner Patriota



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!