Chapter 2.2: 8086 Registers

Microprocessors
The register setAX · BX · CX · DXSP · BP · SI · DISegment registers and IPThe FLAGS registerStatus and control flagsInstructions that change flags
Sercan KÜLCÜ · Giresun University · Computer Engineering

Introduction

Learning Outcomes

Register set

List the 14 registers of the 8086 by group and explain their 8- and 16-bit use.

Special roles

Know the implicit roles of AX, BX, CX, DX, SP, BP, SI and DI in instructions.

Flags

Explain which results set CF, ZF, SF, OF, PF and AF; know how DF, IF and TF control the processor.

Register pairs

Know which accesses use the pairs CS:IP, SS:SP, SS:BP, DS:SI and ES:DI.

The Register Set

What Is a Register?

  • A register is a small, very fast storage cell inside the processor.
  • 8086 registers are 16 bits wide; four of them can also be split into two 8-bit halves.
  • A memory access takes several clock cycles over the external bus; a register access is almost free.
  • Registers hold temporary data, addresses, counters and results.
  • Most instructions need at least one operand in a register: the 8086 has no memory-to-memory MOV or ADD.
CPUAXBX…≈ 1 cycleMemorybus4+ cycles
The 8086 has 14 registers: 4 general-purpose data registers, 4 pointer/index registers, 4 segment registers, the instruction pointer (IP) and the FLAGS register.

The Register Set

The 8086 Register Set

General-purpose (data) registers15870AXAHALaccumulatorBXBHBLbaseCXCHCLcounterDXDHDLdataPointer and index registersSPstack pointerBPbase pointerSIsource indexDIdestination indexSegment registersCScodeDSdataSSstackESextraSpecial registersIPinstruction pointerFLAGSFLAGS register

All are 16 bits. Only AX, BX, CX and DX split into halves (AH/AL …); SP, BP, SI, DI and the segment registers have no 8-bit parts. In this course the eight registers AX…DI count as the general-purpose registers.

The Register Set

General-Purpose Registers

They hold temporary data. Most instructions accept any of them, but some instructions use a particular register implicitly.

RegisterName8-bit halvesImplicit use (example)
AXAccumulatorAH, ALMUL, DIV, IN, OUT, LODS/STOS
BXBaseBH, BLmemory addressing [BX], XLAT
CXCounterCH, CLLOOP, REP, shift count in CL
DXDataDH, DLhigh half of MUL/DIV, port address
SPStack Pointer—PUSH, POP, CALL, RET
BPBase Pointer—stack frame [BP+n]
SISource Index—string source DS:SI
DIDestination Index—string destination ES:DI

The Register Set · Step through the code

AX = AH : AL — 8-Bit and 16-Bit Use

MOV AX, 1234h   ; AH=12h, AL=34h
MOV AL, 0FFh    ; low half only
ADD AL, 1       ; 8-bit add
MOV AX, 12FFh
ADD AX, 1       ; 16-bit add

Writing one 8-bit half does not change the other. The carry of an 8-bit operation goes to CF, not into the other half.

AXAH = 12hAL = 34h0001 00100011 0100150

AX gets 1234h: high byte AH = 12h, low byte AL = 34h.

AXAH = 12hAL = FFh0001 00101111 1111150

Only AL changes; AH is kept → AX = 12FFh.

AXAH = 12hAL = 00h0001 00100000 0000150

FFh + 1 = 100h does not fit in 8 bits: AL = 00h, CF = 1, ZF = 1. The carry does not reach AH; AX = 1200h.

AXAH = 12hAL = FFh0001 00101111 1111150

AX is set back to 12FFh.

AXAH = 13hAL = 00h0001 00110000 0000150

This time the add is 16-bit: 12FFh + 1 = 1300h; the carry moved into AH, CF = 0.

General-Purpose Registers

