Returning result to eax (IA-32 Assembly language)

I'm slightly confused as to how to return a value from a method in assembly language. As far as I know, the eax register is used to hold the result that is to be returned.

As an example, say my result is 4 and I use:

mov eax, 4

I now have 4 in eax and I want to return this method. Is there anything I need to do or will the instruction ret automatically return the result?

The thing is that I don't know what's so special about register eax since when I use ret I go back to the caller, and the caller is free to access any of the registers I stored the result to, so why I couldn't just have used ebx or ecx with the result stored instead?

7
задан Mateusz Piotrowski 14 October 2015 в 21:27
поделиться