Abstraction ; ์ถ์ํ
" ๋ณต์กํ ์๋ฃ, ๋ชจ๋, ์์คํ ๋ฑ์ผ๋ก๋ถํฐ ํต์ฌ์ ์ธ ๊ฐ๋ ๋๋ ๊ธฐ๋ฅ์ ๊ฐ์ถ๋ ค ๋ด๋ ๊ฒ "
Instruction set architecture (ISA)
: ํ๋์จ์ด์ Low-level ์ํํธ์จ์ด ๊ฐ์ abstraction interface
ํ์ค์์ ๋ฐ์ง๋ฉด ๊ธฐ๊ณ๋ฅผ ์ด์ ํ๋ ์ฌ์ฉ์์๊ฒ ์ ๊ณตํ๋ '์ฐจ'๋ผ๋ abstraction layer ๊ฐ์..
Abstractions in Computer
- Programming using APIs : API๋ฅผ ์ด์ฉํด ํ๋ก๊ทธ๋๋ฐ
- Operating Sytems : ์ด์์ฒด์ , APIs๋ฅผ ์ ๊ณต
- Instruction Set Architecture (ISA) : Assembly language or Machine language
- Hardware Implementation
Hardware/Software Stack in Computer
- Applications
- Operating Systems
- BIOS (Fermware instructions)
- Instruction Set Architecture(ISA)
Computer Hardware
---------------------------
- Application software : high-level language๋ก ์ฐ์ฌ์ง ๊ฒ!
- System software
- Compilers : high-level language๋ก ์ฐ์ฌ์ง ์ฝ๋๋ฅผ machine code๋ก ๋ฒ์ญ
- Operating Systems
: input/output Handling, memory and storage ๊ด๋ฆฌ, scheduling tasks + sharing resources - BIOS (Basic Input/Output System)
- ISA : hardware์ low-level software ์ฌ์ด์ interface .. assembly programming(low-level language)
- Hardware : processor, memory, I/O controllers
Instructions
-> ์ธ๊ตญ์ธ์๊ฒ ๋งํ๋ ค๋ฉด ๊ทธ๋ค์ ์ธ์ด๋ฅผ ์์์ผ ํ๋ฏ, ์ปดํจํฐ๋ ๊ทธ๋ฌํจ.
์ปดํจํฐ์ ์ธ์ด๊ฐ ๋ฐ๋ก instructions!!
- collection of instructions = instruction set
- ์๋ก ๋ค๋ฅธ CPU๋ ์๋ก ๋ค๋ฅธ instruction sets์ ๊ฐ์ง๊ณ ์์
Levels of Program Code
High-level language
: ์ถ์ํ ์์ญ์ ๋ ๊ฐ๊น์ด ๋ฌธ์ ์์ญ. productivity and portabilityํจ
complie ํ์๋ cpu๊ฐ ์์๋ฃ๊ฒ ๋ณํ๋จ (= not portable)
| C compiler
↓ (one-to-many)
Assembly language
: textual and symbolic representation of instructions
์ข ๋ ์์ง์ (?) ์ด๋๊น
| Assembler
↓ (one-to-one)
Machine code(object code or binary)
: binary bits of instructions and data ; ๋ชจ๋ ๋ช ๋ น๊ณผ ๋ฐ์ดํฐ๊ฐ ์ด์ง ๋นํธ๋ก..
linux machine์์ hello.c ๋ฅผ ์คํ์ํค๊ธฐ ์ํด์๋ ?
% gcc -g hello.c -o hello
% ./hello
์ ๊ณผ์ ์ ๊ฑฐ์น๋ฉด hello๋ผ๋ machine code๊ฐ ์์ฑ๋๋ค. ์ ์ฝ๋๋ binary ๋๋ executableํ ์คํํ์ผ!
์ปดํ์ผ๋ฌ๋ฅผ ๊ฑฐ์ณ์ hello.c. ๋ก๋ถํฐ hello(executable) ์ฝ๋๋ก ๋ง๋ค์ด๋๋ค.
์ด ๋ ์ด ์ฝ๋๋ 2์ง์๋ก 10001011 10111100 ์ด๋ฐ ์์ผ๋ก ํ์ผ์ด ๋ง๋ค์ด์ ธ์๊ณ ,
์ด ํ์ผ์ ์ด์ด๋ณด๋ฉด 8bit์ฉ ๋ฌธ์๋ก ๋ณํํด์ ๋ฌธ์๋ก ๋ณด์ด๊ฒ ๋๋ค.
ex) 0100 0001 = 0x41 = 'A' (In text Editor)
์ฌ๊ธฐ์
% objdump -S -D -Mintel hello
๋ฅผ ํด์ฃผ๋ฉด assembly code๋ฅผ ์ฌ๋์ด ์ฝ์ ์ ์๊ฒ๋ ๋ง๋ค์ด์คใ ใ
์ฆ, ์๋ฒฝํ๊ฒ ๊ธฐ๊ณ์ด๋ก ๋ณํ๊ธฐ ์ง์ ์ฌ๋์ด ์ฝ์ ์ ์๋ ์ ๋์ ๋จ๊ณ๋ก ํ ์นธ ๋๋ ค๋์ค๋ค๊ณ ์๊ฐํ๋ฉด ๋จ.
(-Mintel์ assembly code์ intel format์ ์ฌ์ฉํ๋ค๋ ์ด์ผ๊ธฐ!)
High-level Code to Executable(Binary)
C program
|
| preprocessor
|
Expanded C program
|
| compiler
| (Human-readable assembly code)
assembly code
|
| assembler
|------------------------------ machine code
object code (binary code)
|
| linker <--- library routines
|
executable
|
| loader
|
memory
** gcc ๋ผ๋ command๋ ์ด ๋ชจ๋ ๊ณผ์ ์ ํ ๋ฒ์ ์ฒ๋ฆฌํด์ฃผ๋ ์์ด!
์ปดํ์ผ์ ํ๋ค๋ ๊ฒ์, machine code๋ฅผ ๋ง๋ค๊ธฐ ์ํด ์์ ๊ฐ์ ๋จ๊ณ๋ฅผ ๊ฑฐ์น๋ ๊ฒ์ ๋งํจ.
1. Preprocessing
: macros์ includeํ header files์ ๊ฐ์ ธ์จ๋ฌ๊น,
%cpp simple_sub.c > simple_sub.i
2. Compilation
: preprocessed๋ ์ฝ๋๋ฅผ assembly language๋ก ์ค์ ๋ก ์ปดํ์ผ ํด์ฃผ๋ ๋จ๊ณ!
%gcc -S simple_sub.i
๊ทธ ๊ฒฐ๊ณผ simple_sub.s๊ฐ ์์ฑ๋์๋ค.
3. Assembler
: ์ด์
๋ธ๋ฆฌ ์ธ์ด๋ฅผ machine code๋ก ๋ณํํ๊ณ object file์ ์์ฑํ๋ค
%as simple_sub.s -o simple_sub.o
.o ํ์ผ์ ํ๋ก๊ทธ๋จ์ machine instructions๋ฅผ ํฌํจํ๊ณ ์๋ค.
(printf์ reference๊ฐ ์ ์๋์ง ์๋๋ค๋๋ฐ ๋ญ์๋ฆฌ์ง)
4. Linker
: compilation์ ์ต์ข
๋จ๊ณ๋ก object files์ linking ํด์ executableํ ํ์ผ์ ๋ง๋ฆ (๊ฐ์ข
๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ฝ๋๋ฅผ ํฉ์นจ)
% ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/5/crtbegin.o -L/usr/lib/gcc/x86_64- linux-gnu/4.4.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3 -L/usr/lib - L/lib -L/usr/lib -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu --as-needed --no-as-needed -lc --as-needed --no-as-needed /usr/lib/gcc/x86_64- linux-gnu/5/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o simple_sub.o -o simple_sub
์ค์ ์คํ ํ์ผ์๋ ์์คํ ์ด๋ C run-time(crt) ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ง์ ์ธ๋ถ์ ์ธ ํจ์๋ค์ ํ์๋ก ํ๊ธฐ ๋๋ฌธ์, gcc ๋ด๋ถ์์ ์ค์ ๋ก ์ฌ์ฉํ๋ ๋งํฌ commands๋ ๋งค์ฐ๋งค์ฐ ๋ณต์กํ๋น
์ด์ ์ด๋ ๊ฒ ๋ง๋ค์ด์ง simple_sub๋ฅผ ์ด์ด๋ณด๋ฉด ๋ฐ๋ก ์คํ์ด ๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค!
%3 - 5 = -2 //output
Stored Program Concept
- instructions๊ณผ data๋ binary๋ก ๋ํ๋ด์ง๋ฉฐ, ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ๋๋ค
- CPU๋ ์ด instructions๊ณผ data๋ฅผ ์คํํ๊ธฐ ์ํด fetch ํด์จ๋ค
- Binary compatibility๋ ์ปดํ์ผ๋ ํ๋ก๊ทธ๋จ์ด ๋์ผํ ISA์ ์๋ก ๋ค๋ฅธ ์ปดํจํฐ์์๋ ์๋ํ ์ ์๋๋ก ํด์ค๋ค.
Cross Compiler
- RISC-V machine ์์ด RISC-V machine ์ฝ๋๋ฅผ ๋ง๋ค๊ณ ์ถ์ผ๋ฉด ์ด๋ป๊ฒ ํด์ผํ ๊น??
๋๋๊ฒ๋ ์ฐ๋ฆฐ x86 machine์ผ๋ก RISC-V binaries๋ฅผ ๋ง๋ค ์ ์๋ค. ์ด๋ป๊ฒ??
Cross Compiler๋ฅผ ํตํด!!!! - Cross Compiler๋ ์ปดํ์ผ๋ฌ๊ฐ ์คํ๋๋ ํ๋ซํผ์ด ์๋๋ผ ๋ค๋ฅธ ํ๋ซํผ์ executable code๋ฅผ ๋ง๋ค ์ ์๋ ์ปดํ์ผ๋ฌ์ด๋ค.
์ฐ๋ฆฌ๋ ์์ ์์ RISC-V ๋ฅผ ์ธ๊ฑฐ๊ธฐ ๋๋ฌธ์ RISC-V cross compiler๋ฅผ ์ด์ฉํด์ RISC-V ์ฝ๋๋ฅผ ๋ง๋ค์ด ๋ผ ๊ฒ์ (์ดํด๋ฆฝ์ค ์ฌ์ฉ) ๊ทธ๋ฆฌ๊ณ ์ด ์ฝ๋๋ฅผ RISC-V Simulator์ธ Jupiter์์ ๋๋ ค๋ณผ ๊ฒ!
'๐ก๐ธ๐ธ๐ถ5: ๐ฆ๐๐๐๐ถ ๐ฐ๐๐พ๐ > Computer Architecture(COSE222)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์ปดํจํฐ๊ตฌ์กฐ] CH4. RISC-V & RISC-V Instruction #3 (0) | 2021.10.16 |
---|---|
[์ปดํจํฐ๊ตฌ์กฐ] CH4. RISC-V & RISC-V Instruction #2 (0) | 2021.10.13 |
[์ปดํจํฐ๊ตฌ์กฐ] CH4. RISC-V & RISC-V Instruction #1 (0) | 2021.10.09 |
[์ปดํจํฐ๊ตฌ์กฐ] CH3. Performance (0) | 2021.10.09 |
[์ปดํจํฐ๊ตฌ์กฐ] CH1. Computer and Technology (0) | 2021.10.08 |