'Computer Systems: A Programmer's Perspective 3rd (Randal E. Bryant)'를 주교재로 한 시스템 소프트웨어 강의 수업자료를 복습하며 정리한 것
C, assembly, machine code
- Architecture
- also ISA : instruction set architecture
- machine, assembly code를 쓰기 위해 이해해야 하는 프로세서 설계 부분
- e.g.) instruction set specification, registers
- Machine code : byte-level programs that a processor executes
- Assembly code : machine code를 text로 표현한 것
- Microarchitecture
- architecture의 구현
- e.g.) cache sizes and core frequency
- Assembly/Machine Code View
- Turning C into Object Code
- command : gcc -Og p1.c p2.c -o p
- -Og : Optimization level
- -o p : 생성될 binary file의 이름을 p로 하겠다.
- Assembly Characteristics : Data Types
- Integer data of 1, 2, 4, or 8 bytes
- Data values, Addresses
- Floating point data of 4(float), 8(double), or 10(long double) bytes
- Code : Byte sequences encoding series of instructions
- array나 별도의 자료구조와 같은 aggregate type은 지원하지 않음(just contiguously allocated bytes in memory)
- Assembly Characteristics : Operations
- arithmetic function(산술적 연산)은 register나 memory를 대상으로 수행됨
- Transfer data between memory and register
- Transfer control
- call, jump, conditional branches
- Assembler
- Translates .s into .o
- Binary encoding of each instruction
- Missing linkages between code in different files
- Linker
- Resolves references between files
- Combines with static run-time libraries
- e.g.) code for malloc, printf
- some libaries are dynamically linked (Linking occurs when program begins execution)
- Machine Instruction Example
C Code | Assembly | Object code |
*dest = t; | movq %rax, (%rbx) | 0x40059e: 48 89 03 |
t : register %rax dest : register %rbx *dest : Memory M[%rbx] |
- Disassemble
- Object code를 assembly code로 변환
Assembly Basics : Registers, operands, move
- x86-64 Integer registers
-
- 32bit에서 사용하던 8개 레지스터(%eax ~ %ebp)에 64bit로 변경되며 추가된 것들로 이루어짐
- %rsp(%esp)는 다른 레지스터들과 달리 스택 메모리 영역을 가리키는 용도로만 사용
- %rax의 하위 32bit를 사용하고싶다면 %eax를 사용
- Moving Data
- movq Source, Dest : 어떠한 데이터를 source로부터 destination으로 이동시켜라
- Operand Types
- Immediate : Constant integer data e.g.) $0x400, $-533
- Register : e.g.) %rax
- Memory : e.g.) (%rax)
Arithmetic & logical operations
- Address Computation Instruction
- leaq Src, Dst
- Src : address mode를 사용한 표현식
- Dst를 src에 표현된 address로 set
- e.g.) p = &x[i]; k = 1, 2, 4, or 8
- leaq Src, Dst
- Some Arithmetic Operations
- Two Operand Instructions
- addq : +
- subq : -
- imulq : *
- salq : <<
- sarq : >> (arithmetic right shift)
- shrq : >> (logical right shift)
- xorq : ^
- andq : &
- orq : |
- One Operand Instructions
- incq : Dest + 1
- decq : Dest - 1
- negq : -Dest
- notq : ~Dest
- Two Operand Instructions
'CS > 시스템소프트웨어' 카테고리의 다른 글
05. machine-control (0) | 2022.10.31 |
---|---|
03. float (0) | 2022.10.28 |
02. Bits, Bytes, and Integers (0) | 2022.10.25 |