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

09. Assembly 4: Complex Data Types 본문

Computer Science/System Programming

09. Assembly 4: Complex Data Types

Geca 2025. 2. 11. 17:20

 

9. 1. Array

 

- Array Allocation: Data Type Array_Name[Length];

 

- Array를 Allocation 하게되면 연속적으로 저장하게 됩니다.

 

  ex) char val[5] => Memory Address: x, x+1, x+2, x+3, x+4.

 

        int val2[4] => Memory Address: x, x+4, x+8, x+12.

 

 

- Array Access: %edx에 Array의 Start Address가 있고,

 

  %eax에 Array의 Index가 있다고 가정하면,

 

  Movl (%edx, %eax, 4), %eax 로 Array Value를 가져올 수 있습니다. [int Type Array]

 

 

ex) int arr[5] = {1, 3, 5, 7, 9}; [Memory Address x]

 

  1) arr[3] => 7. [int]

 

  2) arr => x. [pointer]

 

  3) arr + 2 => x + 8. [pointer]

 

  4) &arr[3] => x + 12. [pointer]

 

  5) *(arr + 2) => 5. [int]

 

 

- Nested Array Allocation: Data Type Array_Name[Row Length][Column Length];

 

- Nested Array Access: Array Start Address + i X C X K + j X K.

 

[i is Array Row Index / j is Array Column Index / C is the number of Columns / K is Data Type Byte].

 


 

9. 2. Alignment

 

- Array뿐만 아니라 Structure도 연속적으로 메모리공간을 할당합니다.

 

- Structure에 Data를 Input, Search할 때도 Address Opeartions이 필요하며,

 

  이 때도 Nested Array 처럼 Start Address로부터 Structure에서 선언한 순서대로,

 

  요소들의 크기를 더해가며 Address를 찾습니다.

 

 

- 컴퓨터는 데이터를 저장할 때 탐색을 쉽게하기 위해서 Alignment(정렬) 하기를 원합니다.

 

   Char은 1Byte,

 

   short는 2Byte,

 

   int/float는 4Byte,

 

   double은 8Byte(Window는 8Byte, Linux는 4Byte)

 

   로 Alignment를 수행합니다.

 

structure Str1{
	char c;
	int i[2];
	double d;
};

 

 

1) Window

 

2) Linux

 

 

- 결론적으로, 메모리의 효율적인 사용을 위해서 Structure를 만들 때, 선언 순서는 중요합니다.

 


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

10. Linking  (0) 2025.02.12
08. Assembly 3: Procedures  (0) 2025.02.10
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