0Pricing
Assembly Language & x86 Low-Level Systems Programming · Lesson

Calling Conventions: cdecl, stdcall, and System V

Compare the major x86 calling conventions so your assembly and C code agree on where arguments go, who cleans the stack, and which registers are preserved.

Calling Conventions: cdecl, stdcall, and System V is a free Assembly Language & x86 Low-Level Systems Programming lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Assembly Language & x86 Low-Level Systems Programming learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Conventions Matter

For assembly and C to interoperate, both sides must agree on a calling convention: how arguments are passed, who cleans the stack, and which registers must be preserved.

Argument Passing

Conventions differ on where arguments go: on the stack, in registers, or a mix. Getting this wrong corrupts data silently.

cdecl

cdecl (32-bit, the C default) pushes arguments on the stack right to left, and the caller cleans them up after the call.

push arg2
push arg1
call func
add esp, 8     ; caller cleans

stdcall

stdcall also passes on the stack right to left, but the callee cleans the stack via ret n. The Win32 API uses it.

ret 8          ; callee cleans 8 bytes

Caller vs Callee Cleanup

The key contrast:

  • cdecl: caller cleans, supports variadic functions
  • stdcall: callee cleans, smaller call sites

System V AMD64

The 64-bit Linux/macOS convention passes the first six integer args in registers: RDI, RSI, RDX, RCX, R8, R9; extras go on the stack.

mov rdi, arg1
mov rsi, arg2
call func

Microsoft x64

64-bit Windows uses a different register set: RCX, RDX, R8, R9 for the first four args, plus 32 bytes of shadow space.

Return Values

Integer and pointer results come back in EAX (32-bit) or RAX (64-bit); floating point uses XMM0 in 64-bit conventions.

Preserved vs Scratch Registers

Each convention designates callee-saved registers (the callee must restore them) and caller-saved ones (free to clobber). Violating this corrupts the caller.

Stack Alignment

System V requires the stack to be 16-byte aligned at a call. Forgetting this crashes code that uses SSE instructions.

Matching the Compiler

Always declare functions on the C side with the matching convention attribute (e.g. __stdcall) so both halves agree.

Quick Check

Test your understanding of calling conventions.

Recap

You learned calling conventions:

  • cdecl: stack args, caller cleans, supports varargs
  • stdcall: stack args, callee cleans
  • System V x64: args in RDI,RSI,RDX,RCX,R8,R9
  • Return in EAX/RAX; respect callee-saved registers and alignment

Frequently asked questions

Is the “Calling Conventions: cdecl, stdcall, and System V” lesson free?

Yes — the full text of “Calling Conventions: cdecl, stdcall, and System V” is free to read here on the web, and the Assembly Language & x86 Low-Level Systems Programming course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Assembly Language & x86 Low-Level Systems Programming course, upgrade to CoddyKit PRO.

What will I learn in “Calling Conventions: cdecl, stdcall, and System V”?

Compare the major x86 calling conventions so your assembly and C code agree on where arguments go, who cleans the stack, and which registers are preserved. You practise Assembly Language & x86 Low-Level Systems Programming with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Assembly Language & x86 Low-Level Systems Programming?

No prior experience is required. Assembly Language & x86 Low-Level Systems Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Calling Conventions: cdecl, stdcall, and System V” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Assembly Language & x86 Low-Level Systems Programming lesson?

Yes. Every Assembly Language & x86 Low-Level Systems Programming lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Calling Assembly from C
  2. Calling C from Assembly
  3. Mixed-Language Programming Techniques
  4. Calling Conventions: cdecl, stdcall, and System V
← Back to Assembly Language & x86 Low-Level Systems Programming