SOFTWARE MODEL OF THE 8086/8088
MICROPROCESSOR
1
The 8086 microprocessor is a 16-bit processor that uses a
set of registers and flags to execute instructions efficiently.
Its architecture includes general-purpose registers, segment
registers, pointer/index registers, and a flag register :-
1. GENERAL PURPOSE REGISTERS
Each can be used as 16-bit or split into 8-bit (high + low).
1. AX (Accumulator Register)
• Used in arithmetic, logic, and I/O operations.
• Default register for many instructions.
• Splits into:
• AH (high 8-bit)
• AL (low 8-bit)
2. BX (Base Register)
• Used as a base pointer for memory addressing.
• Helps in accessing data from memory.
• Splits into:
• BH (high 8-bit)
• BL (low 8-bit)
3. CX (Count Register)
• Used in loops, shifts, and rotations.
• Act as counter in instructions like LOOP.
• Splits into:
• CH (high 8-bit)
• CL (low 8-bit)
2
4. DX (Data Register)
• Used in multiplication/division operations.
• Stores I/O port addresses.
• Splits into:
• DH (high 8-bit)
• DL (low 8-bit)
2. SEGMENT REGISTERS
Used to divide memory into segments.
1. CS (Code Segment)
• Holds address of the current code segment.
• Works with IP (Instruction Pointer).
2. CS (Code Segment)
• Holds address of the current code segment.
• Works with IP (Instruction Pointer).
3. CS (Code Segment)
• Holds address of the current code segment.
• Works with IP (Instruction Pointer).
4. CS (Code Segment)
• Holds address of the current code segment.
• Works with IP (Instruction Pointer).
3
3. POINTER AND INDEX REGISTERS
Used for memory addressing and stack operations.
1. SP (Stack Pointer)
• Points to the top pf the stack.
• Used with stack segment.
2. BP (Base Pointer)
• Used to access stack data.
• Helpful in function calls.
3. SI (Source Index)
• Points to Source data in memory.
• Used in string operations.
4. DI (Destination Index)
• Points to destination location.
• Used in string operations.
4. SPECIAL REGISTERS
1. IP (Instruction Pointer)
• Holds offset address of next instruction.
• Works with Code segment.
2. SR (Status Register)
• Contains status flags.
4
8086 FLAG REGISTER
Flags indicate the status of operations.
1. Carry Flag (CF)
• Set when carry/borrow occurs.
• Used in unsigned arithmetic.
2. Parity Flag (PF)
• Set if result has even number of 1s.
3. Auxiliary Flag (AF)
• Set when carry occurs from bit 3 to bit 4.
• Used in BCD operations.
5
4. Zero Flag (ZF)
• Set if result is zero.
5. Sign Flag (SF)
• Show sign of result.
• 1 = negative, 0 = positive.
6. Overflow Flag (OF)
• Set when signed overflow occurs.
7. Trap Flag (TF)
• Enables step-by-step debugging.
8. Interrupt Flag (IF)
• Enables/Disables interrupt.
• 1 = enable, 0 = disable.
9. Direction Flag (DF)
• Controls string operations.
• 0 = forward, 1 = backward.
6
ARITHMETIC INSTRUCTIONS
1. ADD
Adds two operands, operand1 and operand2.
Algorithm:
operand1 = operand1 + operand2
Code:
MOV AL, 5 ; AL = 5
ADD AL, -3 ; AL = 2
RET
7
2. ADC
Add with Carry.
Algorithm:
operand1 = operand1 + operand2 + CF
Code:
STC ; set CF = 1
MOV AL, 6 ; AL = 6
ADC AL, 2 ; AL = 9
RET
8
3. SUB
Subtract two operands, operand2 from operand1.
Algorithm:
operand1 = operand1 - operand2
Code:
MOV AX, 10
SUB AX, 2 ; AX = 8
RET
9
4. SBB
Subtract with Borrow.
Algorithm:
operand1 = operand1 - operand2 - CF
Code:
STC ; set CF = 1
MOV DL, 6
SBB DL, 4 ; DL = 6 - 4 - 1 = 1
RET
10
LOGICAL INSTRUCTIONS
1. AND
Logical AND between all bits of two operands. Result is stored in operand1.
These rules apply:
1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0
Code:
MOV DL, 'a' ; DL = 01100001b
AND DL, 11011111b ; DL = 01000001b ('A')
RET
11
2. OR
Logical OR between all bits of two operands. Result is stored in first
operand.
These rules apply:
1 OR 1 = 1
1 OR 0 = 1
0 OR 1 = 1
0 OR 0 = 0
Code:
MOV DL, 'D' ; DL = 01000001b
OR DL, 00100000b ; DL = 01100001b ('d')
RET
12
3. XOR
Logical XOR (Exclusive OR) between all bits of two operands. Result is
stored in first operand.
These rules apply:
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 1 = 1
0 XOR 0 = 0
Code:
MOV DL, 00000111b
XOR DL, 00000010b ; DL = 00000101b
RET
13
4. NOT
Invert each bit of the operand.
Algorithm:
• if bit is 1 turn it to 0.
• if bit is 0 turn it to 1.
Code:
MOV DL, 00011011b
NOT DL ; DL = 11100100b
RET
14
SHIFT INSTRUCTIONS
1. SHL
Shift operand1 Left. The number of shifts is set by operand2.
Algorithm:
• Shift all bits left, the bit that goes off is set to CF.
• Zero bit is inserted to the right-most position.
Code:
MOV DL, 11100000b
SHL DL, 1 ; DL = 11000000b, CF=1.
RET
15
2. SHR
Shift operand1 Right. The number of shifts is set by operand2.
Algorithm:
• Shift all bits right, the bit that goes off is set to CF.
• Zero bit is inserted to the left-most position.
Code:
MOV DL, 00000111b
SHR DL, 1 ; DL = 00000011b, CF=1.
RET
16
3. SAL
Shift Arithmetic operand1 Left. The number of shifts is set by operand2.
Algorithm:
• Shift all bits left, the bit that goes off is set to CF.
• Zero bit is inserted to the right-most position.
Code:
MOV DL, 0E0h ; DL = 11100000b
SAL DL, 1 ; DL = 11000000b, CF=1.
RET
17
4. SAR
Shift Arithmetic operand1 Right. The number of shifts is set by operand2.
Algorithm:
• Shift all bits right, the bit that goes off is set to CF.
• The sign bit that is inserted to the left-most position has the same
value as before shift.
Code:
MOV DL, 0E0h ; DL = 11100000b
SAR DL, 1 ; DL = 11110000b, CF=0.
MOV BL, 4Ch ; BL = 01001100b
SAR BL, 1 ; BL = 00100110b, CF=0.
RET
18
ROTATE INSTRUCTIONS
1. ROR
Rotate operand1 right. The number of rotates is set by operand2.
Algorithm:
Shift all bits right, the bit that goes off is set to CF and the same bit is
inserted to the left-most position.
Code:
MOV DL, 1Ch ; DL = 00011100b
ROR DL, 1 ; DL = 00001110b, CF=0.
RET
19
2. ROL
Rotate operand1 left. The number of rotates is set by operand2.
Algorithm:
Shift all bits left, the bit that goes off is set to CF and the same bit is
inserted to the right-most position.
Code:
M MOV DL, 1Ch ; DL = 00011100b
ROL DL, 1 ; DL = 00111000b, CF=0.
RET
20
3. RCR
Rotate operand1 right through Carry Flag. The number of rotates is set by
operand2.
Algorithm:
Shift all bits right, the bit that goes off is set to CF and previous value of CF
is inserted to the left-most position.
Code:
STC ; set carry (CF=1).
MOV AL, 1Ch ; AL = 00011100b
RCR AL, 1 ; AL = 10001110b, CF=0.
RET
21
4. RCL
Rotate operand1 left through Carry Flag. The number of rotates is set by
operand2.
Algorithm:
Shift all bits left, the bit that goes off is set to CF and previous value of CF is
inserted to the right-most position.
Code:
STC ; set carry (CF=1).
MOV DL, 1Ch ; DL = 00011100b
RCL DL, 1 ; DL = 00111001b, CF=0.
RET
22
JUMPING INSTRUCTIONS
1. UNCONDITIONAL JUMP - JMP
Unconditional Jump. Transfers control to another part of the program. 4-
byte address may be entered in this form: 1234h:5678h, first value is a
segment second value is an offset.
Code:
include '[Link]'
ORG 100h
MOV DL, 5
JMP label1 ; jump over 2 lines!
PRINT 'Not Jumped!'
MOV DL, 0
label1:
PRINT 'Got Here!'
RET
23
2. CONDITIONAL JUMP - JE
Short Jump if first operand is Equal to second operand. Signed/Unsigned.
Algorithm:
if ZF = 1 then jump
Code:
include '[Link]'
ORG 100h
MOV DL, 5
CMP DL, 5
JE label1
PRINT 'DL is not equal to 5.'
JMP exit
label1:
PRINT 'DL is equal to 5.'
exit:
RET
24
LOOPING INSTRUCTIONS
1. LOOP
Decrease CX, jump to label if CX not zero.
Algorithm:
• CX = CX - 1
• if CX <> 0 then
jump
else
no jump, continue
Code:
include '[Link]'
ORG 100h
MOV CX, 5
label1:
PRINTN 'loop!'
LOOP label1
RET
25
2. LOOPE
Decrease CX, jump to label if CX not zero and Equal (ZF = 1).
Algorithm:
• CX = CX - 1
• if (CX <> 0) and (ZF = 1) then
jump
else
no jump, continue
Code:
include '[Link]'
ORG 100h
MOV BX, 0
MOV DX, 5
label1:
PUTC '*'
ADD BX, 100
CMP BH, 0
LOOPE label1
RET
26