데이터 이동 명령어 (MOV, PUSH, POP)
MOV, PUSH, POP, LEA를 포함해 레지스터와 메모리, 스택 사이에서 데이터를 이동하는 명령어를 능숙하게 사용합니다.
데이터 이동 명령어 (MOV, PUSH, POP)은(는) CoddyKit의 무료 Assembly Language & x86 Low-Level Systems Programming 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Assembly Language & x86 Low-Level Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Data on the Move
In assembly language, programs constantly move data around. This data lives in different places: inside the CPU's registers or in memory.
Understanding how to move data is fundamental. It's like learning to pick up and place objects before you can build anything complex.
- Registers: Fast, small storage directly inside the CPU.
- Memory: Slower, larger storage outside the CPU (RAM).
- Stack: A special area in memory used for temporary storage and function calls.
Moving Data with MOV
The MOV instruction is your primary tool for copying data. It stands for "move," but it actually copies the source to the destination, leaving the source unchanged.
Its basic form is MOV destination, source. The destination can be a register or a memory location, and the source can be an immediate value, a register, or a memory location.
Here's how to put a number directly into a register:
section .text
global _start
_start:
mov eax, 123 ; Copy the immediate value 123 into the EAX register
mov ebx, 456 ; Copy 456 into EBX
; Exit system call
mov eax, 1
xor ebx, ebx
int 0x80Register to Register Moves
You can also copy data from one register to another. This is a very common operation for temporary storage or preparing data for other operations.
When you move data between registers, the original register's value remains, and the destination register gets a copy.
Consider this example:
section .text
global _start
_start:
mov eax, 10 ; EAX = 10
mov ebx, eax ; EBX gets a copy of EAX (EBX = 10), EAX is still 10
mov ecx, 20 ; ECX = 20
mov edx, ecx ; EDX gets a copy of ECX (EDX = 20), ECX is still 20
; Exit system call
mov eax, 1
xor ebx, ebx
int 0x80Storing and Loading from Memory
Moving data between registers and memory is crucial for working with variables. Memory addresses are often enclosed in square brackets [].
To store a register's value into a memory location, you use MOV [memory_address], register. To load a value from memory into a register, it's MOV register, [memory_address].
Let's define a variable in memory and interact with it:
section .data
my_var dd 50 ; Define a double-word (4-byte) variable 'my_var' and initialize it to 50
section .text
global _start
_start:
mov eax, [my_var] ; Load the value from 'my_var' (50) into EAX
mov ebx, 100 ; EBX = 100
mov [my_var], ebx ; Store the value of EBX (100) into 'my_var'.
; Now 'my_var' holds 100, EAX still holds 50.
; Exit system call
mov eax, 1
xor ebx, ebx
int 0x80Understanding the Stack
The stack is a crucial area of memory used for temporary storage. It operates on a "Last-In, First-Out" (LIFO) principle, like a stack of plates.
- When you "push" something onto the stack, it goes on top.
- When you "pop" something off, you always get the item that was most recently pushed.
The Stack Pointer (ESP) register always points to the "top" of the stack (the last item pushed).
Adding Data with PUSH
The PUSH instruction adds data to the top of the stack. When you PUSH a value:
- The ESP (Stack Pointer) register is decremented by 4 (for 32-bit values).
- The value is then stored at the new memory address pointed to by ESP.
This means the stack grows downwards in memory (towards lower addresses).
section .text
global _start
_start:
mov eax, 10 ; EAX = 10
mov ebx, 20 ; EBX = 20
push eax ; Push EAX's value (10) onto the stack
push ebx ; Push EBX's value (20) onto the stack (now on top of 10)
push 30 ; Push the immediate value 30 onto the stack (now on top of 20)
; At this point, the stack contains 30, then 20, then 10 (from top to bottom).
; Exit system call
mov eax, 1
xor ebx, ebx
int 0x80Retrieving Data with POP
The POP instruction removes data from the top of the stack and places it into a specified destination (usually a register).
When you POP a value:
- The value at the memory address pointed to by ESP is retrieved.
- The ESP (Stack Pointer) register is then incremented by 4.
POP reverses the effect of PUSH, ensuring you get back the last item you pushed.
section .text
global _start
_start:
mov eax, 10
mov ebx, 20
push eax ; Stack: [10]
push ebx ; Stack: [20, 10]
pop ecx ; ECX = 20. Stack: [10]
pop edx ; EDX = 10. Stack: []
; EAX = 10, EBX = 20, ECX = 20, EDX = 10.
; Notice ECX got EBX's original value because EBX was pushed last.
; Exit system call
mov eax, 1
xor ebx, ebx
int 0x80LEA: Getting an Address
The LEA instruction (Load Effective Address) is a bit special. Unlike MOV with brackets, LEA doesn't actually load the content of a memory location.
Instead, LEA calculates the address of the source operand and stores that address into the destination register.
It's super useful for working with pointers or calculating array offsets without touching memory data.
section .data
my_array dd 10, 20, 30 ; An array of double-words
section .text
global _start
_start:
mov ebx, 0 ; EBX will be our index (0 for first element)
mov ecx, 4 ; ECX will be our scale (4 bytes per double-word)
lea eax, [my_array + ebx*ecx] ; Calculate address of my_array[0] and put it in EAX
; EAX now holds the memory address of 'my_array'
; If we used MOV EAX, [my_array + ebx*ecx], EAX would hold the value 10.
; With LEA, EAX holds the *address* where 10 is stored.
; Exit system call
mov eax, 1
xor ebx, ebx
int 0x80Data Movement Challenge
Consider the following x86 assembly code snippet. Assume EAX and EBX initially contain 0.
mov eax, 5
push eax
mov ebx, 10
push ebx
pop eax
pop ebx
What will be the final values in the EAX and EBX registers?
Summary of Data Movement
Great job! You've learned the fundamental instructions for moving data in x86 assembly:
MOV: Copies data between registers, memory, and immediate values. It's your workhorse for assigning and loading data.PUSH&POP: Manage data on the stack, following a LIFO principle. Essential for temporary storage and procedure calls.LEA: Calculates and loads an address into a register, without touching the data at that address. Crucial for pointer arithmetic.
These instructions are the building blocks for almost every assembly program. Next, we'll explore how to perform arithmetic and logical operations on this data!
자주 묻는 질문
“데이터 이동 명령어 (MOV, PUSH, POP)” 강의는 무료인가요?
네 — “데이터 이동 명령어 (MOV, PUSH, POP)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Assembly Language & x86 Low-Level Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
“데이터 이동 명령어 (MOV, PUSH, POP)”에서 뭘 배우나요?
MOV, PUSH, POP, LEA를 포함해 레지스터와 메모리, 스택 사이에서 데이터를 이동하는 명령어를 능숙하게 사용합니다. 브라우저에서 직접 실행하는 실습 코드로 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개 중 1번째 강의입니다.
“데이터 이동 명령어 (MOV, PUSH, POP)” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Assembly Language & x86 Low-Level Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Assembly Language & x86 Low-Level Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 데이터 이동 명령어 (MOV, PUSH, POP)
- 산술 및 논리 연산
- 조건부 점프와 반복문
- 비트 연산 및 시프트 명령어