8086 と 8088 は 16 ビット プロセッサで、レジスタの幅はそれぞれ 16 ビットです。(いくつかの命令は、div 入力と mul 出力のように、DX と AX の組み合わせを 32 ビット整数として扱います。)
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 (16 進数) でメモリにアクセスする場合、DS = 1230h および SI = 0045h を設定できます。このようにして、1 つのレジスタで 16 ビットだけではなく、20 ビットの線形アドレスを形成できます。(これはリアル モードに適用されます。プロテクト モードではセグメンテーションが異なります。)
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).