开发者

How's return value implemented in assembly level?

开发者 https://www.devze.com 2023-01-18 21:31 出处:网络
int main(void){ printf(\"Hello World\"); return 0; } How is 0 passed as return value in assembly level?开发者_StackOverflow社区 Is there a dedicated CPU register for this job?
int main(void){

printf("Hello World");

return 0;

}

How is 0 passed as return value in assembly level?开发者_StackOverflow社区 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:

How's return value implemented in assembly level?

How's return value implemented in assembly level?


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.


That's part of the application binary interface.

These days the return value and function parameters usually are passed in registers, because that is the most efficient option. Only if that gets too big for the available registers the stack is used.

0

精彩评论

暂无评论...
验证码 换一张
取 消