8086 和 8088 是 16 位处理器 - 它们的寄存器均为 16 位宽度。 (一些指令将 DX 和 AX 的组合视为 32 位整数,如 div 输入和 mul 输出。)
注意8086有16位数据总线; 8088 有一个 8 位数据总线。 (因此加载/存储 16 位字需要 2 个总线周期。两者的地址仍然是 20 位。)
通用寄存器
8086 CPU有8个通用寄存器,每个寄存器都有自己的名字:
AX——累加器寄存器(分为AH/AL):
Generates shortest machine code: short-form encodings exist
Arithmetic, logic and data transfer
One number must be in AL or AX
Multiplication & Division
Input & Output
BX——基址寄存器(分为BH/BL)。
Offset address relative to DS by default
CX——计数寄存器(分为CH/CL):
The LOOP instruction uses it implicitly as a counter
Repetitive operations on strings with the REP command
Count (in CL) of bits to shift and rotate
DX——数据寄存器(分为DH/DL):
DX:AX concatenated into 32-bit register for some MUL and DIV operations
Specifying ports in some IN and OUT operations
SI - 源索引寄存器:
Can be used for pointer addressing of data
Used as source in some string processing instructions
Offset address relative to DS by default
DI - 目标索引寄存器:
Can be used for pointer addressing of data
Used as destination in some string processing instructions as ES:DI
Offset address relative to DS outside of string instructions
BP - 基指针:
Primarily used to access parameters and locals on the stack
Offset address relative to SS
SP - 堆栈指针:
Always points to top item on the stack
Offset address relative to SS (but can't be used in 16-bit addressing modes)
Should always points to word (byte at even address)
An empty stack will have SP = FFFEh
分部寄存器
- CS - 指向包含当前程序的段。
- DS - 通常指向定义变量的段。
- ES - 额外的段寄存器,由编码器定义其用途。
- SS - 指向包含堆栈的段。
虽然可以在段寄存器中存储任何数据,但这绝不是一个好主意。段寄存器有一个非常特殊的用途——指向可访问的内存块。
段寄存器与通用寄存器一起工作以访问任何内存值。例如,如果我们想访问物理地址 12345h(十六进制)的内存,我们可以设置 DS = 1230h 和 SI = 0045h。通过这种方式,我们可以形成 20 位线性地址,而不是单个寄存器的 16 位。 (这适用于实模式;在保护模式中分段是不同的。)
CPU 通过将段寄存器乘以 10h 并在其上加上通用寄存器(1230h * 10h + 45h = 12345h)来计算物理地址:
由2个寄存器组成的地址称为有效地址。
默认情况下,BX、SI 和 DI 寄存器与 DS 段寄存器一起使用;
BP 和 SP 与 SS 段寄存器一起工作。
其他通用寄存器不能形成有效地址。
另外,虽然BX可以形成有效地址,但BH和BL不能。
特殊用途寄存器
IP——指令指针:
Always points to next instruction to be executed
Offset address relative to CS
IP寄存器总是和CS段寄存器一起工作,它指向当前正在执行的指令。
标志注册
标志寄存器 - 确定处理器的当前状态。它们在数学运算后由 CPU 自动修改,这允许确定结果的类型,并确定将控制权转移到程序其他部分的条件。
通常你不能直接访问这些寄存器。
Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example when you add bytes 255 + 1 (result is not in range 0...255). When there is no overflow this flag is set to 0.
Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in (the low 8 bits of a) result, and to 0 when there is odd number of one bits.
Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow (carry-out) for low nibble (4 bits).
Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is set to 0.
Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. (This flag takes the value of the most significant bit.)
Trap Flag (TF) - Used for on-chip debugging.
Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external devices.
Direction Flag (DF) - this flag is used by some instructions to process arrays. When this flag is set to 0 the processing is done forward, when this flag is set to 1 the processing is done backward.
Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127).