Understanding register usage in the switch condition

前端 未结 1 918
一生所求
一生所求 2021-01-26 09:31

I have a switch-condition code in C and assembly code. But it seems very arbitrary to me what to set, edx or eax or ecx?

How do I tell the difference between edx, epx, e

1条回答
  •  无人及你
    2021-01-26 09:40

    In most assembly code, whatever is in %eax is the value returned from the function. That is why in the .L19 block whatever was in %edx is moved into %eax. Looking back, wherever you set result to something, the code moves that value into %edx so that when the code jumps to .L19 the value will be placed in %eax by default.
    This looks like a 32-bit system, so it has 8 general-purpose registers:

    • %ebx, %ecx, %edx, %esi, and %edi are registers that mostly store whatever data is necessary for them to hold at any given time.
    • %eax holds the return value for a function, e.g. the function that called it will be looking in %eax for that function's return value before it changes %eax.
    • %ebp and %esp are special registers that essentially manage and allocate space on the stack for various function calls.

    To see where your arguments are being placed, look at where that data is being referenced in the code. For example, at .L13, the program places %ebp+8 (which is p1) into %eax, then places the value at that address (*p1) into %edx. So, %edx now holds the value pointed to by p1.

    The registers DO NOT hold the arguments to the function. Don't think that %edx contains one of the arguments to switchmode() by default. Arguments are always placed on the stack.

    0 讨论(0)
提交回复
热议问题