0Pricing
Reverse Engineering & Binary Analysis Basics · レッスン

レジスタとメモリ操作

レジスタを使ってデータを保存する方法と、命令がメモリ上の位置とやり取りする仕組みを理解します。

「レジスタとメモリ操作」はCoddyKit上の無料Reverse Engineering & Binary Analysis Basicsレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはReverse Engineering & Binary Analysis Basics学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Reverse Engineering & Binary Analysis Basicsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Registers & Memory: CPU's Workspace

In reverse engineering, understanding how a CPU uses registers and memory is fundamental. Think of them as the CPU's short-term and long-term storage areas.

  • Registers are tiny, super-fast storage units directly inside the CPU.
  • Memory (like RAM) is a larger, slower storage area outside the CPU, where programs and data reside.

We'll explore how assembly instructions move data between these crucial locations.

CPU Registers: Internal & Fast

Registers are the fastest way for the CPU to access data. They hold values that the CPU is actively working with, like intermediate calculation results or memory addresses.

Different architectures (like x86, x64, ARM) have different sets of registers, but their purpose is similar: providing quick access to data for computation.

x86/x64 General Purpose Registers

For x86/x64 architectures, you'll commonly encounter general-purpose registers used for various tasks. While their roles can vary, some have conventional uses:

  • RAX/EAX: Often used for return values from functions.
  • RBX/EBX: A general-purpose register.
  • RCX/ECX: Often used as a counter in loops.
  • RDX/EDX: Can be used for arguments or data.

Remember, the 'R' prefix (e.g., RAX) denotes 64-bit, while 'E' (e.g., EAX) denotes 32-bit versions.

The `MOV` Instruction: Moving Data

The MOV (move) instruction is one of the most fundamental in assembly. It copies data from a source to a destination. The source can be an immediate value, a register, or a memory location. The destination can be a register or a memory location (but not memory-to-memory directly).

Let's see a C example that conceptually maps to register operations.

#include <stdio.h>

int main() {
  int value1 = 100;
  int value2 = 200;
  int sum = value1 + value2;
  printf("Sum: %d\n", sum);
  return 0;
}

Understanding Memory

Beyond registers, programs need larger storage: memory. This is where your code, variables, and data structures actually live when not actively being processed by the CPU.

Memory is organized as a vast array of bytes, each with a unique address. The CPU uses these addresses to find and access specific pieces of data.

  • Think of memory addresses like house numbers on a street.
  • Each byte is a small "storage box" at a specific address.

How to Find Data: Addressing Modes

To access data in memory, assembly uses various addressing modes. These are different ways to calculate the exact memory address an instruction needs.

  • Direct Addressing: The address is explicitly given (e.g., [0x12345678]).
  • Register Indirect Addressing: The address is stored in a register (e.g., [EAX]).
  • Base + Index Addressing: Combines a base register with an index register (e.g., [EBX + ESI]).
  • Base + Index + Displacement: Adds a constant offset (displacement) to the base and index (e.g., [EBP + ESI + 0x10]).

These modes are crucial for accessing arrays, structures, and function parameters.

Fetching Data: Register <- Memory

To use data stored in memory, the CPU first needs to load it into a register. The MOV instruction is again used for this, but with a memory address as the source.

In assembly, square brackets [] typically denote a memory access. For example, [EAX] means "the value at the memory address currently held in register EAX".

#include <stdio.h>

int main() {
  int data = 42;
  int result;

  // Imagine 'data' address is loaded into a register, then its value is fetched
  result = data;

  printf("Result: %d\n", result);
  return 0;
}

Saving Data: Memory <- Register

After the CPU processes data in its registers, it often needs to store the results back into memory. This is also done using the MOV instruction, but this time, a memory address is the destination.

Understanding these load (read) and store (write) operations is vital for tracing program execution and data manipulation during reverse engineering.

#include <stdio.h>

int main() {
  int x = 5;
  int y = 10;
  int *ptr = &x;

  // Imagine y's value (in a register) is moved to where ptr points (memory address of x)
  *ptr = y;

  printf("x is now: %d\n", x);
  return 0;
}

The Stack: Temporary Storage

One special region of memory is the stack. It's used for temporary storage, like function arguments, local variables, and return addresses. It operates on a "Last-In, First-Out" (LIFO) principle, like a stack of plates.

  • PUSH: Adds data to the top of the stack.
  • POP: Removes data from the top of the stack.

The Stack Pointer (RSP/ESP) register always points to the current top of the stack.

Check Your Understanding

Time for a quick check on registers and memory!

Registers & Memory: Key Takeaways

We've covered the crucial roles of registers and memory in assembly and reverse engineering:

  • Registers are the CPU's internal, fastest storage, holding data for immediate processing.
  • Memory (RAM) provides larger storage, organized by unique addresses.
  • The MOV instruction is central for moving data between registers and memory.
  • Addressing modes define how memory locations are calculated and accessed.
  • The stack is a special LIFO memory area for temporary data.

Mastering these concepts is essential for understanding how programs manipulate data at a low level!

よくある質問

「レジスタとメモリ操作」レッスンは無料ですか?

はい。「レジスタとメモリ操作」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Reverse Engineering & Binary Analysis Basicsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Reverse Engineering & Binary Analysis Basicsコースには全4レッスンが含まれています。

「レジスタとメモリ操作」で何を学びますか?

レジスタを使ってデータを保存する方法と、命令がメモリ上の位置とやり取りする仕組みを理解します。 ブラウザで直接実行するハンズオンコードでReverse Engineering & Binary Analysis Basicsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Reverse Engineering & Binary Analysis Basicsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのReverse Engineering & Binary Analysis Basicsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「レジスタとメモリ操作」レッスンにはどのくらい時間がかかりますか?

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

このReverse Engineering & Binary Analysis Basicsレッスンでコードを書いて実行できますか?

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

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

  1. x86/x64アセンブリの基礎
  2. レジスタとメモリ操作
  3. 制御フローと関数呼び出し
  4. スタックと呼び出し規約
← Reverse Engineering & Binary Analysis Basicsに戻る