6
6
6
There are 6 general instruction formats in 8086
1. One byte instruction
one byte long – using implied data or registers- all 8 bits form an opcode, sometimes LS 3 bits are used for specifying registers.
2. Register to register
Two bytes length – first byte for opcode, second byte for register and R/M field.
D7 D6 D5 D4 D3 D2 D1 D0
D7 D1 D0
W 11
REG R/M
3. Register to/from Memory with no displacement
Two bytes length – similar to register to register except for the MOD field D7 D6 D5 D4 D3 D2
D1 D0D7 D1 D0
W MOD
REG R/M
4. Register to/from Memory with displacement
Three/four bytes length – additional bytes for the displacement
D7 D6 D5 D4 D3 D2 D1 D0
D7 D0OPCODE MO
DREG R/M
D7 D0Lower
byte of Disp.D7
D0Upper byte of Disp.
5. Immediate operand to Register
Three/four bytes length – additional bytes for the displacement – first byte as well as 3 bits from second byte used for opcode
D7 D6 D5 D4 D3 D2 D1 D0
D7 D0OPCODE 11 R/M
D7 D0Lower
byte DATAD7
D0Upper byte DATA
OPCODE
6. Immediate operand to Memory with 16-bit Displacement
Five/Six bytes length –first 2 bytes contain information on Opcode, MOD and R/M fields. The remaining 4 bytes contain 2 bytes of displacement and 2 bytes of data
D7 D6 D5 D4 D3 D2 D1 D0
D7 D0OPCODE MO
DR/M
D7 D0Lower
byte of Disp.
D7 D0Upper
byte of Disp.
OPCODE
D7 D0Lower
byte DATA.
D7 D0Upper
byte DATA
Instruction Set The instructions in 8086, can be classified into 13 groups based on their functions.
1. Data Transfer Instructions 2. Arithmetic Instructions
3. Logic Instructions 4. Compare Instruction
5. Jump Instructions 6. Loop Instructions
7. Shift Instructions 8. Rotate Instructions
9. Flag Control Instructions 10. String Instructions
11.Input / Output Instructions 12. Interrupt Instructions
13. Subroutine and Subroutine handling instructions.
Data Transfer Instructions
Move data between its Internal registers or between an internal register and a storage location in memory. All the STORE, MOVE, LOAD, EXCHANGE, INPUT and OUTPUT instructions belong to this category.
MOV
MOV REG, memory ; MOV memory, REG
MOV REG, REG ; MOV memory, immediate
MOV REG, immediate ; MOV SREG, memory
MOV memory, SREG; MOV REG, SREG
MOV SREG, REG
Copy operand2 to operand1.
The instruction MOV transfers a byte or word of data from the source to the destination. (transfer data from source operand to destination operand).
The source can be a register or a memory location or an immediate number.
The destination can be a register or a memory location.
Both the source and destination cannot refer to memory locations in the same instruction.
The MOV instruction
Direct loading of one segment register to another segment register is not permitted. (should copy to general register first).
Direct loading of segment register with immediate data is not permitted. (should copy to general register first).
Eg: MOV AX, CX MOV AH, AL MOV DS, AX MOV AX,100H
XCHG (Exchange byte or word)
Syntax:
XCHG Destination, Source
Operation:
(D)<--->(S)
Exchange values of two operands.
Example:
XCHG AX, DX
DestinationSource
REG memory
memory REG
REG REG
This instruction exchanges the contents of the specified source and destination operands, which may be registers or one of them may be a memory location.
Exchange of contents of two memory locations is not permitted.
Immediate data is not allowed in this instructions.
LEA ( Load Effective Address)
Syntax:
LEA REG, memory
Operation:
REG <= address of memory (offset)
Example:
LEA AX, m
The instruction LEA loads the EA formed by source operand into the specified destination register.
determines offset of a variable or memory location indicated as a source (address) and places the offset in the specified 16-bit register.
The source operand must be a memory variable and the destination must be a 16-bit general register.
Eg: LEA AX, [BX] LEA BX, AMOUNT
LDS ( Load register and DS register)
Syntax:
LDS REG, memory
Operation:
REG <= low order word
DS <= high order word
Example:
LDS AX, mMemory contains data are
1234h 5678h
AX is set to 1234h, DS is set to 5678h.
m34
12
78
56
10103h
10102h
10101h
10100h
The instruction LDS copies the contents of first two memory locations to a specified 16-bit register and the next consecutive two memory locations into the DS register.
LES (Load register and ES register)
Syntax:LES REG, memory
Operation:
REG = low order wordES = high order word
Example:
LES AX, mmemory contain data are.
1234h 5678h
AX is set to 1234h, ES is set to 5678h.
The instruction LES copies the contents of first two memory locations to a specified 16-bit register and the next consecutive two memory locations into the ES register.
LAHF : Load AH from lower byte of LAHF : Load AH from lower byte of FlagFlagIt loads the AH register with the lower byte of the
flag register . This command is Used to observe the status of all the condition code flags.
No Flags affected Eg: LAHF
FlagsFlags
Carry flag
Parity flag
Auxiliary flag
Zero
Overflow
Direction
Interrupt enable
Trap
Sign6 are status flags3 are control flag
SAHF : Store AH to lower byte of Flag SAHF : Store AH to lower byte of Flag registerregisterIt copies the contents of AH into the lower byte of
the flag register. Set or reset the condition code flags in the lower byte of the flag register.
Flags Affected : SF,ZF,AF,PF,CFEg : SAHF
PUSH: Push to Stack
This instruction pushes the contents of the specified register/memory location on to the stack.
The Stack Pointer decremented by two, after each execution of the instruction.
The higher byte is Pushed first and then the lower byte.
Thus out of the two decremented stack address the higher byte occupies the higher address and the lower byte occupies the lower address.
Eg: PUSH AXCurrent stack top is already occupied so decrement
SP by one then store AH into the address pointed to by SP.
Further decrement SP by one and store AL into the location pointed to by SP.
Thus SP is decremented by 2 and AH-AL contents are stored in stack memory. 1000
1001 1002 1003
Example:
PUSH AXPUSH DSPUSH [5000H]
C,Z,S,O,P,A unchanged
POP : Pop from Stack
The POP operation incremented SP by two and then stores the two byte contents of the stack memory onto the operand (register or memory).
The POP instruction serves exactly opposite to the PUSH instruction.
Example:
eg: POP AX
Contents of stack top memory location is stored in AL and SP is incremented by one.
Further contents of memory location pointed to by SP are copied to AH and SP is again incremented by 1.
Effectively SP is incremented by 2 and points to next stack top.
Eg : POP DS
Eg: POP [5000H]
C,Z,S,O,P,A unchanged
PUSHF : Push Flags to StackPUSHF : Push Flags to Stack
The push flag instruction pushes the flag register on to the stack ; first the upper byte and then the lower byte is pushed on to it.
The SP is decremented by 2, for each push operation.
POPF : Pop Flags from StackPOPF : Pop Flags from Stack
The pop flags instruction loads the flag register completely (both bytes) from the word contents of the memory location currently addressed by SP and SS.
The SP is incremented by 2 for each pop operation.
IN : Input the PortIN : Input the Port
This instruction is used for reading an input port.The address of the input port may be specified in the
instruction directly or indirectly.AL and AX are the allowed destinations for 8 and 16
bit input operations.DX is the only register which is allowed to carry the
port address.If the port address is of 16 bits it must be in DX.
IN (Input from port into AL or AX)
1. IN AL, 03
2.IN AX, DX
3.MOV DX, 0800H
IN AX,DX
OUT : Output to the PortOUT : Output to the PortThis instruction is used for writing to an output port.The address of the output port may be specified in the
instruction directly in DX.Contents of AX or AL are transferred directly or indirectly
to an address port after execution of this instruction.The registers AL and AX are the allowed source
operands for 8-bit and 16-bit operations respectively.If the port address is of 16 bits it must be in DX.
Eg:1. OUT 03H, AL2. OUT DX, AX3. MOV DX, 0300H OUT DX, AX
XLAT (Translate)
Syntax:
XLAT
Operation:
((AL)+(BX)+(DS)0) -----> (AL)
Execution of the XLAT instructiThe most common application of this instruction is for software code conversions.
Mnemonic
Meaning Format Operation Flags affected
XLAT Translate XLAT ((AL)+(BX)+(DS)0→() None
Execution of the XLAT instruction replaces the contents of AL by the contents of the accessed lookup-table location.
the physical address of this element in the table is derived as PA = (DS) 0 + (BX) + (AL).
The most common application of this instruction is for software code conversions.
The translate instruction is used for finding out the codes in case of code conversion problems, using look up table technique.
The translation from the code of the key pressed to the corresponding code is performed using XLAT instruction.
Before execution of the XLAT instruction, BX should be loaded with the offset address of lookup table in the data segment (DS) and AL with the code to be converted.
When XLAT is executed , the byte pointed to by (BX + AL) is transformed to the AL register.
Eg: MOV AL,code MOV BX,2400 XLATOperation ( (AL) + (BX) + (DS)0 ) -> (AL)
Assume (DS) = 0300H, (BX)=0100H, and (AL)=0DH.
Execution of XLAT replaces the contents of AL by the contents of memory location with physical address.
PA=(DS)0 +(BX) +(AL)
= 03000H + 0100H + 0DH = 0310DH
(0310DH) (AL) , Assuming this memory locations contains 52H ,this value is placed in AL. That is (AL)=52h.