- rax is the 64-bit, "long" size register. It was added in 2003 during the transition to 64-bit processors.
- eax is the 32-bit, "int" size register. It was added in 1985 during the transition to 32-bit processors with the 80386 CPU. I'm in the habit of using this register size, since they also work in 32 bit mode, although I'm trying to use the longer rax registers for everything.
- ax is the 16-bit, "short" size register. It was added in 1979 with the 8086 CPU, but is used in DOS or BIOS code to this day.
- al and ah are the 8-bit, "char" size registers. al is the low 8 bits, ah is the high 8 bits. They're pretty similar to the old 8-bit registers of the 8008 back in 1972.
레지스터의 종류
Name | Notes | Type | 64-bit long |
32-bit int |
16-bit short |
8-bit char |
rax | Values are returned from functions in this register. 누산기(accumulator) 레지스터 |
scratch | rax | eax | ax | ah and al |
rcx | Typical scratch register. Some instructions also use it as a counter. 카운터(counter) 레지스터 |
scratch | rcx | ecx | cx | ch and cl |
rdx | Scratch register. 데이터(data) 레지스터 |
scratch | rdx | edx | dx | dh and dl |
rbx |
Preserved register: don't use it without saving it! 베이스(base) 레지스터 |
preserved | rbx | ebx | bx | bh and bl |
rsp |
The stack pointer. Points to the top of the stack (details coming soon!) | preserved | rsp | esp | sp | spl |
rbp |
Preserved register. Sometimes used to store the old value of the stack pointer, or the "base". | preserved | rbp | ebp | bp | bpl |
rsi | Scratch register. Also used to pass function argument #2 in 64-bit Linux 근원지 인덱스(source index) 레지스터 |
scratch | rsi | esi | si | sil |
rdi | Scratch register. Function argument #1 in 64-bit Linux 목적지 인덱스(destination index) 레지스터 |
scratch | rdi | edi | di | dil |
r8 | Scratch register. These were added in 64-bit mode, so they have numbers, not names. | scratch | r8 | r8d | r8w | r8b |
r9 | Scratch register. | scratch | r9 | r9d | r9w | r9b |
r10 | Scratch register. | scratch | r10 | r10d | r10w | r10b |
r11 | Scratch register. | scratch | r11 | r11d | r11w | r11b |
r12 |
Preserved register. You can use it, but you need to save and restore it. | preserved | r12 | r12d | r12w | r12b |
r13 |
Preserved register. | preserved | r13 | r13d | r13w | r13b |
r14 |
Preserved register. | preserved | r14 | r14d | r14w | r14b |
r15 |
Preserved register. | preserved | r15 | r15d | r15w | r15b |
Conditioion Code Register(상태 레지스터)
상태 레지스터, 플래그 레지스터 라고도 불리며 1비트 레지스터로 구성되어 있다. (t = a+b)
CF | Carry flag(올림수) | if carry out from most significant bit (unsigned overflow) |
SF | Sign flag(부호) | t == 0 |
ZF | Zero flag | t < 0 |
OF | Overflow flag | two's complement (signed) overflow (a > 0 && b > 0 && t < 0) || (a < 0 && b < 0 && t > 0) |
레지스터 인자 전달
-리눅스 ELF 환경에서는 다음과 같은 순서로 함수의 인자를 전달받는다
Parameter 1 - rdi
Parameter 2 - rsi
Parameter 3 - rdx
Parameter 4 - rcx
Parameter 5 - r8(범용레지스터)
Parameter 6 - r9(범용레지스터)
-인자가 7개 이상일경우 스택을 사용한다.
Parameter 7 - (%rsp)
Parameter 8 - 0x8(%rsp)
system call - %rax
'CS' 카테고리의 다른 글
[DataStructure] Bloom filter (0) | 2022.08.22 |
---|---|
[DataStructure] B-tree vs LSM-tree (0) | 2022.08.22 |
[OS] 2Q - A low overhead high-performance buffer management replacement algorithm (0) | 2022.08.22 |
[Computer Architecture] - Compilation system (0) | 2022.08.22 |
[Computer Architecture] - ISA(Instruction Set Architecture)와 Abstraction(추상화) (0) | 2022.08.22 |