MIC Chapter 3 Instruction Set of 8086 Microprocessor
MIC Chapter 3 Instruction Set of 8086 Microprocessor
Syllabus:
3.1 Machine Language Instruction format, addressing modes
3.2 Instruction set, Groups of Instructions
Arithmetic Instructions, Logical Instructions, Data transfer instructions, Bit manipulation instructions, String Operation
Instructions, Program control transfer or branching Instructions, Process control Instructions
2. Register to Register:
This format is two byte long. The first byte of instruction gives the opcode and size of operand (16 bit/8 bit) with help
of w bit. The second byte of instruction gives the register operands and R/M fields.
Example: MOV A, B (Move the content of register B to register A)
1. Instruction: MOV A, B
2. Operation: The contents of register B are copied into register A.
3. Length: Typically 1 byte (depending on the CPU architecture).
In this instruction:
Base: The content of the BX register acts as the base address.
Displacement: The value 0x10 (16 in decimal) is the displacement added to the base address to form the final
memory address.
So, the instruction moves the content of the AX register to the memory location at BX + 0x10.
Example: MOV [BX + 0x10], AX
: MOV AX, [BP + SI + 0x04]
In this case:
Base: The combined content of the BP and SI registers acts as the base address.
Displacement: The value 0x04 (4 in decimal) is the displacement added to the base address to form the final
memory address. Here, the content of the memory location at BP + SI + 0x04 is moved into the AX register.
5.Immediate operand to Register:
In this instruction format, first byte and 3 bits from second byte (D3, D4, D5) are used as opcode. It contains 2 bytes of
immediate operand in case of 16 bit data.
If v = 0, shift count is 1.
If v = 1, shift count is in CL register.
5) z bit: this bit is used by REP prefix to control the loop.
6) Register relative:
In this addressing mode, effective address of data is formed by adding 8 bit or 16 bit displacement with the
contents of BX, BP, SI, or DI registers e.g. MOV AX, 50H [BX]
7) Based Indexed:
In this addressing mode, the effective address of data is formed by adding contents of base register (BX or BP)
to the contents of an index register (SI, DI)
e.g. MOV AX, [BX] [SI]
8) Relative Based Indexed:
The effective address of data, in this mode, is formed by adding an 8 bit / 16 bit displacement to the sum of
contents of any one base register(BX or BP) and any one index register (SI or DI).
e.g. MOV AX, 1000H [BX] [SI]
rds.
SBB, borrow flag (i.e. Carry flag) and source will be subtracted from destination and result is placed in
destination.
SUB, only source will be subtracted from destination and result is placed in destination.
destination = destination - source
DAA ; C > 9
7C + 06 = 82
ii) Let AL = 73, CL = 29
DAA ; C > 9
9C + 06 = A2
A>9
A2 + 60 = 02 in AL and CF = 1
13) DAS: Decimal Adjust after Subtraction
General form: DAS
This instruction is used after subtracting two packed BCD numbers. The result of subtraction must be in AL.
If lower nibble of AL > 9 or the AF = 1 then this instruction will subtract 6 from lower nibble of AL.
If the result in upper nibble is now greater than 9 or if carry flag was set, the instruction will subtract 60
from AL.
Examples:
1) Let AL = 75, BH = 46
SUB AL, BH ; AL = 75 – 46
= 2F
DAS ; AL = AL - 06
= 2F - 06
= 29
2) Let AL = 49, BH = 72
SUB AL, BH ; AL = 49 - 72
= D7 with CF = 1
Since D > 9
AL = AL - 60
= D7 - 60
= 77 with CF = 1
14) NEG: Negate (Find 2’s complement)
General form: NEG destination
This instruction finds 2’s complement of destination
For finding 2’s complement, it subtracts the contents of destination from zero.
The result is stored in destination.
The destination may be a register or a memory location.
15) MUL: Unsigned multiplication of byte or word
General form: MUL source
This instruction multiplies an unsigned byte by contents of AL or an unsigned word by contents of AX.
The source can be a register or memory location. Immediate data cannot be used as source.
When a byte is multiplied by AL, the result is put in AX.
When a word is multiplied by AX, the result can be as large as 32 bits. The most significant word (upper 16
bits) of result is placed in DX. The least significant word (lower 16 bits) of result is placed in AX.
If the most significant byte of 16 bit result or the most significant word of 32 bit result is 0, CF and OF will be
0. A, P, S and Z flags are undefined.
Examples:
MUL BH ; AX = AL *
BH MUL CX ; DX :
AX = AX * CX
MUL BYTE PTR
16) IMUL: Multiply signed numbers [BX]
MUL WORD PTR [SI]
General form: IMUL source
This instruction multiplies a signed byte by AL or a signed word by contents of AX.
The source can be a register or memory location. Immediate data can not be used as source.
When a byte is multiplied by AL, the signed result is put in AX.
When a word is multiplied by AX, the signed result is put in registers DX and AX with upper 16 bits in DX
and lower 16 bits in AX.
If upper byte of 16 bit result or upper word of 32 bit result contains only sign bits (all 0s for positive result
and all 1s for negative result) then CF = OF = 0 (reset).
If upper byte of 16 bit result or upper word of 32 bit result contains part of the product, CF = OF = 1 (set).
A, P, S, Z flags undefined.
Examples:
IMUL BX
IMUL AX
IMUL WORD PTR [SI]
17) CBW: Convert signed Byte to signed Word.
General form: CBW
This instruction copies the sign bit of a byte in AL to all bits in AH.
No flags are affected.
IDIV BL
IDIV BP
IDIV BYTE PTR[BX]
3. Logical
1) AND: Logical AND
General form: AND destination, source
This instruction ANDs bits of destination and source. The result is stored in destination.
The source can be immediate number, a register or memory location.
The destination can be a register or a memory location.
Both operands cannot be memory locations.
The size of operand must be same.
Flags affected:
OF = CF = 0 (reset)
P, S and Z flags are modified.
A (Auxiliary Carry) flag is undefined.
Examples: AND AX, 8000H
AND BH, CL
AND DX, [BX]
General form: OR destination, source
2) OR: Logical OR
This instruction performs OR operation on bits of source and destination. The result is stored in destination.
The source can be immediate number, a register or memory location.
The destination can be a register or a memory location.
Both operands cannot be memory locations.
The size of operand must be same.
Flags affected:
OF = CF = 0 (reset)
P, S and Z flags are modified.
A (Auxiliary Carry) flag is undefined.
Examples:
OR BX, CX OR
AL, DL OR
[BX], AH OR
AL, 30H
3) XOR: Logical Exclusive OR
General form: XOR destination, source
This instruction performs logical exclusive OR operation on bits of source and destination. The result is
stored in destination.
The source can be immediate number, a register or memory location.
The destination can be a register or a memory location.
Both operands cannot be memory locations.
The size of operand must be same.
Flags affected:
OF = CF = 0 (reset)
P, S and Z flags are modified.
A (Auxiliary Carry) flag is undefined.
Examples:
XOR AL, BL XOR
CX, DX XOR
BX, 5000H XOR
[SI], FFH XOR
DX, DX
4) NOT: Invert each bit of operand
General form: XOR destination
This instruction complements the contents of destination.
The destination can be register or memory location.
No flags are affected.
Examples:
NOT BX
NOT BYTE PTR[BX]
NOT WORD PTR[SI]
NOT CL