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

07. Compiler 본문

Computer Science/Computer Architecture

07. Compiler

Geca 2025. 4. 25. 16:00

 

7. 1. Compiler and Assembler

 

1. Compiler: C Program -> Assembly Language Program.

 

 

2. Assembler: Assembly Language Program -> Machine Language Module.

 

- Pseudoinstruction(의사 명령어): Hardware가 지원하지 않는 Assembly 명령어를, 

 

  Assembler가 마치 실제로 있는 것처럼 처리하는 명령어.

 

  Pseudoinstruction 덕분에 실제의 하드웨어 구현보다 더 풍부한 방법을 제공해줍니다.

 

  다만, Assembler가 자유롭게 활동할 수 있도록 Register($at) 1개를 Assembler 전용으로 제공해야 합니다.

 

 

- Unix System Object File

 

  1) Object File Header: Object File을 구성하는 각 부분의 크기와 위치를 가지고 있습니다.

 

  2) Text Segment: Machine Instruction을 가지고 있습니다.

 

  3) Static Data Segment: 프로그램의 수명동안 살아 있는 데이터가 들어가 있습니다.

 

  4) Relocation Information: 프로그램이 메모리에 적재될 때,

 

      Absolute Address를 필요로 하는 명령어와 데이터를 가지고 있습니다.

 

  5) Symbol Table: Label을 찾아서 이진수로 변환할 수 있도록 Address와 짝지어 주는 Table.

 

  6) Debugging Information.

 


 

7. 2. Linker and Loader

 

3. Linker: Machine Language Module + Library -> Machine Language Program.

 

- Linker는 여러 개의 Object File을 모아서 Execution File을 만듭니다.

 

  1) Code와 Data Module을 Memory에 Symbol 형태로 올려 놓습니다.

 

  2) Object File의 Relocation Information, Symbol Table을 이용해서,

 

      Data와 Instruction Label의 주소를 결정합니다.

 

  3) 외부 및 내부 참조를 해결합니다.

 

 

4. Loader: Machine Language Program -> Memory

 

  1) Execution File을 읽어서 Text Segment, Data Segment의 크기를 알아내고,

 

      Memory에 충분히 들어갈 만큼 공간을 할당합니다.

 

  2) Execution File의 Data와 Instruction을 복사합니다.

 

  3) 주 프로그램에 전달해야할 인수가 있다면 Stack에 복사합니다.

 

  4) Register를 초기화하고, Stack Pointer는 사용가능한 첫 주소를 가리키게 합니다.

 

  5) Start-up Routine(기둥루틴)으로 점프하고, 이 Start-up Routine에서 인수를 인수레지스터에 넣고,

 

      프로그램의 주 루틴을 호출합니다. 프로그램이 다시 Start-up Routine으로 복귀하면,

 

      exit를 호출하여 프로그램을 종료시킵니다.


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

09. Floating Point Number  (0) 2025.04.29
08. Arithmetic Operations  (0) 2025.04.29
06. Procedure and Jumping  (0) 2025.04.24
05. Logical Operation and Branch  (0) 2025.04.24
04. Instruction Format  (0) 2025.04.23
Comments