Processor register
프로세서 레지스터(영어: processor register, 순화 용어: 기록기) 또는 단순히 레지스터는 컴퓨터의 프로세서 내에서 자료를 보관하는 아주 빠른 기억 장소이다. 일반적으로 현재 계산을 수행중인 값을 저장하는 데 사용된다. 대부분의 현대 프로세서는 메인 메모리에서 레지스터로 데이터를 옮겨와 데이터를 처리한 후 그 내용을 다시 레지스터에서 메인 메모리로 저장하는 로드-스토어 설계를 사용하고 있다.
레지스터는 메모리 계층의 최상위에 위치하며, 가장 빠른 속도로 접근 가능한 메모리이다. 최신 프로세서에서 레지스터는 대개 레지스터 파일로 구현되지만, 과거에는 플립플롭, 마그네틱 코어, 박막 필름 메모리 등으로 구현되기도 했다.
Segment
- Segment:Offset
-
물리적 주소 = Segment x 0x10 + offset
80386+ Register Set
X86-registers.png
아래의 내용은 EAX, EBX와 같이 'Extended'를 의미하는 E는 제외하여 표현한다.
레지스터명이 R로 시작할 경우 프로세스가 64bit 환경이라 그렇다. 32bit 환경은 E로 시작한다.
General purpose registers
- AX: 수학 연산, I/O 연산, INT 21.
- BX: Base 또는 Pointer.
- CX: 루프 및 반복
- DX: 다양한 데이터, 문자 출력
모든 일반적인 목적을 위한 레지스터는 16비트로 되어 있으며, 8비트 레지스터로 나누어질 수 있다. 예를 들어, AX는 AL 그리고 AH로 나누어질 수 있다. L은 low를 의미하고, H는 high를 의미한다. 만약 AX에 어떤 값을 부여하면 AH가 그 값의 첫 부분을 포함하고, AL은 마지막 부분을 포함한다.
386이 나왔을 때 4개의 새로운 레지스터가 추가되었는데, 그것은 EAX, EBX, ECX, EDX이다. 여기서 E는 32비트로 Extended(확장됨)를 의미한다. 그리고 알아둘 것은 <span style="color:red">EAH 또는 EAL라는 것은 없다.
Index registers
- SI (Source Index): 문자열/배열의 소스를 지정하기 위해 사용됨.
- DI (Destination Index): 문자열/배열의 목적지를 지정하기 위해 사용됨.
- IP (Instruction Pointer): 다음 명령의 주소를 저장하고, 그래서 직접적으로 변경될 수 없음.
Stack registers
- BP (Base Pointer): 스택 오퍼레이션을 위해 SP 와 연결되어 사용됨.
- SP (Stack Pointer)
Segment registers
- CS (Code Segment): 코드를 저장하는 메모리 블록
- DS (Data Segment): 데이터를 저장하는 메모리 블록
- SS (Stack Segment): 루틴으로부터 리턴 어드레스를 저장하기 위해 프로세서에 의해 사용되는 레지스터
- ES, FS, GS: 특수 목적으로 사용됨.
Special purpose
- IP (Instruction Pointer): 실행된 명령의 offset 를 가지고 있음.
EFLAGS Register (EFL)
The EFLAGS is a 32-bit register used as a collection of bits representing Boolean values to store the results of operations and the state of the processor.
The names of these bits are:
31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ID | VIP | VIF | AC | VM | RF |
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0 | NT | IOPL | OF | DF | IF | TF | SF | ZF | 0 | AF | 0 | PF | 1 | CF |
The bits named 0 and 1 are reserved bits and shouldn't be modified.
The different use of these flags are: | |
0. | CF : Carry Flag. Set if the last arithmetic operation carried (addition) or borrowed (subtraction) a bit beyond the size of the register. This is then checked when the operation is followed with an add-with-carry or subtract-with-borrow to deal with values too large for just one register to contain. |
2. | PF : Parity Flag. Set if the number of set bits in the least significant byte is a multiple of 2. |
4. | AF : Adjust Flag. Carry of Binary Code Decimal (BCD) numbers arithmetic operations. |
6. | ZF : Zero Flag. Set if the result of an operation is Zero (0). |
7. | SF : Sign Flag. Set if the result of an operation is negative. |
8. | TF : Trap Flag. Set if step by step debugging. |
9. | IF : Interruption Flag. Set if interrupts are enabled. |
10. | DF : Direction Flag. Stream direction. If set, string operations will decrement their pointer rather than incrementing it, reading memory backwards. |
11. | OF : Overflow Flag. Set if signed arithmetic operations result in a value too large for the register to contain. |
12-13. | IOPL : I/O Privilege Level field (2 bits). I/O Privilege Level of the current process. |
14. | NT : Nested Task flag. Controls chaining of interrupts. Set if the current process is linked to the next process. |
16. | RF : Resume Flag. Response to debug exceptions. |
17. | VM : Virtual-8086 Mode. Set if in 8086 compatibility mode. |
18. | AC : Alignment Check. Set if alignment checking of memory references is done. |
19. | VIF : Virtual Interrupt Flag. Virtual image of IF. |
20. | VIP : Virtual Interrupt Pending flag. Set if an interrupt is pending. |
21. | ID : Identification Flag. Support for CPUID instruction if can be set. |
Segmentation
We are using the 32-bit segment addressing feature of the 486. Using 32-bit addressing as opposed to 16-bit addressing gives us many advantages:
- No need to worry about 64K segments. Segments can be 4 gigabytes in length under the 32-bit architecture.
- 32-bit segments have a protection mechanism for segments, which you have the option of using.
You don't have to deal with any of that ugly 16-bit crud that is used in other operating systems for the PC, like DOS or OS/2; 32-bit segmentation is really a thing of beauty in comparison to that.
i486 addresses are formed from a segment base address plus an offset. To compute an absolute memory address, the i486 figures out which segment register is being used, and uses the value in that segment register as an index into the global descriptor table (GDT). The entry in the GDT tells (among other things) what the absolute address of the start of the segment is. The processor takes this base address and adds on the offset to come up with the final absolute address for an operation. You'll be able to look in a 486 manual for more information about this or about the GDT's organization.
i486 has 6 16-bit segment registers, listed here in order of importance:
- CS (Code Segment Register): Added to address during instruction fetch.
- SS (Stack Segment Register): Added to address during stack access.
- DS (Data Segment Register): Added to address when accessing a memory operand that is not on the stack.
- ES, FS, GS (Extra Segment Registers): Can be used as extra segment registers; also used in special instructions that span segments (like string copies).
See also
Favorite site
- Wikipedia (en) Processor register
- Memory Management : Segmentation 1 1
- Rude's Factory :: 어셈블리: 범용 레지스터, 세그먼트 레지스터, 포인터 레지스터, 인덱스 레지스터, 플래그 레지스터 2
- Rude's Factory :: 어셈블리: 세그먼트(segment)란?
- [추천] 범용 레지스터: EAX, ECX, EDX, ESI, EDI, ESP, EBP
- Register 정리
- [추천] Basic Disassemble 1 3
- 채워가는 블로그 :: 레지스터 정리