Core · Module 7 · Lesson 1 of 4
How a function call works
A call is a jump that remembers where to come back to. Arguments travel in registers, the return address goes on the stack, and a few instructions set up and tear down the frame.
By the end you can
- Describe what a calling convention specifies: where arguments, return values and saved registers go
- Trace the instructions of a call and return, and what each one does to the stack
- Estimate the cost of a call, and explain how inlining removes it
Builds on The call stack is a stack.
01 · A question first
A function call is one line of code. Underneath, the processor stores where it was, passes the arguments, sets up space for the function's variables, and later undoes all of it. How much does that cost, and why do compilers often make the call disappear entirely?
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- A jump that remembers
- What a calling convention specifies
- The call, step by step
- Frames, locals and the frame pointer
- What a call costs
- Inlining
- Why this module starts here
- Pseudocode & Multi-Language Implementations (C++, Java, Python)
03 · Practice
Something wrong with this lesson? Report a problem