8086 and 8088 are 16-bit processors - each of them has a width of 16 bits. (In a few instructions, the combination of DX and AX is treated as a 32-bit integer, such as div input and mul output.)
Note that the 8086 has a 16-bit data bus; The 8088 has an 8-bit data bus. (Thus, loading / saving a 16-bit word takes 2 clock cycles of the bus. Addresses are still 20-bit for both.)
GENERAL PURPOSE OF REGISTRATION
The 8086 processor has 8 general-purpose registers, each of which has its own name:
AX - battery register (divided by 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 - base address register (divided by BH / BL).
Offset address relative to DS by default
CX - account register (divided by 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 - data register (divided into DH / DL):
DX:AX concatenated into 32-bit register for some MUL and DIV operations Specifying ports in some IN and OUT operations
SI - source index register:
Can be used for pointer addressing of data Used as source in some string processing instructions Offset address relative to DS by default
DI - destination index register:
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 - base pointer:
Primarily used to access parameters and locals on the stack Offset address relative to SS
SP - stack pointer:
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
SEGMENT REGISTERS
- CS - indicates a segment containing the current program.
- DS - usually indicates the segment where the variables are defined.
- ES is an optional segment register, it is up to the encoder to determine its use.
- SS - indicates a segment containing a stack.
Although you can store any data in segment registers, this is not a good idea. Segment registers have a special purpose - to indicate available blocks of memory.
Segment registers work together with a general register to access any memory value. For example, if we want to access memory at the physical address 12345h (hexadecimal), we could set DS = 1230h and SI = 0045h. Thus, we can form 20-bit linear addresses instead of 16-bit with one register. (This is applicable in real mode; in protected mode, the segmentation is different.)
The processor calculates the physical address by multiplying the segment register by 10h and adding a general purpose register (1230h * 10h + 45h = 12345h):
An address formed from 2 registers is called an effective address.
By default, the BX, SI, and DI registers work with the DS segment register;
BP and SP work with SS segment register.
Other general purpose registers cannot form an effective address.
In addition, although BX can form an effective address, BH and BL cannot.
SPECIAL REGISTRATION PURPOSES
IP - instruction pointer:
Always points to next instruction to be executed Offset address relative to CS
The IP register always works with the CS segment register and indicates the instruction that is being executed.
FLAG REGISTRATION
Flags Register - determines the current state of the processor. They are automatically modified by the CPU after mathematical operations, which allows you to determine the type of result and determine the conditions for transferring control to other parts of the program. Generally, you cannot access these registers directly.
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).