0Pricing
Assembly Language & x86 Low-Level Systems Programming · 강의

메모리 주소 지정 모드

직접, 간접, 베이스, 인덱스와 스케일된 인덱스 같은 다양한 주소 지정 모드로 메모리 위치에 액세스하는 방법을 살펴봅니다.

메모리 주소 지정 모드은(는) CoddyKit의 무료 Assembly Language & x86 Low-Level Systems Programming 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Assembly Language & x86 Low-Level Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Memory's Many Paths

Welcome! Today, we'll learn how your CPU finds data in memory. This is crucial for understanding how programs work at a low level.

Memory addressing modes are the different ways a CPU can calculate the effective memory address of an operand.

  • They allow flexible access to data.
  • They're key for arrays, structures, and dynamic data.

Direct Addressing: Fixed Spots

Direct addressing is the simplest way to access memory. You provide the exact, fixed address of the data you want.

Think of it like going to a specific house number on a street. It's straightforward but not very flexible if you need to access different houses dynamically.

Try running this example:

section .data
  ; Define a word (2-byte) variable at a specific label
  my_data dw 0x1234

section .text
  global _start

_start:
  ; Move the content of 'my_data' into the AX register
  ; The CPU directly accesses the address associated with 'my_data'
  mov ax, [my_data]

  ; Exit program (Linux specific syscall)
  mov eax, 1    ; syscall number for exit
  xor ebx, ebx  ; exit code 0
  int 0x80      ; call kernel

Register Indirect: Flexible Pointers

Register indirect addressing uses a general-purpose register (like EBX, ESI, or EDI) to hold the memory address.

Instead of a fixed address, the register acts as a 'pointer' to the data. This is much more flexible, as you can change the register's value to point to different memory locations.

Here's an example:

section .data
  ; Define some data in memory
  value1 dw 0xAABB
  value2 dw 0xCCDD

section .text
  global _start

_start:
  ; Load the address of 'value1' into EBX
  mov ebx, value1
  ; Move the content pointed to by EBX into AX
  mov ax, [ebx] ; AX now holds 0xAABB

  ; Change EBX to point to 'value2'
  mov ebx, value2
  ; Move the content pointed to by EBX into DX
  mov dx, [ebx] ; DX now holds 0xCCDD

  ; Exit program
  mov eax, 1
  xor ebx, ebx
  int 0x80

Base Addressing: Structured Access

Base addressing combines a base register (often EBX or EBP) with a fixed numerical displacement (offset).

This is extremely useful for accessing fields within a data structure or elements of an array when the base address of the structure/array is in the register.

Example:

section .data
  ; A 'structure' with two word members
  my_struct:
    member1 dw 0x1111
    member2 dw 0x2222

section .text
  global _start

_start:
  ; Load the base address of 'my_struct' into EBX
  mov ebx, my_struct

  ; Access 'member1' (offset 0 from base)
  mov ax, [ebx + 0] ; AX now holds 0x1111

  ; Access 'member2' (offset 2 bytes from base, as words are 2 bytes)
  mov dx, [ebx + 2] ; DX now holds 0x2222

  ; Exit program
  mov eax, 1
  xor ebx, ebx
  int 0x80

Index Addressing: Array Iteration

Index addressing uses an index register (like ESI or EDI) plus a displacement.

This mode is perfect for iterating through array elements, where the displacement can be the starting address of the array and the index register holds the current element's offset.

Consider this:

section .data
  ; An array of words
  my_array dw 10h, 20h, 30h, 40h

section .text
  global _start

_start:
  ; Set ESI to 0 (first element offset)
  mov esi, 0
  ; Access first element: my_array[0]
  mov ax, [my_array + esi] ; AX = 10h

  ; Increment ESI to point to the next word (2 bytes)
  add esi, 2
  ; Access second element: my_array[1]
  mov bx, [my_array + esi] ; BX = 20h

  ; Exit program
  mov eax, 1
  xor ebx, ebx
  int 0x80

Base-Index: 2D Arrays & More

Base-index addressing combines a base register and an index register (with an optional displacement).

This is powerful for accessing elements in two-dimensional arrays, or arrays of structures. The base register might hold the start of a row, and the index register the column offset.

It looks like [base + index] or [displacement + base + index].

