اتفاقيات الاستدعاء: cdecl وstdcall وSystem V
قارن بين أهم اتفاقيات الاستدعاء في x86 لضمان توافق كود التجميع وC في مواضع المعاملات، والجهة التي تنظف المكدس، والسجلات التي يجب الحفاظ عليها.
اتفاقيات الاستدعاء: cdecl وstdcall وSystem V درس مجاني في Assembly Language & x86 Low-Level Systems Programming على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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) وفتح باقي دورة 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/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Assembly Language & x86 Low-Level Systems Programming؟
لا تُشترط خبرة سابقة. Assembly Language & x86 Low-Level Systems Programming على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «اتفاقيات الاستدعاء: cdecl وstdcall وSystem V»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Assembly Language & x86 Low-Level Systems Programming هذا؟
نعم. كل درس في Assembly Language & x86 Low-Level Systems Programming يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- استدعاء لغة التجميع من C
- استدعاء C من لغة التجميع
- تقنيات البرمجة متعددة اللغات
- اتفاقيات الاستدعاء: cdecl وstdcall وSystem V