呼び出し規約:cdecl、stdcall、System V
主要なx86呼び出し規約を比較し、引数の配置場所、スタックを解放する側、保持されるレジスタについてアセンブリとCのコードで認識を合わせる方法を学びます。
「呼び出し規約:cdecl、stdcall、System V」はCoddyKit上の無料Assembly Language & x86 Low-Level Systems Programmingレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応の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時間対応のAIチューター)、Assembly Language & x86 Low-Level Systems Programmingコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Assembly Language & x86 Low-Level Systems Programmingコースには全4レッスンが含まれています。
「呼び出し規約:cdecl、stdcall、System V」で何を学びますか?
主要なx86呼び出し規約を比較し、引数の配置場所、スタックを解放する側、保持されるレジスタについてアセンブリとCのコードで認識を合わせる方法を学びます。 ブラウザで直接実行するハンズオンコードでAssembly Language & x86 Low-Level Systems Programmingを演習し、24時間対応の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