AX — Accumulator

  • 16 bits wide; splits into two 8-bit parts, AH (high) and AL (low).
  • 8-bit instructions can use AH and AL separately.
  • Used mostly in arithmetic and logic instructions.
  • Some instructions use AX/AL implicitly: MUL, DIV, IN/OUT, CBW, DAA, LODSB/STOSB.
  • With AX, many instructions encode one byte shorter (e.g. ADD AX, imm16).
ADD AX, AX     ; AX = AX + AX
MOV AX, 0005h
ADD AX, AX     ; AX = 000Ah
MOV AH, 4Ch    ; DOS: exit
INT 21h

Adding AX to itself is the same as multiplying it by 2.

General-Purpose Registers

BX — Base

  • 16 bits; splits into two 8-bit halves, BH and BL.
  • The only data register that can hold an offset in indirect memory addressing: [BX], [BX+SI], [BX+4].
  • Holds the base address of arrays and tables (matrices).
  • Addressing as [AX], [CX] or [DX] does not exist on the 8086.
DS segment3Ah04FFh25h0500h17h0501h9Ch0502hBL = 25hMOV BL, [0500h]
MOV BL, [500h] does not put the number 500h in BL; it reads the byte at DS:0500h. To load the number, drop the brackets: MOV BX, 0500h.

General-Purpose Registers · Step through the code

Indirect Access with BX

MOV BX, 0500h     ; BX = address
MOV AL, [BX]      ; AL = [0500h]
MOV DL, [0501h]   ; direct address
ADD AL, DL        ; AL = 25h + 17h
MOV [BX+2], AL    ; [0502h] = AL
25h0500h17h0501h00h0502h9Ch0503hBX

BX gets the number 0500h; BX can now serve as an address (a pointer).

25h0500h17h0501h00h0502h9Ch0503hBX

[BX]: the byte BX points to is read → AL = 25h.

25h0500h17h0501h00h0502h9Ch0503hBX

The same kind of access works with a constant address: DL = [0501h] = 17h.

25h0500h17h0501h00h0502h9Ch0503hBX

AL = 25h + 17h = 3Ch.

25h0500h17h0501h3Ch0502h9Ch0503hBX

AL is written to [BX+2] = 0502h. Memory changed; BX did not.

General-Purpose Registers

CX — Counter

  • 16 bits; splits into two 8-bit halves, CH and CL.
  • Used for loops (LOOP), repeats (REP) and counting.
  • LOOP label: first CX ← CX − 1, then jump to the label if CX ≠ 0. Flags are not affected.
  • In shift and rotate instructions, a count greater than 1 goes in CL: SHL AX, CL.
  • JCXZ: jump if CX = 0 (guards against an empty loop).
MOV CX, 0005h   ; 5 passes
NEXT:
  ; ... body ...
  LOOP NEXT      ; CX--, jump if CX≠0
Entering the loop with CX = 0 makes the first LOOP set CX to FFFFh, and the loop runs 65536 times.

General-Purpose Registers · Step through the code

CX and LOOP: 5 + 4 + 3 + 2 + 1

MOV CX, 5          ; counter
MOV AX, 0          ; sum
AGAIN: ADD AX, CX
LOOP AGAIN         ; CX--, jump if ≠0
MOV DX, AX         ; result

The loop body runs with CX = 5, 4, 3, 2, 1; it does not run with CX = 0.

CX = 5: the loop will run 5 times.

The sum starts at AX = 0.

AX = AX + CX → 0 + 5 = 5.

LOOP: CX = 5 → 4; not zero, jump to AGAIN.

AX = AX + CX → 5 + 4 = 9.

LOOP: CX = 4 → 3; not zero, jump to AGAIN.

AX = AX + CX → 9 + 3 = 12.

LOOP: CX = 3 → 2; not zero, jump to AGAIN.

AX = AX + CX → 12 + 2 = 14.

LOOP: CX = 2 → 1; not zero, jump to AGAIN.

