สแต็กเฟรมและตัวแปรเฉพาะที่
สร้างและรื้อสแต็กเฟรมโดยใช้ตัวชี้ฐาน (EBP/RBP) เพื่อจัดสรรตัวแปรเฉพาะที่และเข้าถึงพารามิเตอร์ภายในโพรซีเยอร์ได้อย่างถูกต้องสม่ำเสมอ
สแต็กเฟรมและตัวแปรเฉพาะที่ เป็นบทเรียน Assembly Language & x86 Low-Level Systems Programming ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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
เรียนรู้ Assembly ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 48
คำถามที่พบบ่อย
บทเรียน “สแต็กเฟรมและตัวแปรเฉพาะที่” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “สแต็กเฟรมและตัวแปรเฉพาะที่” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Assembly Language & x86 Low-Level Systems Programming ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Assembly Language & x86 Low-Level Systems Programming มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “สแต็กเฟรมและตัวแปรเฉพาะที่”
สร้างและรื้อสแต็กเฟรมโดยใช้ตัวชี้ฐาน (EBP/RBP) เพื่อจัดสรรตัวแปรเฉพาะที่และเข้าถึงพารามิเตอร์ภายในโพรซีเยอร์ได้อย่างถูกต้องสม่ำเสมอ คุณปฏิบัติ Assembly Language & x86 Low-Level Systems Programming ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 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 ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- พื้นฐานสแตกการเรียก
- การกำหนดและเรียกโพรซีเยอร์
- การส่งอาร์กิวเมนต์และค่าที่ส่งคืน
- สแต็กเฟรมและตัวแปรเฉพาะที่