You are on page 1of 40

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 D0 D1 D7 D6 D0 D5 D4 D3 REG D2 D1 R/M W

11

3. Register to/from Memory with no displacement Two bytes length similar to register to register except for the MOD field
D7 D0 D1 W D7 D6 D0 MO D D5 D4 D3 REG D2 D1 R/M

4. Register to/from Memory with displacement


Three/four bytes length additional bytes for the displacement
D7 D0

OPCODE

D7 D6 D0 MO D

D5 D4 D3 REG

D2 D1
R/M

D7 D0 Lower byte of Disp.


D7 D0 Upper 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 D0
D7 D6 D0 D5 D4 D3 OPCODE D2 D1 R/M D7 D0 Lower byte DATA

OPCODE

11

D7 D0Upper byte DATA

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 D0 D7 D6 D0 MO D D5 D4 D3 OPCODE D2 D1 R/M D7 D0 Lower byte of Disp.

OPCODE

D7 D0 Upper byte of Disp.

D7 D0 Lower byte DATA.

D7 D0 Upper byte DATA

Instruction Set
The instructions in 8086, can be classified into 13 groups based on their functions. Instructions 1. Data Transfer Instructions 3. Logic Instructions 5. Jump Instructions 2. Arithmetic 4. Compare

Instruction

6. Loop Instruction 8. Rotate 10. String 12. Interrupt

Instructions
Instructions Instructions

7. Shift Instructions 9. Flag Control Instructions 11.Input / Output 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 REG, memory ; MOV memory, REG

MOV

MOV REG, REG ;


MOV REG, immediate ; MOV memory, SREG; MOV SREG, REG

MOV memory, immediate


MOV SREG, memory MOV REG, SREG

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 Destination REG memory REG Source memory REG REG

Operation: (D)<--->(S)

Exchange values of two operands.


Example: XCHG AX, DX

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

10103h
10102h 10101h 10100h

56 78 12 34 m

Example:
LDS AX, m Memory contains data are 1234h 5678h AX is set to 1234h, DS is set to 5678h.

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 word ES = high order word Example: LES AX, m memory 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 Flag


It 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

Flags

Overflow Direction Interrupt

Carry Parity Auxiliary Zero Sign

flag

flag

enable
Trap

flag

are status flags 3 are control flag

SAHF : Store AH to lower byte of Flag register


It 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,CF Eg : 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 AX Current 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 AX PUSH DS PUSH [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:
Contents

POP AX

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 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 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 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
AX, DX DX, 0800H

2.IN

3.MOV

IN AX,DX

OUT : Output to the Port


This 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. 2.

3.

OUT OUT MOV OUT

03H, AL DX, AX DX, 0300H 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.

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. Mnemoni c XLAT Meaning Format Operation ((AL)+(BX)+(DS)0() Flags affected None

Translate XLAT

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 XLAT Operation ( (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.

You might also like