AX = AX + CX → 14 + 1 = 15.

LOOP: CX = 1 → 0; no jump, the loop exits.

The result is copied to DX: 5+4+3+2+1 = 15 = 000Fh.

General-Purpose Registers

DX — Data

  • 16 bits; splits into two 8-bit halves, DH and DL.
  • A 16-bit multiply gives a 32-bit result: DX holds the high word, AX the low word → DX:AX.
  • In a 16-bit divide the dividend is DX:AX; the quotient goes to AX, the remainder to DX.
  • I/O port numbers above 255 are given in DX: OUT DX, AL.
  • In DOS calls (INT 21h) it holds a string address: LEA DX, msg.
MUL BX (16 bit × 16 bit)AX×BXDX (high)AX (low)32-bit product
Example: MUL BX → DX:AX = AX × BX. The 8-bit MUL BL gives AX = AL × BL and leaves DX alone.

General-Purpose Registers · Step through the code

DX:AX with MUL

MOV AX, 1234h
MOV BX, 0100h
MUL BX          ; DX:AX = AX*BX
MOV AX, 00FFh
MOV BL, 2
MUL BL          ; AX = AL*BL
MOV DX, 03F8h   ; port address
OUT DX, AL      ; write to port

MUL is an unsigned multiply; use IMUL for signed. After MUL, SF, ZF, PF and AF are undefined.

AX = 1234h.

BX = 0100h (256).

1234h × 0100h = 00123400h → DX = 0012h, AX = 3400h. The high half is nonzero, so CF = OF = 1.

AX = 00FFh; the old result is still in DX.

BL = 02h (BX = 0102h, BH unchanged).

8-bit product: FFh × 02h = 01FEh → AX. DX is unchanged; AH ≠ 0, so CF = OF = 1.

This time DX is a port number: 03F8h (the COM1 serial port).

FEh in AL is sent to port 03F8h. Ports above 255 require DX.

Pointer and Index Registers

SP — Stack Pointer

  • The 16-bit stack pointer holds the offset of the top item on the stack.
  • The address is always relative to the stack segment: the physical address is SS:SP.
  • The stack is LIFO: PUSH adds, POP removes; on the 8086 items are always 16 bits.
  • The stack grows downward in memory: PUSH first subtracts 2 from SP, then writes; POP first reads, then adds 2 to SP.
  • “SP = FFFEh on an empty stack” holds for .COM programs (DOS/emu8086 set SP to FFFEh); it is not a general rule.
SS segmentFFF6hFFF8hFFFAhFFFCh2222hFFFEh1111hSPgrowth

Pointer and Index Registers

BP — Base Pointer

  • The 16-bit base pointer marks a fixed position on the stack.
  • Memory accesses through BP use the SS segment by default: [BP+4] → SS:BP+4.
  • Used to access a procedure's stack parameters and local variables.
  • SP keeps changing with PUSH/POP; BP stays fixed during the procedure, so the parameter positions are known.
ADDP PROC
  PUSH BP
  MOV  BP, SP     ; frame base
  MOV  AX, [BP+4] ; 1st param
  POP  BP
  RET  2
ADDP ENDP

The classic procedure prologue: PUSH BP + MOV BP, SP.

Pointer and Index Registers

SI and DI — Index Registers

SI — Source Index
  • 16 bits; an offset in the data segment (DS).
  • Points to the data to be read.
  • The source in string instructions: MOVSB, CMPSB, LODSB → DS:SI.
  • Example: MOV SI, 2000h — points SI at a memory location.
DI — Destination Index
  • 16 bits; in string instructions, an offset in the extra segment (ES).
  • Points to where data will be written.
  • The destination in string instructions: MOVSW, STOSB, SCASB → ES:DI.
  • Example: MOV DI, 3000h — points DI at a memory location.
Outside string instructions, [SI] and [DI] are plain index registers using the DS segment. After each string step SI and DI move up or down by 1 (byte) or 2 (word), depending on the DF flag.