section .data
  ; A 2x2 array of words (each row is 4 bytes: 2 words * 2 bytes/word)
  matrix dw 1, 2   ; Row 0
         dw 3, 4   ; Row 1

section .text
  global _start

_start:
  ; EBX holds the base address of the matrix
  mov ebx, matrix

  ; Access element [0][0]: (EBX + ESI)
  mov esi, 0 ; Index for column 0
  mov ax, [ebx + esi] ; AX = 1

  ; Access element [0][1]: (EBX + ESI)
  mov esi, 2 ; Index for column 1 (1 word * 2 bytes/word)
  mov bx, [ebx + esi] ; BX = 2

  ; Access element [1][0]: (EBX + displacement for row 1 + ESI)
  ; Row 1 starts 4 bytes after row 0
  mov esi, 0
  mov cx, [ebx + 4 + esi] ; CX = 3

  ; Exit program
  mov eax, 1
  xor ebx, ebx
  int 0x80

Scaled-Index: Data Type Friendly

Scaled-index addressing is an extension of base-index, allowing you to multiply the index register by a scale factor (1, 2, 4, or 8).

This is incredibly useful when working with arrays of different data sizes (bytes, words, double words, quad words) because the CPU automatically calculates the correct offset.

Format: [base + index*scale + displacement]

section .data
  ; An array of double words (4 bytes each)
  d_array dd 100h, 200h, 300h

section .text
  global _start

_start:
  ; EBX holds the base address of the array
  mov ebx, d_array

  ; Access d_array[0] (index 0, scale 4 for dword)
  mov esi, 0
  mov eax, [ebx + esi*4] ; EAX = 100h

  ; Access d_array[1] (index 1, scale 4 for dword)
  mov esi, 1
  mov ebx, [ebx + esi*4] ; EBX = 200h

  ; Access d_array[2] (index 2, scale 4 for dword)
  mov esi, 2
  mov ecx, [ebx + esi*4] ; ECX = 300h

  ; Exit program
  mov eax, 1
  xor ebx, ebx
  int 0x80

The Constant: Displacement

You've seen the term 'displacement' pop up in several modes. A displacement is a constant, signed 8-bit, 16-bit, or 32-bit value that's added to the calculated address.

  • It provides a fixed offset from a base or index.
  • It's often used to access specific members within a structure or to jump to a certain point in an array.
  • It can be positive or negative.

It acts like a fixed street number offset from a known starting point.

Choosing Your Addressing Mode

Which mode should you use?

  • Direct: For fixed, known memory locations (e.g., global variables).
  • Register Indirect: For pointers, dynamic memory access.
  • Base/Index: For array iteration, accessing structure members.
  • Scaled-Index: Best for arrays of different-sized data types, letting the CPU handle scaling.

Understanding these modes gives you powerful control over memory!

Addressing Mode Challenge

Test your knowledge on memory addressing modes!

Memory Paths Mastered

Great job! You've explored the fundamental x86 memory addressing modes:

  • Direct: Fixed addresses.
  • Register Indirect: Register as a pointer.
  • Base: Base register + displacement.
  • Index: Index register + displacement.
  • Base-Index: Base + Index + optional displacement.
  • Scaled-Index: Base + Index * Scale + optional displacement.

These modes are the building blocks for how your programs interact with data in memory. Keep practicing!

자주 묻는 질문

“메모리 주소 지정 모드” 강의는 무료인가요?

네 — “메모리 주소 지정 모드” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Assembly Language & x86 Low-Level Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

“메모리 주소 지정 모드”에서 뭘 배우나요?

직접, 간접, 베이스, 인덱스와 스케일된 인덱스 같은 다양한 주소 지정 모드로 메모리 위치에 액세스하는 방법을 살펴봅니다. 브라우저에서 직접 실행하는 실습 코드로 Assembly Language & x86 Low-Level Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Assembly Language & x86 Low-Level Systems Programming을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Assembly Language & x86 Low-Level Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“메모리 주소 지정 모드” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Assembly Language & x86 Low-Level Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Assembly Language & x86 Low-Level Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. x86 레지스터 쉽게 이해하기
  2. 메모리 주소 지정 모드
  3. 데이터 표현과 타입
  4. FLAGS 레지스터와 상태 비트
← Assembly Language & x86 Low-Level Systems Programming(으)로 돌아가기