إطارات المكدس والمتغيرات المحلية
أنشئ إطارات المكدس وأزلها باستخدام مؤشّر الأساس (EBP/RBP) لتخصيص المتغيرات المحلية والوصول إلى المعاملات reliably داخل الإجراءات.
إطارات المكدس والمتغيرات المحلية درس مجاني في 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 Stack Frames?
A procedure needs space for its own local variables and a stable way to find its parameters. A stack frame gives each call its own private region of the stack.
The Base Pointer
The base pointer (EBP in 32-bit, RBP in 64-bit) provides a fixed reference into the frame, while ESP keeps moving as you push and pop.
The Prologue
A procedure begins by saving the old base pointer and setting up a new frame.
push ebp
mov ebp, espAllocating Locals
Reserve space for locals by subtracting from the stack pointer. The locals then live at negative offsets from EBP.
sub esp, 8 ; room for two 4-byte localsAccessing Locals
Reference each local by a fixed offset below the base pointer.
mov dword [ebp-4], 10 ; first local = 10Accessing Parameters
With the classic cdecl layout, parameters sit above the saved EBP and return address, at positive offsets.
mov eax, [ebp+8] ; first argumentThe Epilogue
Before returning, restore the stack and base pointer so the caller frame is intact.
mov esp, ebp
pop ebp
retThe LEAVE Shortcut
The LEAVE instruction performs mov esp, ebp then pop ebp in one step, a compact epilogue.
leave
retFrame Layout Map
From high to low addresses in a typical frame:
- Parameters [ebp+8], [ebp+12]
- Return address [ebp+4]
- Saved EBP [ebp]
- Locals [ebp-4], [ebp-8]
Why Save EBP?
Each call saves the callers EBP so nested calls can each have a valid frame and the chain can be unwound, which debuggers use to print stack traces.
Frame Pointer Omission
Optimizing compilers may skip EBP setup to free a register, addressing locals relative to ESP instead. This is faster but harder to debug.
Quick Check
Test your understanding of stack frames.
Recap
You learned stack frames:
- Prologue:
push ebp,mov ebp, esp - Reserve locals with
sub esp, access at[ebp-N] - Parameters at
[ebp+N] - Epilogue restores frame;
LEAVEis the shortcut
الأسئلة الشائعة
هل درس «إطارات المكدس والمتغيرات المحلية» مجاني؟
نعم — نص درس «إطارات المكدس والمتغيرات المحلية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Assembly Language & x86 Low-Level Systems Programming، انتقل إلى CoddyKit PRO. تتضمن دورة Assembly Language & x86 Low-Level Systems Programming 4 دروس في المجموع.
ماذا ستتعلم في «إطارات المكدس والمتغيرات المحلية»؟
أنشئ إطارات المكدس وأزلها باستخدام مؤشّر الأساس (EBP/RBP) لتخصيص المتغيرات المحلية والوصول إلى المعاملات reliably داخل الإجراءات. تتمرن على 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.
كم من الوقت يستغرق درس «إطارات المكدس والمتغيرات المحلية»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Assembly Language & x86 Low-Level Systems Programming هذا؟
نعم. كل درس في Assembly Language & x86 Low-Level Systems Programming يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- أساسيات مكدس الاستدعاءات
- تعريف الإجراءات واستدعاؤها
- تمرير الوسائط والقيم المرجعة
- إطارات المكدس والمتغيرات المحلية