What registers does strcmp evaluate? x86 Assembly

10,927

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.
Share:
10,927
user2059300
Author by

user2059300

Updated on July 05, 2022

Comments

  • user2059300
    user2059300 almost 2 years

    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.