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
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:
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.