You are on page 1of 11

lOMoARcPSD|30016554

INSTRUCTION SET AND PROGRAMMING INSTRUCTIONS


OF 8086
Computer Networks (APJ Abdul Kalam Technological University)

Studocu is not sponsored or endorsed by any college or university


Downloaded by Sri Msd (srimsd19@gmail.com)
lOMoARcPSD|30016554

INSTRUCTION SET OF 8086/8088


1. Data copy / transfer instructions
2. Arithmetic and logical instructions
3. Branch instructions
4. Loop instructions
5. Machine control instructions
6. Flag manipulation instructions
7. Shift and rotate instructions
8. String instructions
Data copy/transfer instructions
• Transfer data from source operand to destination operand.
• All the store , move, load, exchange ,input and output instructions belongs to this category.
1. MOV : MOVE
 This data transfer instruction transfers data from one register/memory location to
another register/memory location.
 The source and destination may be any one of the following
 Segment register
 General purpose register
 Special purpose register
 Memory location
 Direct loading of segment registers with immediate data is not permitted.
 To load a segment register with immediate data , first you need to transfer it to a general
purpose register and then move it to the segment register.
Eg:: MOV AX, 5000H
MOV AX, BX
MOV AX, [SI]
MOV AX, [2000H]
MOV AX, 50H[BX]
2. PUSH ▪
 This instruction pushes the contents of the specified register/memory location on to the
stack.
 The SP register points the stack top. The sequence of operation is

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

1. Stack pointer is decremented by one


2. Move the higher bits of data first.
3. Stack pointer is again decremented by one.
4. Move the lower bits of data then.
Eg:: PUSH AX
3. POP
 This instruction when executed, loads the specified register/memory location with the
content of memory location of which the address is formed using the current stack
segment and stack pointer as usual.
The sequence of operation is as follows
1. The content of stack top memory location is stored in register
2. SP is incremented by one.
3. Further contents of memory location pointed to by SP are copied to register and then SP is
incremented.
Eg:: POP AX
POP DS
POP [5000H]
4. XCHG: Exchange
 The instruction exchanges the contents of specified source and destination operands,
which may be registers or one of them may be a memory location.
Cases:: • Immediate is not permitted.
• Exchange between 2 memory location is not allowed
Eg:: XCHG [5000H], AX
XCHG BX, AX
5. IN: Input the Port
 The instruction is used for reading an input port.
 The address of the port may be specified in the instruction directly or indirectly.
 DX is the only register which carry port address.
Eg:: 1. IN AL, 03H
2. IN AX, 0800H
3. MOV DX, 0800H IN AX, DX
6. OUT: Output to the port
 The instruction is used for writing to an output port.

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

 The address of the instruction specified directly or implicitly in DX.


 The data to an odd addressed port is transferred on D8-D15 oThe data to an even addressed