Pointer and Index Registers · Step through the code

Copying a String with SI and DI

CLD              ; DF=0: addresses go up
MOV SI, 0200h    ; source
MOV DI, 0300h    ; destination
MOV CX, 3        ; byte count
REP MOVSB        ; ES:[DI] ← DS:[SI]
0200h'A''B''C'—source0300h————dest

CLD: DF = 0 → SI and DI will increase on each step.

0200h'A''B''C'—SIsource0300h————dest

SI = 0200h: start of the string “ABC” to copy.

0200h'A''B''C'—SIsource0300h————DIdest

DI = 0300h: start of the destination area.

0200h'A''B''C'—SIsource0300h————DIdest

CX = 3: REP repeats at most 3 times.

0200h'A''B''C'—SIsource0300h'A'———DIdest

Pass 1: 'A' is copied; SI = 0201h, DI = 0301h, CX = 2.

0200h'A''B''C'—SIsource0300h'A''B'——DIdest

Pass 2: 'B' is copied; SI = 0202h, DI = 0302h, CX = 1.

0200h'A''B''C'—SIsource0300h'A''B''C'—DIdest

Pass 3: 'C' is copied; CX = 0 → REP ends.

Pointer and Index Registers

Segment Registers and IP

  • CS (code), DS (data), SS (stack), ES (extra): each holds the start of a 64 KB segment.
  • IP (instruction pointer): the offset within CS of the next instruction to execute.
  • IP cannot be written with MOV; only JMP, CALL, RET and interrupts change it.
  • A segment register cannot take an immediate value: you need MOV DS, AX.
PairUse
CS:IPnext instruction
SS:SPtop of stack
SS:BPstack frame
DS:BX, DS:SI, DS:DIdata
DS:SI → ES:DIstring instructions
Physical address (20 bits) = segment × 16 + offset. Multiplying by 16 appends a 0 to the hex number: with DS = 2000h and BX = 0500h, [BX] → 20000h + 0500h = 20500h.

The FLAGS Register

The FLAGS Register

  • Also called the status register; 9 of its 16 bits are used.
  • Describes the result of the last arithmetic/logic instruction executed.
  • Determines whether conditional jumps (JZ, JC, JG …) are taken.
0CF1–2PF3–4AF5–6ZF7SF8TF9IF10DF11OF12–13–14–15–status flag (set by the result)control flag (set by the programmer)
6 status flagsCF, PF, AF, ZF, SF, OF: set (1) or cleared (0) by the hardware according to the result.
3 control flagsDF, IF, TF: change how the processor runs; the programmer sets them with instructions such as CLD/STD and CLI/STI.

The FLAGS Register

SF — Sign Flag

  • The sign flag tells whether the result is negative or positive.
  • It is a copy of the result's most significant bit (MSB):
  • MSB = 1 → the number is negative (read as signed) → SF = 1.
  • MSB = 0 → the number is positive or zero → SF = 0.
  • The MSB is bit 7 for 8 bits, bit 15 for 16 bits.
Result (8 bits)MSBSF
00h … 7Fh00
80h … FFh11
35h = 0011 0101b00
C2h = 1100 0010b11
The processor does not know whether a number is signed or unsigned; SF is just a copy of the MSB. Reading the result as two's complement (signed) is the programmer's job.

The FLAGS Register

ZF and PF

ZF — Zero Flag
  • Tells whether the result is zero.
  • If the result is 0, ZF = 1; otherwise ZF = 0.
  • CMP AX, BX sets ZF = 1 on equality → JE/JZ jumps.
  • Example: SUB AL, AL → AL = 00h, ZF = 1.
PF — Parity Flag
  • PF = 1 if the number of 1s in the low 8 bits of the result is even; PF = 0 if it is odd.
  • Even in a 16-bit operation only the low byte counts.
  • Example: 03h = 0000 0011b → two 1s → PF = 1.
  • Example: 07h = 0000 0111b → three 1s → PF = 0.
