엔지니어가 되고 싶은 공돌이

08. Assembly 3: Procedures 본문

Computer Science/System Programming

08. Assembly 3: Procedures

Geca 2025. 2. 10. 23:52

 

8. 1. Stack

 

 

- Process에서 Data는 Stack에서 관리합니다.

 

 

 

- pushl: %esp 레지스터에서 4(64bit 컴퓨터는 %rsp 레지스터에서 8)를 감소시키고, 스택에 지정한 레지스터의 값을 넣습니다.

 

 

 

 

- popl: 스택의 값을 레지스터에 넣고, %esp 레지스터에서 4(64bit 컴퓨터는 %rsp 레지스터에서 8)를 증가시킵니다.

 


 

8. 2. Procedures

 

- Procedure Call(call label): stack에 return address(현재 PC 값)를 push하고, Label로 Jump합니다.

 

- Procedure Return(ret): stack에서 return address를 pop하고, retrurn adderss로 Jump합니다.

 

 

- Callee Function(호출당한 함수)return valueCaller Function(호출하는 함수)로 보낼 떄,

 

1) char, shor, int, long, pointer 등은 EAX Register에 저장해서 보냅니다.

 

2) Floating Point Number는 Floating Point Register에 저장해서 보냅니다.

 

3) Structure는 Caller Stack에 저장합니다.

 

 

- Programming Language를 위해 Stack은 Recursion(재귀)를 지원할 수 있어야 합니다.

 

 %esp와 %ebp가 현재 수행되는(or 재귀되는) 수 많은 함수들 중 하나를 지정.

 


 

8. 3. Example

 

 

 

- Caller Fuction에서 사용하고 있는 레지스터가 있다면(여기서는 %ebx), Callee Fuction이 작업 전 미리 그 값을 Temporary Save해둡니다. Caller Fucntion에서도 Temporary Save할 수 있습니다. [IA-32는 둘 다 사용.]

 

 

 


'Computer Science > System Programming' 카테고리의 다른 글

10. Linking  (0) 2025.02.12
09. Assembly 4: Complex Data Types  (0) 2025.02.11
07. Assembly 2: Control Flow  (0) 2025.02.07
06. Assembly 1: Basic Operations  (0) 2025.02.06
05. Program and Instruction Set  (0) 2025.02.06
Comments