port is transferred on D0-D7 o
Eg:: 1. OUT 03H, AL
2. MOV DX, 0800H OUT DX, AX
7. XLAT : Translate
• The translate instruction is used to for finding out the codes in case of code conversion problems
using look up table technique.
Eg:: MOV AX, SEG TABLE
MOV DS, AX
MOV AL, CODE
MOV BX, OFFSET TABLE XLAT
8. LEA: Load Effective Address
• Loads the effective address formed by the destination operand is transferred to the source register.
• This instruction is more useful in the case of machine language also.
Eg:: 1. LEA BX, ADR { Offset or ADR will be transferred to BX}
2. LEA SI, ADR[BX] { Offset of ADR will be added with content of SI register and is
transferred
9. LDS/LES : (Load pointer to DS/ES)
• Thisinstruction copies a word from 2 memory location(2 bytes) into register specified in the
instruction and then copies a word from next 2 memory locations into DS/ES register.s
10.PUSHF (Push flag to stack)
• It pushes the flag register into the stack.
• First the upper byte and then the lower byte is pushed on to it
11. POPF( Pop flag from stack)
• The pop flag register loads the flag register completely (both bytes from the word content of the
memory location currently addressed by SP)
12. LAHF( Load AH from lower byte of flag)
• Load the AH register with the lower byte of flag register.
• Used to observe the status of all the condition flags (except Overflow) 13. SAHF( Store AH to lower
byte of flag register)
• This instruction sets or resets the condition code (except overflow) flags in the lower byte of the flag
register depending upon the corresponding bit positions in AH.
ADDRESSING MODES
3

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

▪ Addressing modes indicating the way of locating data or operands.


▪ It describe the type of operands and the way they are accessed for executing an instruction.
▪ The addressing mode for sequential and control transfer instructions are
1. Immediate
2. Direct 10. Intrasegment indirect mode
3. Register 11. Intersegment Direct mode.
4. Register Indirect 12. Intersegment indirect
5. Indexed
6. Register relative
7. Based indexed
8. Relative based indexed
9. Intrasegment direct mode

1. Immediate
▪ Immediate data is a part of instruction, and appears in the form of successive byte or bytes.
Eg::MOV AX, 0005H MOV BL, 06H
2. Direct
▪ In direct addressing mode,a 16 bit address (offset) or an IO address is directly specified in the instruction as a
part of it.
Eg::MOV AX, [5000H] IN 80H
( Here data resides in a memory loc in the DS, whose effective address may be computed using 5000H as the
offset address and content of DS as segment address. In 2nd instruction 80H is an IO address.)
3. Register Addressing Mode
▪ In this mode the data is stored in a register and it is referred using the particular register.
▪ All the registers, except IP, may be used in this mode.
Eg :: MOV BX, AX ADC AL, BL( The operands in these instructions are provided in registers BX,
AX and AL, BL respectively.)
4. Register indirect
▪ Sometimes, the address of the memory location which contains data or operand is determined in an
indirect way, using the offset registers.
▪ The offset address of data is in either BX or SI or DI register,The default segment is either DS or ES.
▪Eg::MOV AX, [BX]
( Here the data is present in a memory location in DS whose offset address is in BX)
5. Indexed Addressing mode
▪ Special case of register indexed addressing mode.

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

▪ In indexed mode, offset of the operand is stored in one of the index registers.
▪ DS is the default segment for index registers SI & DI,But in string instructions DS and ES are default
segments for SI and DI respectively.
Eg:: MOV AX,[SI] Here the data is available at an offset address stored in SI in DS.
6. Register Relative
▪ In this addressing mode, the data is available at an effective address formed by adding an 8 bit or 16
bit displacement with the content of any one of the registers BX, BP, SI and DI in the default ( either
DS or ES) segment
▪ Eg:: MOV AX , 50H[BX].
7.Based Indexed
▪ The effective address of data is formed by adding content of a base register (BX or BP) to the content
of an index register (SI or DI).
▪ Eg::: MOV AX, [ BX][SI]Here BX is the base base register and SI is the index register.
8. Relative based indexed
▪ The effective address is formed by adding an 8 bit or 16 bit displacement with the sum of contents of any of the
base registers and any of the index registers, in a default segment.
▪ Eg::MOV AX, 50H [BX][SI]
For Control transfer instructions
▪ For control transfer instructions the addressing modes depend upon whether the destination location is within
the same segment or in a different one.
▪ If the location to which the control is to be transferred lies in a different segment other than the current one the
mode is called intersegment mode and if the destination location lies in the same segment,the mode is called
intrasegment mode.
9. Intrasegment direct mode
▪ The address to which the control is to be transferred lies in the same segment in which the control transfer
Instruction lies and appears directly in the instruction as an immediate displacement value.
▪ The displacement is computed relative to the content of the instruction pointer IP.
Eg:: JMP SHORT LABEL;Label lies within the segment.
10. Intrasegment indirect mode
▪ The displacement to which the control is to be transferred is in the same segment in which thecontrol transfer
instruction lies,but it is passed to the instruction indirectly.
▪ The branch address is found as the content of a register or a memory location.
▪ Eg:: JMP [BX] Jump to effective address stored in BX.
11. Intersegment direct mode

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

▪ In this mode the address to which the control is to be transferred is in a different segment.
▪ It provides a means of branching from one code segment to another code segment.
EG::: JMP 5000H : 2000H; Jump to 2000H of the segment 5000H.
12. Intersegment indirect mode
▪ In this mode, the address to which the control is to be transferred lies in a different segment and it is
passed to the instruction indirectly.
ASSEMBLER DIRECTIVES
• An assembler is a program used to convert an assembly language pgm into equivalent machinecode
modules which further converted into executable codes.
• It decides the address of each labels and substitute the values of each constants and variable.
• For completing all these tasks assembler requires some hints from the programmer.
-The required storage for a particular constant or variable,Logical names of the segments,Types of
modules/routines,End of file. Etc..
• These hints are given by some predefined alphabets/strings called Assembler directives.
1.DB (Define Byte)
• Used to reserve byte or bytes of memory locations in the available memory.
• While preparing EXE file, this directive directs assembler to allocate the specified number of memory bytes.
2. DW : DEFINE WORD
• Serves the same purpose as DF,But reserves no of words(16 bits) instead of bytes.
• Eg:: WORDS DW 1234H , 4567H, 78ABH, 045CH
• During initialization lower bytes are stored at lower memory address and vice versa.
3. DQ : DEFINE QUAD WORD
• Define assembler to reserve 4 words of memory (8 bytes) and may initialize with defined values.
4. DT : DEFINE TEN BYTES
• It directs the assembler to define the specified variable requiring 10 bytes of memory and initialize
with defined values.
5. ASSUME : Assume Logical Segment name
• The ASSUME directive is used to inform the assembler, the names of logical segments to be
assumed for different segments used in the program.
• The ASSUME statement is a must at the starting of each assembly language pgm.
• Eg:; ASSUME DS: DATA • ASSUME CS: CODE
6. END (END OF PROGRAM)
• This marks the end of an assembly language program.

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

• It ignores the source lines available later on.


7. ENDP (END OF PROCEDURE)
• Directive used to indicate the end of procedure.
• A procedure is usually assigned by a name ie, label. And to mark the end of a procedure, the name
may appear as a prefix with a directive ENDP.
Eg::STAR PROC
………………………
………………………
………………………
STAR ENDP
8. ENDS( End OF Segment)
• Marks the end of a logical segment
• Eg;;ASSUME DS: DATA
DATA SEGMENT
…..
DATA ENDS
9.EQU : EQUATE
• Used to assign a label with a value or symbol
• It is used to reduce the recurrence of the constants or numerical values in the pgm.
• Eg:: LABEL EQU 0500H
• The statement assigns LABEL with the value 0500H
10. EXTRN : External and PUBLIC : public
• The directive EXTRN informs the assembler that the names procedures, labels declared after this
directive have already been defined in some other assembly language modules..
• While in other module, where the names procedures ,labels actually appear, they must be declared
public , using the PUBLIC directive.
MODULE1 SEGMENT
PUBLIC FACTORIAL FAR
MODULE1 ENDS
MODULE2 SEGMENT
EXTRN FACTORIAL FAR
MODULE2 ENDS
11.GROUP : Group the related segments

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

• This directive is used to form logical groups of segments with similar


purpose or type.
• Eg:PROGRAM GROUP CODE , DATA, STACK
The above stmt directs the loader/linker to prepare an EXE file such that CODE, DATA, STACK segment must lie
within a 64kbyte memory segment that is named as program.
12. LABEL
• This directive is used to give name to the current content of the location counter.
• When the assembly process starts, the assembler initializes a location counter to keep track of the memory
locations assigned to the program. As the program assembly proceeds , the content of the location counter get
updated. During the assembly process , whenever the assembler comes across the LABEL directive, it assigns
the declared label with the current content of the location counter.
• The type of label must be declared.
FAR/ NEAR
BYTE/ WORD
12. LENGTH
• Used to refer the length of data array or string
MOV CX, LENGTH ARRAY
• This statement when assembled, will substitute the length of the array in bytes, in the instruction.
13. LOCAL
• The labels variables, constants or procedures declared LOCAL in a module used only by that particularmodule.
• After some time, some other module may declare a particular datatype LOCAL, which was previously declared
LOCAL by an other module or modules. Thus same label may serve different purposes for different modules.
Eg: LOCAL a, b, DATA, ARRAY, ROUTINE
14. NAME : Logical Name of a module
• Used to assign a name for your assembly language program
• The module may now be referred by its declared name.
15. OFFSET: Offset of a Label
• When the assembler comes across the OFFSET operator along with a label, it first computes the 16 bit
displacement of the particular label and replaces the string “OFFSET LABEL” by the computed displacement.
• This operator is used with arrays, strings, labels and procedures to decide their offsets in theirdefault segments.
• Its most common use is to refer the memory indirectly.
Eg:CODE SEGMENT
MOV SI, OFFSET LIST

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

CODE ENDS
DATA SEGMENT
LIST DB 10H
DATA ENDS
16. ORG : ORIGIN
• This directs the assembler to start the memory allotment for the particular block, segment or code
from the declared address in the ORG statement.
• If ORG statement is not written in the program , the location counter is initializes to 0000H
17. PROC: PROCEDURE
• Marks the starts of a named procedure in a given statement.
• Two types are specified depending on whether it has called by a pgm which is located in the same
segment or a different one.
FAR
NEAR
• Eg:RESULT PROC NEAR RESULT PROC FAR
• In the first statement the procedure which is called by the pgm located within the segment.
18. PTR
• The POINTER operator is used to declare the type of a label, variable or memory operand.
• If it is prefixed by BYTE then it is an 8-bit quantity. If by WORD then it is a 16-bit quantity.
• Eg:• MOV AL, BYTE PTR [SI]• Moves the contents of memory location addressed by Index Register to AL.
19. SEG: SEGMENT OF A LABEL
➢ This is used to decide the segment address of the label, variable or procedure and substitutes the
segment base address in place of “ SEG” label.
➢Eg::MOV AX, SEG ARRAY MOV DS, AXsegment address of ARRAY moved AX and then moved to DS
20. SHORT
➢It indicates the assembler that only one byte is required to code the displacement for a jump
➢The displacement is within -128 to +127 bytes from the address of the byte next to the jump code.
➢JMP SHORT LABEL
21. TYPE
• Helps to decide the data type of the specified label and replaces the TYPE label by the datatype.
MOV AX TYPE STRING
[For Word type ,datatype is 2 For double , datatype is 4 For byte, datatype is 1]
22. GLOBAL

Downloaded by Sri Msd (srimsd19@gmail.com)


lOMoARcPSD|30016554

• The labels, procedures ,variables or constants declared by GLOBAL can be used by all other
modules.
ROUTINE PROC GLOBAL
23. + & - Operators
❑Represent arithmetic addition and subtraction respectively,Typically add or subtract 8 or 16 bit
displacement value.
MOV AL, [SI +2]
24. FAR PTR
❑ Indicates the assembler that the label following FAR PTR is not available within the same segment
and the address of the label is of 32 bits ( 2 bytes offset followed by 2 byte segment address)
JMP FAR PTR LABEL
25. NEAR PTR
❖The label following NEAR PTR is in the same segment and needs only 16 bit ie, 2 bye offset to address it.

JMP NEAR PTR LABEL


CALL NEAR PTR ROUTINE
26. EVEN : Align on Even Memory Address
❖.Updates the location counter to the next even address, if the current location counter contents are
not even, and assigns the following routine or variable or constant to that address.
EVEN
A PROC
.....
ENDP

10

Downloaded by Sri Msd (srimsd19@gmail.com)

You might also like