12. Translating and Starting Program
12.3. Producing an Object Module
- Assembler(or Compiler) : 어셈블리 언어의 프로그램을 기계어로 바꾸어주는 역할
- 목적 파일(기계어로 번역된 Object 파일)
- Header : 아래의 항목들의 위치 정보를 알려줌
- Text segment : translated instructions
- Static data segment : data 영역, 전역 변수
- Relocation info : 여러 목적 파일들이 재배치가 되는데, 그 재배치의 정보들이 담겨 있음
- Symbol table : global definitions and external refs
- Debug info : 소스 코드와 어떻게 매핑되는지에 대한 정보를 담고있음
12.4. Linking Object Modules
- Produces an executable image
- Merges segments
- Resolve labels (determine their address)
- Patch location-dependent and external refs
12.5. Loading a Program
- Load from image file on disk into memory
- Read header to determine segment sizes
- Create virtual address space → 메모리 공간 확보
- Copy text and initialized data into memory
- Set up arguments on stack
- Initialize registers
- Jump to startup routine
12.6. Dynamic Linking
- 실행 파일의 size를 줄일 수 있음
- Only link/load library procedure when it is called
- Requires procedure code to be relocatable
- Automatically picks up new library versions
12.7. Lazy Linkage
12.8. Starting Java Applications
13. C Sort Example to Put It All Together
13.1. C Sort Example
void swap(int v[], int k){
int temp;
temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
}
// v in $a0, k in $a1, temp in $t0
13.2. The Procedure Swap
swap: s11 $t1, $a1, 2 # $t1 = k * 4
add $t1, $a0, $t1 # $t1 = v + (k*4) => address of v[k]
lw $t0, 0($t1) # $t0 (temp) = v[k]
lw $t2, 4($t1) # $t2 = v[k+1]
sw $t2, 0($t1) # v[k] = $t2(v[k+1])
sw $t0, 4($t1) # v[k+1] = $t0(temp)
jr $ra # return to calling routine