<Levels of Program Code>
1. High-level code
closer to the problem domain
better productivity & portability
2. Assembly code
Human-readable representation of the machine code
Can use symbolic names (labels)
3. Machine code
Instructions encoded in binary format
No symbols (doesn't have labels identified by human beings)
컴퓨터 하드웨어에게 일을 시키려면 하드웨어가 알아들을 수 있는 언어로 말을 해야 한다.
컴퓨터 언어에서 단어를 명령어(instruction) 이라 하고 그 어휘를 명령어 집합(instruction set)이라고 한다.
<Instruction Set>
- Arithmetic operations (add, sub, ...)
- Logic operations (and, or, xor, ...)
- Multiplicaiton / Division
(much more complex than add / sub in digital system -> treated seperately)
- Load from memory / Store to memory
- Jump / branch
- Exception handling
- Floating point
이번 학기 나는 ISA (Instruction Set Architecture) 중에서 RISC-V 공부할 거얌
<Arithmetic Operations>
Add and subtract operations have three operands (one destination and two sources)
add a, b, c # a <- b + c
두 변수 b와 c를 더해서 그 합을 a에 넣으라고 컴퓨터에 지시하는 것
<Example>
Suppose you have "add" and "sub" instructions with two operands.
Example C code:
f = (g + h) - (i + j); // 4 operands (g, h, i, j)
simple operation in C code will be broken down into multiple instructions by CPU
Corresponding RISC-V assembly code:
add t0, g, h # t0 = g + h
add t1, i, j # t1 = i + j
sub f, t0, t1 # f = t0 - t1
in assembly program, we always have to let the CPU know where those intermediate values have to be stored.
<Registers>
small, high-speed storage inside the CPU
(CPU cannot directly access data inside the storage or memory
-> brought into register in CPU and then CPU can access those data)
registers hold data during the execution
RISC-V ISA has a 32 registers and the size of each register is 32bits.
The collection of those 32 registers is called "register file"
Each register has its own number(name): x0 to x31
A 32-bit value is referred to as a "word"
<Memory>
Memory is the main storage for program data
To apply arithmetic operations on data in memory...
- Load: memory -> registers
- Compute: (source) register -> (destination) register
- Store: register -> memory
Memory is byte addressed (each address: 1 byte(8-bit))
When we are accessing main memory, we cannot name all of the locations with unique name
because memory space is so large.
-> locations of data items in memory will be pointed by the memory address
(that's why there is pointer in high level languages)
아까 봤던 example C code에서
f = (g + h) - (i + j);
f, g, h, i, j를 x19, x20, x21, x22, x23에 있다고 가정해보자.
이를 RISC-V assembly code로 바꾸면?
add x5, x20, x21
add x6, x22, x23
sub x19, x5, x6
여기서 x5, x6는 temporaries,
x19는 saved registers이다.
'SKKU SW > Computer Architecture' 카테고리의 다른 글
[컴퓨터구조] Logical operations (0) | 2023.04.14 |
---|---|
[컴퓨터구조] Immediate Operands, Load Immediate Value (0) | 2023.04.14 |
1.0E6이 뭐야 (0) | 2023.04.14 |
[컴퓨터구조] SPEC CPU Benchmark + 전력 장벽 (0) | 2023.04.13 |
[컴퓨터구조] Performance (0) | 2023.04.13 |