This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:papc:chapter_6_3 [2025/12/22 11:34] – [x86 registers] ktokarz | en:multiasm:papc:chapter_6_3 [2026/04/01 14:03] (current) – [ZMM registers] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Register Set ====== | ||
| + | As x86 processors evolved, the set of available registers and their size expanded. Newer processors added more general-purpose registers, and new registers related to the FPU and vector extensions were added. In this chapter, we discuss the registers available to the programmer, from the 8086 up to modern 64-bit processors. | ||
| + | ===== x86 registers ===== | ||
| + | The 8086 processor has seven general-purpose registers for data storage, data manipulation and indirect addressing. Four registers: AX, BX, CX and DX can be accessed in two 8-bit halves. The lower half has the " | ||
| + | <figure gpregistresx86> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | They have some special functions, as listed below. | ||
| + | * AX - Accumulator, | ||
| + | * BX - Base register, used for indirect addressing in base addressing mode. | ||
| + | * CX - Counter register, used for iteration counting for loops and repeated instructions. | ||
| + | * DX - Data register, used as an extension of the accumulator, | ||
| + | * SI - Source index, used for indirect index addressing of source data tables or strings. | ||
| + | * DI - Destination index, used for indirect index addressing of destination data tables or strings. | ||
| + | * BP - Base pointer, often used for accessing data on the stack without the need for the stack pointer modification. | ||
| + | |||
| + | Some registers have special purposes. | ||
| + | * SP - Stack pointer, used for stack manipulation, | ||
| + | * IP - Instruction pointer, points to the next instruction to be executed; sometimes called program counter. | ||
| + | These registers are presented in Fig {{ref> | ||
| + | |||
| + | <figure spregistresx86> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Every processor has a register containing bits used to inform the software about the state of the ALU, about the result of the last arithmetic or logic operation, and used to control the behaviour of the CPU. In x86, it is called the Flags register, and is shown in fig {{ref> | ||
| + | |||
| + | <figure flagsx86> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The meaning of informational flags is as follows: | ||
| + | * CF - Carry flag, set if an operation generates a carry or borrow; for example, if the result of an addition is larger than 16 bits. Used for unsigned arguments. | ||
| + | * PF - Parity flag, set if the result of an operation contains an even number of bits equal to " | ||
| + | * AF - Auxiliary Carry flag, similar to CF but informs about the carry or borrow from the 3rd to the 4th bit. It is used for BCD calculations. | ||
| + | * ZF - Zero flag, set if the result of an operation is zero. | ||
| + | * SF - Sign flag, it is a copy of the most significant bit of the result. | ||
| + | * OF - Overflow flag, set if the result of an operation is too large or small to fit in the destination operand. Used for signed arguments. | ||
| + | |||
| + | Control flags allow modification of the processor' | ||
| + | * TF - Trap flag, used for debugging to execute a program one instruction at a time. | ||
| + | * IF - Interrupt flag, if set, interrupts are enabled. | ||
| + | * DF - Direction flag, determines the direction of string operations. If cleared, string operations work from lower to higher addresses; if set, they operate in the opposite direction. | ||
| + | | ||
| + | The 8086, being a 16-bit processor, can address memory in real mode only (please refer to section " | ||
| + | * CS - Code segment register, used together with IP to access the instruction in the code segment. | ||
| + | * DS - Data segment register, used to access the default data segment. | ||
| + | * ES - Extra segment register, used to access an additional data segment. | ||
| + | * SS - Stack segment register, used together with SP or BP to access elements on the stack. | ||
| + | Segment registers are shown in Fig {{ref> | ||
| + | |||
| + | <figure segmentregsx86> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | ===== IA-32 registers ===== | ||
| + | Starting from the 80386 processor general-purpose registers, stack pointer, instruction pointer, and flags register were extended to 32 bits. Inter added an extra 16 bits to each of them, leaving the possibility to access the lower half as in previous models. For example, an accumulator can be accessed as 32-bit EAX, 16-bit AX, and 8-bit AH and AL. The resulting register set is shown in Fig {{ref> | ||
| + | |||
| + | <figure GPregsIA32> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Similarly, the IP and flags registers were extended to 32-bit size (fig.{{ref> | ||
| + | |||
| + | |||
| + | <figure eflagsIA32> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | In 32-bit machines, two additional segment registers were added: FS and GS (fig.{{ref> | ||
| + | |||
| + | |||
| + | |||
| + | <figure segregsIA32> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | ===== x64 registers ===== | ||
| + | The 64-bit extension to the IA-32 architecture was proposed by AMD. Registers were extended to 64 bits, and additionally, | ||
| + | |||
| + | <figure GPregsx64> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure newregsx64> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | ===== FPU registers ===== | ||
| + | The floating point unit, sometimes referred to as x87, works using eight 80-bit data registers, as presented in figure {{ref> | ||
| + | |||
| + | |||
| + | <figure fpudataregs> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | There are also control and status registers in the Floating Point Unit as presented in figure {{ref> | ||
| + | |||
| + | <figure fpucontrolregs> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | FPU instruction pointer, data pointer and last opcode registers are used for cooperation with the main processor. The Tag register (figure {{ref> | ||
| + | |||
| + | <figure fputagreg> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The Status Word register contains information about the FPU's current state, including the top of the stack, exception flags, and condition codes (figure {{ref> | ||
| + | |||
| + | <figure fpustatereg> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The Control Word register (figure {{ref> | ||
| + | |||
| + | <figure fpucontrolreg> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | ===== MMX registers ===== | ||
| + | MMX instructions are executed with the use of 64-bit packed data. Intel decided to map MMX registers onto the existing FPU registers. The MMX unit has 8 registers named MM0 - MM7, as presented in figure {{ref> | ||
| + | |||
| + | <figure mmxregs> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | ===== XMM registers ===== | ||
| + | SSE instructions are executed with the use of 128-bit packed data. To perform calculations, | ||
| + | |||
| + | To control the behaviour and to provide information about the status of the SSE unit, the MXCSR register is implemented (figure {{ref> | ||
| + | |||
| + | <figure mxcsrreg> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | ===== YMM registers ===== | ||
| + | The YMM registers are the 256-bit extension to the XMM registers. They are introduced to implement the AVX set of instructions. Additionally, | ||
| + | ===== ZMM registers ===== | ||
| + | ZMM registers are the further extension of XMM registers to 512 bits. In 64-bit machines, 32 of such registers are available. | ||
| + | XMM are the physical lower halves of YMM, which are the lower halves of ZMM. Anything written to the XMM register appears in part of the YMM and ZMM registers as presented in figure {{ref> | ||
| + | |||
| + | <figure xyzmmregs> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | Together with AVX extension and ZMM registers, eight 16-bit opmask registers were introduced to x64 processors. They can be used, e.g. to provide conditional execution or mask several elements of vectors in AVX instructions. | ||
| + | |||
| + | |||
| + | |||
| + | ===== Additional registers ===== | ||
| + | In the x64 architecture, | ||
| + | Different processors have different sets of model-specific registers, MSR. There are also machine check registers MCR. They are used to control and report on processor performance, | ||