Convenciones de llamada: cdecl, stdcall y System V
Compare las principales convenciones de llamada de x86 para que su código de ensamblador y C coincida en la ubicación de los argumentos, quién limpia la pila y qué registros se conservan.
Convenciones de llamada: cdecl, stdcall y System V es una lección gratuita de Assembly Language & x86 Low-Level Systems Programming en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Assembly Language & x86 Low-Level Systems Programming, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Assembly Language & x86 Low-Level Systems Programming incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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 cleansstdcall
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 bytesCaller 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 funcMicrosoft 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
Preguntas frecuentes
¿La lección «Convenciones de llamada: cdecl, stdcall y System V» es gratis?
Sí — el texto completo de «Convenciones de llamada: cdecl, stdcall y System V» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Assembly Language & x86 Low-Level Systems Programming, actualiza a CoddyKit PRO. El curso de Assembly Language & x86 Low-Level Systems Programming incluye 4 lecciones en total.
¿Qué aprenderé en «Convenciones de llamada: cdecl, stdcall y System V»?
Compare las principales convenciones de llamada de x86 para que su código de ensamblador y C coincida en la ubicación de los argumentos, quién limpia la pila y qué registros se conservan. Practicas Assembly Language & x86 Low-Level Systems Programming con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Assembly Language & x86 Low-Level Systems Programming?
No se requiere experiencia previa. Assembly Language & x86 Low-Level Systems Programming en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Convenciones de llamada: cdecl, stdcall y System V»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Assembly Language & x86 Low-Level Systems Programming?
Sí. Cada lección de Assembly Language & x86 Low-Level Systems Programming incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Llamar a ensamblador desde C
- Llamar a C desde ensamblador
- Técnicas de programación en varios lenguajes
- Convenciones de llamada: cdecl, stdcall y System V