Professional Documents
Culture Documents
MODES OF
8086
Vaibhav Nijhawan
Department of Electronics and
Communication Engineering
Maharaja Agrasen Institute of
Technology
Delhi
ADDRESSING MODES OF 8086
2
Vaibhav Nijhawan, ECE Department, MAIT
❖ Implied
❖ Register
❖ Immediate
❖ Direct
❖ Register indirect
❖ Register indirect addressing
DATA mode works with SI, DI, BX
ADDRESSING and BP registers
❖ Base Addressing mode
MODES
❖ Index addressing mode
❖ Based Indexed Addressing mode
❖ Based Indexed with
displacement Addressing mode
❖ String Addressing Mode
3
Vaibhav Nijhawan, ECE Department, MAIT
❖ Immediate Addressing Mode
❖ MOV AX, 2500H
❖ Register Addressing Mode
❖ MOV AX, BX
❖ Direct Addressing mode or the
DATA Displacement Only Addressing
Mode
ADDRESSING ❖ MOV AX, [4321H]
MODES ❖ MOV AX, ES: [4321H]
❖ MOV AX, CS: [4321H]
❖ The Register Indirect Addressing
Modes
❖ MOV DX, [BX]
❖ MOV AX, CS:[BX]
4
Vaibhav Nijhawan, ECE Department, MAIT
DATA ADDRESSING MODES
5
DATA ADDRESSING MODE
6
Vaibhav Nijhawan, ECE Department, MAIT
❖ Summary of data addressing modes
8
Vaibhav Nijhawan, ECE Department, MAIT
❖ADDRESS ADDRESSING MODES
❖ Intrasegment direct
2000 JMP 20H
New IP = 2020h
❖ Intrasegment indirect
New IP = BX
Vaibhav Nijhawan, ECE Department, MAIT
9
ADDRESS ADDRESSING MODES
❖ Intersegment direct
❖2000 CALL 1000H: 5000H
❖ New IP = 1000H
❖ New CS = 5000H
❖ Intersegment indirect
❖ 2000 CALL [BX]
11
Vaibhav Nijhawan, ECE Department, MAIT
Example 2:
Find the branch address for the following address addressing mode
Assume the following
IP= 2500H CS = 2000H BX = 3000H DS = 4000H
Immediate value (16-bit) = 1500H
Immediate value (32-bit) = 1500:3500H [43000H] = 40FD3598H [44500H] = 05F6H
Solution:
For Intrasegment direct addressing mode the branch = 1500H + 2500H =4000H
For Intrasegment indirect addressing mode the branch address = 3000H
For Intrasegment indirect addressing using base addressing using BX register mode, branch address = [DS * 10H + BX + Disp] =
[44500H] =05F6H
or Intersegment direct addressing mode the branch address will be IP = 1500H and CS =3500H
or intersegment indirect addressing mode using BX register the branch address
= [DS * 10H + BX] = [43000H] = 40FD3598H So IP = 40FDH and CS = 3598H
12
Vaibhav Nijhawan, ECE Department, MAIT
INSTRUCTION FORMAT AND
TEMPLATES
OF 8086
INSTRUCTION FORMAT
14
Vaibhav Nijhawan, ECE Department, MAIT
The first byte always consists of
the opcode. The OP code may
be of 8-bit or may occupy MSB
six bits of the first byte The
remaining two bits are any of
the following bits.
Direction bit (D) defines
whether the register operand
in byte 2 is the source or
INSTRUCTION destination operand.
15
Vaibhav Nijhawan, ECE Department, MAIT
Sign Bit (S) is used for sign
extension of an 8-bit 2’s
compliment number to a 16-bit
2’s compliment number.
V-Bit is used in shift and rotate
instruction to determine the
number of shifts.
INSTRUCTION V = 0 shift count is 1 V
FORMAT = 1 shift count is in CL
The Z-bit is used in REP
instruction. The Z bit is matched
with the Zero flag bit. The REP
instruction goes on executing
till the Z bit does not match
with the Zero flag.
16
Vaibhav Nijhawan, ECE Department, MAIT
INSTRUCTION TEMPLATES
17
Vaibhav Nijhawan, ECE Department, MAIT
INSTRUCTION
TEMPLATES
18
Vaibhav Nijhawan, ECE Department, MAIT
Example 3:
Construct the machine code for the instruction MOV
BL, CH
Solution:
The Instruction template of this instruction will be
of two bytes only
The 6 bit Opcode for this instruction is 100010.
Since this instruction transfer only 8-bit hence W=0
D=0 indicates CH is a source operand.
19
Vaibhav Nijhawan, ECE Department, MAIT
The same instruction can be coded by another way by considering BL
register in REG field. In this case the D bit is defined in concern with the
BL register and now it will be D = 1 because the BL register is destination.
The R/M field = 101 (CH)
Register (REG) field = 011 (BL)
Hence the machine code for MOV BL, CH will be
20
Vaibhav Nijhawan, ECE Department, MAIT
Example 4:
Construct the machine code for the instruction MOV
1234 (SI), AX
Solution:
Here REG field will specify the AX register, the D bit
must be 0, indicating the AX is the source register. The
REG field must be 000 to indicate AX register. The W bit
must be 1 to indicate it is a word operation. 1234 [SI] is
specified using MOD value of 10 and R/M value of 100
and a displacement of 1234H. The 4 byte code for this
instruction would be 89 8434 12H.
21
Vaibhav Nijhawan, ECE Department, MAIT
Example 5:
Construct the machine Code for IN AX, 35H
Solution:
The instruction template of the IN instruction is
22
Vaibhav Nijhawan, ECE Department, MAIT
Example 6:
Construct the machine Code for SUB BX, [DI]
Solution:
The instruction template of the SUB BX, [DI] instruction is same as that of a
two byte MOV instruction
The 6 bit Opcode for SUB is 001010.
D=1 so that REG field of byte 2 is the destination operand. W=1 indicates
16 bit operation.
MOD = 00 REG = 011 R/M = 101
The machine code is 0010 1011 0001 1101= 2 B 1 D
23
Vaibhav Nijhawan, ECE Department, MAIT
Example 7:
Construct the machine Code for MOV DS: 43 [BP], CX
Solution:
Specify BX using REG field.
D = 0, indicating that CX is the source.
The REG field = 001 indicating CX register.
W = 1 to indicate it is a 16-bit operation.
43 [BP] is specified with MOD = 01and R/M = 110 and
disp = 43 H.
Whenever BP is used to generate the EA, the default
segment
would be SS. But here in this instruction segment
override is used
the segment register DS is used. In such cases segment
override prefix byte (SOP byte) is to be used. The SOP
byte is
24
Vaibhav Nijhawan, ECE Department, MAIT
INSTRUCTION SET OF
8086
DATA TRANSFER &
ARITHMETIC
INSTRUCTIONS
DATA TRANSFER INSTRUCTIONS
1. MOV Destination, Source
• MOV REG, memory
• MOV memory, REG •MOV SREG, memory
• MOV REG, REG •MOV memory, SREG
• MOV memory, immediate •MOV REG, SREG
• MOV REG, immediate •MOV SREG, REG
27
Vaibhav Nijhawan, ECE Department, MAIT
DATA TRANSFER INSTRUCTIONS
7. XCHG Rd, M
M, Rs XLAT is something like
Rd, Rs MOV AL, [BX +AL]
8. XLAT No operands
AL = DS:[BX + unsigned AL]
9. PUSH REG
11. PUSHF No operands
SREG
12. POPF No operands
memory
13. LAHF No operands
10. POP REG
14. SAHF No operands
SREG
memory
Vaibhav Nijhawan, ECE Department, MAIT
28
ARITHMETIC INSTRUCTIONS
1. ADD REG, memory 3. SUB REG, memory
memory, REG memory, REG
REG, REG REG, REG
memory, immediate memory, immediate
REG, immediate REG, immediate
2. ADC REG, memory 4. SBB REG, memory
memory, REG memory, REG
REG, REG REG, REG
memory, immediate memory, immediate
REG, immediate REG, immediate
6. DEC REG
memory
❖ In DEC except the carry flag all other flag changes as that of in SUB and SBB
instructions.
7. NEG REG
memory
MOV AL, 5 ; AL = 05h
NEG AL ; AL = 0FBh (-5)
30
Vaibhav Nijhawan, ECE Department, MAIT
ARITHMETIC INSTRUCTIONS
8. DIV REG
memory
9. IDIV REG
Memory
9. MUL REG
memory
10. IMUL REG
memory
11.CBW No operands
❖ CBW converts the signed value in the AL register into an equivalent
16 bit signed value in the AX register by duplicating the sign bit to
the left.
MOV AL, -5 ; AX = 000FBh (251)
❖ Flag remain unchanged CBW ; AX = 0FFFBh (-5)
12.CWD No operands
❖ CWD converts the 16 bit signed value in the AX register into an
equivalent 32 bit signed value in DX: AX register pair by
duplicating the sign bit to the left. 32
❖ Flag remain unchanged
MOV AX, -5 ; DX AX =00000h:0FFFBh
Vaibhav Nijhawan, ECE Department, MAIT CWD ; DX AX = 0FFFFh:0FFFBh
Example 1:
Write a program to add two 16- bit
numbers. ❖Segment defines a program segment called
Program: name (any arbitrary name)
Data Segment
num1 dw 6785h
num2 dw 1234h ❖END directive marks the end of a module
result dw 00
❖ENDS directive marks the end of a segment
Data Ends
Code Segment
assume CS:Code, DS:Data
Start:mov ax,data ❖ASSUME directive is used to tell the
mov ds,ax assembler, which segment is to be used as an
mov ax,00
active segment.
mov ax,num1
add ax,num2
mov result,ax
int 03h Data defining directives are used to define the
Code Ends type of data stored in the memory.
End start
These directives are DB, DW, DD, DQ and DT.
End
Vaibhav Nijhawan, ECE Department, MAIT
33
❖DUP directive can be used to initialize several
locations and to assign values to these locations.
39
Vaibhav Nijhawan, ECE Department, MAIT
ADJUSTMENT INSTRUCTIONS
Example:
MOV AX, 0105h ; AH = 01, AL = 05 40
Vaibhav Nijhawan, ECE Department, MAIT
AAD ; AH = 00, AL = 0Fh (15)
ADJUSTMENT INSTRUCTIONS
Example:
MOV AL, 15 ; AL = 0Fh 41
Vaibhav Nijhawan, ECE Department, MAIT
AAM ; AH = 01, AL = 05
ADJUSTMENT INSTRUCTIONS
42
Vaibhav Nijhawan, ECE Department, MAIT
DAA No operands - Decimal adjust After Addition.
This instruction adjusts the result of an addition to a packed BCD
number. The previous sub instruction should place its 8-bit binary
result in AL.
DAA converts this binary sum to packed BCD format with the least
significant decimal digit in the lower four bits and the most
significant digit in the upper four bits. If the sum is greater than 99h
after adjustment, then the carry and auxiliary carry flags are
set. Otherwise, the carry and auxiliary carry flags are cleared.
Example:
MOV AL, 0Fh ; AL = 0Fh (15)
DAA ; AL = 15h
ADJUSTMENT INSTRUCTIONS
43
Vaibhav Nijhawan, ECE Department, MAIT
ADJUSTMENT INSTRUCTIONS
44
Vaibhav Nijhawan, ECE Department, MAIT
INSTRUCTION SET OF
8086
FLAG & CONTROL
TRANSFER
INSTRUCTIONS
❖ CLC No operands
❖ CLC clear the carry flag (CF) to 0
❖ CLD No operands
❖ This instruction reset the
designation flag to zero.
❖ CLI No operands
❖ This instruction resets the
interrupt flag to zero.
FLAG RELATED ❖ CMC No operands
INSTRUCTIONS ❖ STC No operands
❖ This instruction sets the Carry
flag.
❖ STD No operands
❖ This instruction sets the Direction
flag..
❖ STI No operands
❖ This instruction sets the Interrupt
enable flag.
47
Vaibhav Nijhawan, ECE Department, MAIT
RET No operands
❖ Returns from a procedure by
transferring control to an
address popped from the top of
the stack.
IRET No operands:
❖ Returns control from an
interrupt procedure to the
❖CONTROL interrupted code.
48
Vaibhav Nijhawan, ECE Department, MAIT
❖ JMP label
4-byte address
❖ Unconditional Jump.
49
Vaibhav Nijhawan, ECE Department, MAIT
JAE label -Jump if is Above or
Equal. Unsigned.
if CF = 0 then jump
JB label - Jump if Below.
CONTROL
Unsigned.
TRANSFER if CF = 1 then jump
50
Vaibhav Nijhawan, ECE Department, MAIT
JC label - Jump if Carry
if CF = 1 then jump
JCXZ label - Jump if CX is 0.
51
Vaibhav Nijhawan, ECE Department, MAIT
JGE label - Jump if Greater or
Equal. Signed.
if SF = OF then jump
52
Vaibhav Nijhawan, ECE Department, MAIT
JNA label - Short Jump if first
operand is Not Above second
operand. Unsigned.
if CF = 1 or ZF = 1 then jump
JNAE label - Short Jump if first
operand is Not Above and Not
Equal to second operand.
Unsigned.
if CF = 1 then jump
CONTROL JNB label - Short Jump if first
TRANSFER operand is Not Below second
operand. Unsigned.
INSTRUCTIONS if CF = 0 then jump
JNBE label - Short Jump if first
operand is Not Below and Not
Equal to second operand.
Unsigned.
if (CF = 0) and (ZF = 0) then
jump
53
Vaibhav Nijhawan, ECE Department, MAIT
JNC label - Short Jump if Carry
flag is set to 0.
if CF = 0 then jump
JNE label - Short Jump if first
operand is Not Equal to
second operand.
Signed/Unsigned.
if ZF = 0 then jump
CONTROL
54
Vaibhav Nijhawan, ECE Department, MAIT
JNL label - Short Jump if first
operand is Not Less then
second operand. Signed.
if SF = OF then jump
JNLE label - Short Jump if first
operand is Not Less and Not
Equal to second operand.
Signed.
CONTROL if (SF = OF) and (ZF = 0)
TRANSFER then jump
55
Vaibhav Nijhawan, ECE Department, MAIT
JNS label - Short Jump if Not
Signed (if positive).
if SF = 0 then jump
JNZ label - Short Jump if Not
Zero (not equal).
56
Vaibhav Nijhawan, ECE Department, MAIT
JPE label - Short Jump if Parity
Even. Only 8 low bits of result
are checked.
if PF = 1 then jump
JPO label - Short Jump if Parity
Odd. Only 8 low bits of result
CONTROL are checked.
57
Vaibhav Nijhawan, ECE Department, MAIT
LOOP label (LOOP
Unconditionally)
Loop instruction is used to
create a loop from the Loop
instruction to a specified label.
Loop decrements CX without
changing any flags and if the
CONTROL result is not 0, transfers
TRANSFER execution to the address
specified by the operand. If CX
INSTRUCTIONS is 0 after being decremented,
execution continues at the
next instruction. The operand
must specify a short label
(between -128 and 127 bytes
from the instruction following
the LOOP instruction).
58
Vaibhav Nijhawan, ECE Department, MAIT
LOOP conditional: Conditional
Loop instruction is used to
create a loop from the Loop
instruction to a specified label
if condition is met and if CX is
not 0.
LOOPE label
Decrease CX, jump to label if
CX not zero and Equal (ZF = 1).
CONTROL LOOPNE label
TRANSFER Decrease CX, jump to label if
CX not zero and Not Equal (ZF
INSTRUCTIONS = 0).
LOOPNZ label
Decrease CX, jump to label if
CX not zero and ZF = 0.
LOOPZ label
Decrease CX, jump to label if
CX not zero and ZF = 1.
59
Vaibhav Nijhawan, ECE Department, MAIT
NOP
PROCESSOR- ESC
WAIT
CONTROL
LOCK
INSTRUCTIONS HLT
60
Vaibhav Nijhawan, ECE Department, MAIT
INSTRUCTION SET OF
8086
STRING INSTRUCTIONS
STRING INSTRUCTIONS
CMPSB No operands
Compare bytes: ES:[DI] from DS:[SI].
After execution DI = DI +1 and SI = SI +1 if DF = 0
Or DI = DI – 1 and SI = SI – 1 if DF = 1
CMPSW No operands
Compare words: ES:[DI] from DS:[SI].
After execution DI = DI + 2 and SI = SI + 2 if DF = 0
Or DI = DI – 2 and SI = SI – 2 if DF = 1
A segment ov erride can be giv en for the source (but not for the
destination). CMPS and its v ariations are usually used with repeat
prefixes. REPNE (or REPNZ) is used to find the first match between two
strings. REPE (or REPZ) is used to find the first non-match.
62
Vaibhav Nijhawan, ECE Department, MAIT
STRING INSTRUCTIONS
LODSB No operands
Copies a byte from a string location pointed by SI to AX
After execution SI = SI +1 if DF = 0
or SI = SI – 1 if DF = 1
LODSW No operands
copies a word from a string location pointed to by SI to AX
After execution SI = SI + 2 if DF = 0
Or SI = SI – 2 if DF = 1
A segment override can be given.
63
Vaibhav Nijhawan, ECE Department, MAIT
STRING INSTRUCTIONS
MOVSB No operands
Copy byte at DS: [SI] to ES: [DI].
After execution DI = DI +1 and SI = SI +1 if DF = 0
Or DI = DI – 1 and SI = SI – 1 if DF = 1
MOVSW No operands
Copy byte at DS:[SI] to ES:[DI].
After execution DI = DI + 2 and SI = SI + 2 if DF =
0
Or DI = DI – 2 and SI = SI – 2 if DF = 1
64
Vaibhav Nijhawan, ECE Department, MAIT
STRING INSTRUCTIONS
SCASB No operands
Compare bytes: AL from ES:[DI].
After execution DI = DI +1 if DF = 0
Or DI = DI – 1 if DF = 1
SCASW No operands
Compare words: AX from ES:[DI].
After execution DI = DI + 2 if DF = 0
Or DI = DI – 2 if DF = 1
No segment override is allowed
65
Vaibhav Nijhawan, ECE Department, MAIT
STRING INSTRUCTIONS
STOSB No operands
Store byte in AL into ES:[DI].
After execution DI = DI +1 if DF = 0
Or DI = DI – 1 if DF = 1
STOSW No operands
Store word in AX into ES:[DI].
After execution DI = DI + 2 if DF = 0
Or DI = DI – 2 if DF = 1
No segment override is allowed
66
Vaibhav Nijhawan, ECE Department, MAIT
STRING INSTRUCTIONS
REP (Unconditionally)
This is a prefix to a string instruction. This instruction repeats
the string instruction by the number of times indicated by
CX. For each string element, the string instruction is
performed and CX is decremented. REP is normally used
with MOVS and STOS
REP (Conditionally)
This prefix to a string instruction is used to repeat a string
instruction as long as condition is true and the maximum
count has not been reached not been reached.
The conditional repeat prefixes should only be used with
SCAS and CMPS, since these are the only string
instructions that modify the zero flag.
67
Vaibhav Nijhawan, ECE Department, MAIT
STRING INSTRUCTIONS
68
Vaibhav Nijhawan, ECE Department, MAIT
THANK YOU