0Pricing
Assembly Language & x86 Low-Level Systems Programming · レッスン

スタックフレームとローカル変数

ベースポインタ(EBP/RBP)を使ってスタックフレームを構築・破棄し、プロシージャ内でローカル変数を確保して引数へ確実にアクセスする方法を学びます。

「スタックフレームとローカル変数」は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 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, esp

Allocating 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 locals

Accessing Locals

Reference each local by a fixed offset below the base pointer.

mov dword [ebp-4], 10   ; first local = 10

Accessing Parameters

With the classic cdecl layout, parameters sit above the saved EBP and return address, at positive offsets.

mov eax, [ebp+8]        ; first argument

The Epilogue

Before returning, restore the stack and base pointer so the caller frame is intact.

mov esp, ebp
pop ebp
ret

The LEAVE Shortcut

The LEAVE instruction performs mov esp, ebp then pop ebp in one step, a compact epilogue.

leave
ret

Frame 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; LEAVE is the shortcut

よくある質問

「スタックフレームとローカル変数」レッスンは無料ですか?

はい。「スタックフレームとローカル変数」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、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を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Assembly Language & x86 Low-Level Systems Programmingを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのAssembly Language & x86 Low-Level Systems Programmingは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「スタックフレームとローカル変数」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このAssembly Language & x86 Low-Level Systems Programmingレッスンでコードを書いて実行できますか?

はい。すべてのAssembly Language & x86 Low-Level Systems Programmingレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. コールスタックの基礎
  2. プロシージャの定義と呼び出し
  3. 引数と戻り値の受け渡し
  4. スタックフレームとローカル変数
← Assembly Language & x86 Low-Level Systems Programmingに戻る