03h00000011two 1s → even → PF = 107h00000111three 1s → odd → PF = 0
ZF = 1 means “the result is zero”, so the flag and the result look inverted. PF was once used for error checking in serial communication.

The FLAGS Register

AF — Auxiliary Carry Flag

  • Auxiliary carry flag: AF = 1 if a carry (in addition) or borrow (in subtraction) passes from bit 3 to bit 4; otherwise 0.
  • In other words, it shows a carry out of the low nibble (4 bits).
  • Specific to BCD (binary-coded decimal, each digit 0–9) arithmetic: DAA, DAS, AAA and AAS use this flag.
0000 100008h+ 0000 100109h0001 000111h↑ carry from bit 3 → bit 4AF = 1 → DAA gives 17h (BCD 17)
There is no conditional jump on AF and no instruction that sets or clears it directly; still, LAHF and PUSHF can read it, SAHF and POPF can write it.

The FLAGS Register

CF — Carry Flag

  • Carry flag: in an n-bit operation, CF = 1 if the result does not fit in n bits (a carry leaves the MSB); otherwise 0.
  • A borrow in subtraction (smaller minus larger) also sets CF = 1.
  • It signals overflow for unsigned numbers.
  • In shifts and rotates the bit shifted out goes to CF.
  • The programmer can change it too: STC (1), CLC (0), CMC (complement).
  • In multi-byte addition, ADC carries it into the next byte.
Operation (8 bits)ResultCF
FFh + 01h00h1
80h + 80h00h1
70h + 10h80h0
05h − 07hFEh1 (borrow)
07h − 05h02h0

The FLAGS Register

OF — Overflow Flag

  • Overflow flag: OF = 1 if the result, read as signed, does not fit in the operand size; otherwise 0.
  • The signed range is −128 … +127 for 8 bits and −32768 … +32767 for 16 bits.
  • Rule for addition: OF = 1 when two positives give a negative, or two negatives give a positive. Adding numbers of opposite sign never overflows.
  • In hardware: OF = 1 when the carry into the MSB differs from the carry out of it.
Operation (8 bits)Unsigned viewSigned viewResultCFOF
05h + 03h5 + 3 = 85 + 3 = 808h00
7Fh + 01h127 + 1 = 128127 + 1 ≠ −12880h01
FFh + 01h255 + 1 ≠ 0−1 + 1 = 000h10
80h + 80h128 + 128 ≠ 0−128 + (−128) ≠ 000h11

CF signals unsigned overflow, OF signed overflow; the two are independent.

The FLAGS Register

DF — Direction Flag

  • The direction flag sets the direction in which string instructions step through memory.
  • DF = 0: low to high addresses; SI/DI increase on each step.
  • DF = 1: high to low addresses; SI/DI decrease.
  • The step is 1 for byte instructions and 2 for word instructions.
  • CLD → DF = 0, STD → DF = 1.
  • Direction matters when copying overlapping areas: if the destination lies ahead of the source, copy from the end (STD).
CLD (DF = 0)100101102103104SI, DI ++STD (DF = 1)100101102103104SI, DI −−

The FLAGS Register · Step through the code

Code Trace: Overlapping Copy with DF = 1

org 100h
mov si, offset arr+3 ; source
mov di, offset arr+4 ; destination
mov cx, 4
std                  ; DF = 1
rep movsb
cld
ret
arr db 'KLMN', 0
arr (010Eh–0112h)K010EhL010FhM0110hN0111h·0112hDF = 0 · CX = 0

“KLMN” will move one place right; source and destination overlap. SI = 0111h: the last source byte.

arr (010Eh–0112h)K010EhL010FhM0110hN0111h·0112hSIDF = 0 · CX = 0

DI = 0112h: the last destination byte (one to the right).

