Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How's return value implemented in assembly level?

int main(void){

printf("Hello World");

return 0;

}

How is 0 passed as return value in assembly level? Is there a dedicated CPU register for this job?

UPDATE

Here's the 2 tables on passing/return data in the pdf, but doesn't seems to have the exact info on how the calling convention of an API is determined and which register is used for storing return address:

alt text

alt text

like image 829
Alan Avatar asked Oct 07 '10 07:10

Alan


1 Answers

That depends on the architecture. Just for a couple of examples, on x86 the EAX register is normally used for return values. On x86-64, it's RAX. On SPARC, it'll normally show up in %o0.

like image 77
Jerry Coffin Avatar answered Oct 12 '22 09:10

Jerry Coffin