호출 규약: cdecl, stdcall, System V
주요 x86 호출 규약을 비교하며, 어셈블리 코드와 C 코드가 인수의 위치, 스택 정리 주체, 보존할 레지스터에 대해 일치하도록 작성하는 방법을 알아봅니다.
호출 규약: cdecl, stdcall, System V은(는) CoddyKit의 무료 Assembly Language & x86 Low-Level Systems Programming 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Assembly Language & x86 Low-Level Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
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
자주 묻는 질문
“호출 규약: cdecl, stdcall, System V” 강의는 무료인가요?
네 — “호출 규약: cdecl, stdcall, System V” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Assembly Language & x86 Low-Level Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
“호출 규약: cdecl, stdcall, System V”에서 뭘 배우나요?
주요 x86 호출 규약을 비교하며, 어셈블리 코드와 C 코드가 인수의 위치, 스택 정리 주체, 보존할 레지스터에 대해 일치하도록 작성하는 방법을 알아봅니다. 브라우저에서 직접 실행하는 실습 코드로 Assembly Language & x86 Low-Level Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Assembly Language & x86 Low-Level Systems Programming을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Assembly Language & x86 Low-Level Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“호출 규약: cdecl, stdcall, System V” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Assembly Language & x86 Low-Level Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Assembly Language & x86 Low-Level Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- C에서 어셈블리 호출
- 어셈블리에서 C 호출
- 혼합 언어 프로그래밍 기법
- 호출 규약: cdecl, stdcall, System V