arr (010Eh–0112h)K010EhL010FhM0110hN0111h·0112hSIDIDF = 0 · CX = 4

CX = 4 bytes to copy.

arr (010Eh–0112h)K010EhL010FhM0110hN0111h·0112hSIDIDF = 1 · CX = 4

std: DF = 1; string instructions will decrement SI and DI on each step.

arr (010Eh–0112h)K010EhL010FhM0110hN0111hN0112hSIDIDF = 1 · CX = 3

MOVSB 1: [0111h] → [0112h] ('N'); SI, DI down by 1, CX = 3.

arr (010Eh–0112h)K010EhL010FhM0110hM0111hN0112hSIDIDF = 1 · CX = 2

MOVSB 2: [0110h] → [0111h] ('M'); SI, DI down by 1, CX = 2.

arr (010Eh–0112h)K010EhL010FhL0110hM0111hN0112hSIDIDF = 1 · CX = 1

MOVSB 3: [010Fh] → [0110h] ('L'); SI, DI down by 1, CX = 1.

arr (010Eh–0112h)K010EhK010FhL0110hM0111hN0112hSIDIDF = 1 · CX = 0

MOVSB 4: [010Eh] → [010Fh] ('K'); SI, DI down by 1, CX = 0. Result KKLMN: the array shifted correctly.

arr (010Eh–0112h)K010EhK010FhL0110hM0111hN0112hSIDIDF = 0 · CX = 0

cld restores DF = 0. Copying forward with CLD would carry 'K' into every byte and give KKKKK: when the destination lies ahead of the source, copy backward.

The FLAGS Register

IF and TF

IF — Interrupt Flag
  • Controls external hardware interrupts (the INTR input).
  • IF = 1: maskable interrupt requests from peripherals are serviced.
  • IF = 0: these requests are ignored (masked).
  • STI → IF = 1, CLI → IF = 0.
  • NMI (non-maskable interrupt) and software interrupts (INT n) are not affected by IF.
TF — Trap Flag
  • Used for on-chip debugging.
  • TF = 1: single-step mode; after each instruction an internal INT 1 occurs and the single-step ISR (interrupt service routine) runs.
  • This lets you examine a program one instruction at a time (DEBUG, emu8086 “single step”).
  • TF = 0: normal execution.
  • There is no direct instruction; use PUSHF → change bit 8 → POPF.
instruction executesTF = 1 → INT 1push FLAGS, CS, IP; TF = 0single-step routineIRET → next instruction

The FLAGS Register

Instructions That Change Flags

InstructionEffectInstructionEffect
CLCCF = 0CLDDF = 0
STCCF = 1STDDF = 1
CMCCF = ¬CFCLI / STIIF = 0 / 1
LAHFAH ← SF ZF – AF – PF – CFSAHFAH → low flag byte
PUSHFpush FLAGSPOPFpop into FLAGS
Instruction groupEffect on flags
ADD, ADC, SUB, SBB, CMP, NEGCF, PF, AF, ZF, SF, OF all updated
INC, DECall updated except CF
AND, OR, XOR, TESTCF = OF = 0; PF, ZF, SF updated; AF undefined
MOV, PUSH, POP, XCHG, LEA, LOOP, JMPflags not affected

The FLAGS Register · Step through the code

Code Trace: Reading and Writing Flags

org 100h
mov al, 0FFh
add al, 1       ; CF ZF AF PF = 1
lahf            ; AH ← flags
cmc             ; flip CF
clc             ; CF = 0
stc             ; CF = 1
mov ah, 0C1h    ; 1100 0001b
sahf            ; flags ← AH
ret
flags (low byte)SF0ZF0–0AF0–0PF0–1CF0AH00000000AH = 00h

AL = FFh. Low byte of the flags: SF ZF – AF – PF – CF.

flags (low byte)SF0ZF1–0AF1–0PF1–1CF1AH00000000AH = 00h

