Ryan Brown
Ryan Brown

Reputation: 1085

x64 assembly functions (call/return vs push/pop/jump)

Whats the difference between using the built-in call and return instructions vs manually pushing and popping the stack and using jumps for functions?

Upvotes: 1

Views: 1111

Answers (1)

Jester
Jester

Reputation: 58762

Functionally, if you do it correctly, nothing. However it takes more instructions and/or registers to emulate call/ret using push/pop. Of course if you really wanted to take it to the extreme, you could also emulate push/pop using lea and mov :)

Also, current processors have specialized hardware to handle function calls for the purposes of branch prediction, which probably won't work for your alternate sequence so you will get performance penalty.

Upvotes: 3

Related Questions