FFh + 1 = 00h: CF = 1, ZF = 1, AF = 1 (F + 1), PF = 1 (00h has zero 1s, even).

flags (low byte)SF0ZF1–0AF1–0PF1–1CF1AH01010111AH = 57h

lahf: the low flag byte is copied to AH → AH = 57h = 0101 0111b (bit 1 is always 1).

flags (low byte)SF0ZF1–0AF1–0PF1–1CF0AH01010111AH = 57h

cmc: CF flips, 1 → 0. The other flags stay.

flags (low byte)SF0ZF1–0AF1–0PF1–1CF0AH01010111AH = 57h

clc: CF = 0 (it already was).

flags (low byte)SF0ZF1–0AF1–0PF1–1CF1AH01010111AH = 57h

stc: CF = 1. Sets up the carry before multi-byte ADC/SBB.

flags (low byte)SF0ZF1–0AF1–0PF1–1CF1AH11000001AH = C1h

AH = C1h = 1100 0001b: bit 7 (SF), bit 6 (ZF), bit 0 (CF) = 1.

flags (low byte)SF1ZF1–0AF0–0PF0–1CF1AH11000001↓AH = C1h

sahf: AH is written to the low flag byte → SF = 1, ZF = 1, CF = 1, AF = PF = 0. OF, DF, IF and TF are not affected.

Lab · 8086 instructions step by step

Lab: Registers and Flags

Summary

Summary

RegistersAX, BX, CX and DX are data registers that split into halves; SP/BP serve the stack, SI/DI strings and indexing, CS/DS/SS/ES the segments, and IP holds the next instruction.
Implicit rolesMUL/DIV → AX, DX · LOOP/REP → CX · [BX] → DS · [BP] → SS · strings → DS:SI, ES:DI · ports → DX.
FlagsCF unsigned and OF signed overflow; ZF zero; SF the MSB; PF parity of the low byte; AF nibble carry. DF, IF and TF are control flags.
Register pairsCS:IP next instruction, SS:SP top of stack, SS:BP stack frame, DS:SI → ES:DI string copy. A segment register cannot take a constant.

Summary

Exercises

  1. With AX = 3A7Fh, what is AX after MOV AL, 0 followed by INC AH?
  2. Find AL, CF, ZF, SF, OF and PF after MOV AL, 9Ch / ADD AL, 64h.
  3. MOV AL, 50h / ADD AL, 50h: what are CF and OF? Why do they differ?
  4. With SP = 0100h, what is SP after 3 PUSHes and 1 POP?
  5. How many times does a LOOP loop run after MOV CX, 0?
Answers
  1. MOV AL, 0 → 3A00h; INC AH → 3B00h.
  2. 9Ch + 64h = 100h → AL = 00h, CF = 1, ZF = 1, SF = 0, OF = 0 (−100 + 100 = 0), PF = 1, AF = 1.
  3. A0h: CF = 0 (80 + 80 = 160 ≤ 255), OF = 1 (+80 + +80 = +160 > 127).
  4. 0100h − 6 + 2 = 00FCh.
  5. 65536 times (the first LOOP sets CX to FFFFh).

Summary

References

  • Intel, The 8086 Family User's Manual, 1979.
  • Barry B. Brey, The Intel Microprocessors, 8th ed., Pearson, 2009.
  • Muhammad Ali Mazidi, Janice G. Mazidi, The x86 PC: Assembly Language, Design, and Interfacing, 5th ed., 2010.
  • emu8086 documentation: the 8086 instructions and Addressing modes sections.
  • Mehmet Bodur, Mikroişlemcilere Giriş: Assembler ile Yazılım ve Arayüz (in Turkish).

The End

Chapter 2.2: 8086 Registers
Previous: Chapter 2.1: 8086 Architecture · Next: Chapter 3.1: Programming Languages
1 / 1 Sercan KÜLCÜ. All rights reserved.