Professional Documents
Culture Documents
Intruction Set & Assembler Directives of 8086
Intruction Set & Assembler Directives of 8086
1-May-23 1
1. Data Copy / Transfer Instructions
2. Arithmetic Instructions
3. Logical Instructions
4. Shift and Rotate Instructions
5. String Manipulation Instructions
6. Branch and Loop Instructions
5. Flag Manipulation Instructions
6. Machine Control Instructions
1-May-23 2
Instruction Set (continued...)
1. DATA TRANSFER INSTRUCTIONS
▪ Source: Seg.Register /
Gen.Register /Mem.location
▪ Destination: Seg.Register /
Gen.Register /Mem.location
▪ Note: Both Source and
Destination cannot be
Mem.Locn
1-May-23 3
Instruction Set (continued...)
General purpose byte or word transfer instructions
MOV Copy byte or word from specified source to specified
destination
PUSH Copy specified word to top of stack
POP Copy word from top of stack to specified
location
XCHG Exchange bytes or exchange words
XLAT Translate a byte in AL using a table in
memory
Simple input and output port transfer instructions
IN Copy a byte or word from specified port to
accumulator
OUT Copy a byte or word from accumulator to
specified port
1-May-23 4
Instruction Set (continued...)
Special address transfer instructions:
LEA Load effective address of operand into specified
register
LDS Load DS register and other specified register from
memory
LES Load ES register and other specified register from
memory
Flag transfer instructions
LAHF Load (copy to ) AH with the low byte of the flag
register
SAHF Store (copy) AH register to low byte of flag
register
PUSHF Copy flag register to top of stack
POPF Copy word at top of stack to flag register
1-May-23 5
Instruction Set (continued...)
Instruction Comments
MOV DS, 5000H Not Valid; immediate addressing with
segment registers not permitted
Example 1 :
*Knowing that,
DS=2042H.
SI=500H, AH AL
AX=214E, 21 4E
SI=500
DS=2042H DS=20420H
1-May-23 7
Instruction Set (continued...)
Example 2 :
Physical Address
PUSH AX
Stack Segment
AH AL 20000 SS = 2000
88 44 SP =
44 2FFFB FFFB
88 2FFFC FFFC
XX 2FFFD FFFD
XX 2FFFE FFFE
XX 2FFFF FFFF
1-May-23 8
Instruction Set (continued...)
Instruction Comments
• Pops stack top content pointed by SP into
Lower Byte of the register / mem. location
1. POP AX and next byte in the stack into Higher Byte
2. POP DS of the register / mem. location ; SPSP+2
3. POP [5000H] • Content of stack top and next byte in the
stack are popped into 5000H & 5001H in
DS
• Exchanges data b/w AX &
1. XCHG [5000H], AX
2. XCHG BX, AX mem.loc [5000H] in data seg.
•Exchange data b/w AX & BX
1. IN AL, 03H
2. IN AX, DX 03H is 8-bit port address
3. MOV DX, 0800H [DX] is 6-bit port address
IN AX, DX
1-May-23 9
Instruction Set (continued...)
Example 3 :
Physical Address
POP AX
Stack Segment
AH AL 20000 SS = 2000
xx
88 xx
44 SP =
44 2FFFB FFFB
88 2FFFC FFFC
XX 2FFFD FFFD
2FFFE FFFE
2FFFF FFFF
1-May-23 10
Instruction Set (continued...)
Instruction Comments
1-May-23 11
Instruction Set (continued...)
Example 4 :
AL Mem[AL+BX]
dddd+mmmm data
AL=dddd
BX=mmmm AL=data
1-May-23 13
Instruction Set (continued...)
1 2 83
KB(0-F) 8255 8086 CPU
User 16-Keys KBD 4 AL BX 5
interface 7
7-seg 9 6
Display
LUT
-
-
-
Example 5 : LUT- Mem.Seg
Performs
❑ Addition,
❑ Subtraction,
❑ Multiplication,
❑ Division,
❑ Increment,
❑ Decrement
along with ASCII and Decimal adjustment
INC Increment
1. INC AX 1. Register addressing
2. INC [BX] 2. Register indirect addressing
3. INC [5000H] 3. Direct addressing
DEC Decrement
1. DEC AX 1. Register addressing
2. DEC [BX] 2. Register indirect addressing
3. DEC [5000H] 3. Direct addressing
SUB Subtract
1. SUB AX, 0100H 1. Immediate addressing
2. SUB AX, BX 2. Register addressing
3. SUB AX, [SI] 3. Indexed / indirect addressing
4. SUB AX, [5000H] 4. Direct addressing
5. SUB [5000H], 0100H 5. Immediate addressing
CMP Compare
1. CMP AX, 0100H 1. Immediate addressing
2. CMP BX, 0100H 2. Immediate addressing
3. CMP BX, [SI] 3. Indexed / indirect addressing
4. CMP BX, CX 4. Register addressing
5. CMP [5000H], 0100H 5. Direct/Immediate addressing
ALHIGH ALLOW
Logical Instructions:
NOT Logical Invert: Invert each bit of a byte or word
in another byte or word
AND Logical AND: AND each bit in a byte or word with
the corresponding bit
OR Logical OR: OR each bit in a byte or word with the
corresponding bit in another byte or word
XOR Logical XOR: Exclusive OR each bit in a byte or
word with the corresponding bit in another byte or
word
TEST Logical Compare: AND operation to update flags,
[OF, CF, SF, ZF, PF] but don’t change operands
Logical Instructions:
NOT NOT AX;
NOT [5000H];
AND AND AX, 0008H;
AND AX, BX;
AND [5000H], DX;
OR OR AX, 0008H;
OR AX, BX;
OR DX, [5000H];
XOR XOR AX, 0098H; XOR AX, BX; XOR AX, [5000H];
TEST TEST AX, BX; TEST [5000H] 06H;
TEST [BX][DI], CX
x0 Carry Flag
MSB LSB
SHL / SAL
1st execution 10 1 01 10 01 0 1
0 01
1 Carry Flag
MSB LSB
SHL / SAL
2nd execution 1 0 1 0 0 1 0 0
Carry Flag
MSB LSB
0 1 1 0 1 0 0 1 x
Carry Flag
MSB LSB
1 0 1 0 1 0 0 1 x
1-May-23 52
ASSEMBLER DIRECTIVES &
OPERATORS
Hints given to the assembler using predefined alphabetical
strings to correctly understand the assembly language
programs and prepare machine codes – called as
ASSEBLER DIRECTIVES
1-May-23 53
Assembler Directives (continued...)
ASSEMBLER DIRECTIVES USED IN
MICROSOFT MACRO ASSEMBLER OR TURBO ASSEMBLER
DIRECTIVES
1.DB Define Byte
2. DW Define Word
3. DQ Define Quadword
4. DT Define Ten Bytes
5. END End of Program
6. ENDP End of Procedure
7. ENDS End of Segment
8. ASSUME Assume Logical Segment Name
9. SEGMENT Logical segment
1-May-23 54
Assembler Directives (continued...)
DIRECTIVES (continued….)
10. EQU Equate
11. EVEN Align on even memory address
12. EXTRN and External and Public
PUBLIC
13. LOCAL Local
14. GLOBAL Global
15. GROUP Group the related segments
16. LABEL Label
17. LENGTH Byte length of a label
18. NAME Logical name of a module
19. ORG Origin
20. PROC Procedure
1-May-23 55
Assembler Directives (continued...)
OPERATORS USED IN
MICROSOFT MACRO ASSEMBLER OR TURBO ASSEMBLER
DIRECTIVES (continued….)
21. FAR PTR Near pointer
22. NEAR PTR Far pointer
OPERATORS
1.OFFSET Offset of a label
2. PTR Pointer
3. SEG Segment of a label
4. SHORT Short
5. ‘+ and -’ Addition and subtraction operators
6. TYPE Type
1-May-23 56
Assembler Directives (continued...)
DIRECTIVES
1.DB DB directive is used to reserve bytes or bytes
of memory location , with data type that
may be a
-Constant
-Variable
-String etc
Example - 1
PRICE DB 49h, 98h, 29h ; Directs assembler to -
reserve an array of 3 bytes named as PRICE and initialize.
1-May-23 57
Assembler Directives (continued...)
Example - 2
MESSAGE DB ‘GOOD MORNING’;
Reserve an array of bytes equal to the number of
characters in the string named as MESSAGE and
initialize by the ASCII equivalent of these characters
Example – 3
TEMP DB 100 DUP(?) ;
Set 100 bytes of storage in memory and give it the name
as TEMP, but leave the 100 bytes uninitialized.
Program instructions will load values into
these locations.
DUP - Duplicates
1-May-23 58
Assembler Directives (continued...)
DIRECTIVES
2. DW DW directive is used to reserve words (16
bits) or words of memory location , with
data type that may be a
-Constant
-Variable
-String etc
Example - 1
WORDS DW 4987h, 1F98h, AB29h ;
Directs assembler to reserve an array of 3 Words named as
WORDS and initialize.
Lower bytes stored in lower and upper bytes stored in higher
addresses
1-May-23 59
Assembler Directives (continued...)
Example - 2
STAR DW 5 DUP (1234H);
Directs assembler to reserve an array of 5 Words
named as STAR and initializes all the locations with
Lower bytes stored in lower and upper bytes stored in
higher addresses
1-May-23 60
Assembler Directives (continued...)
DIRECTIVES
3. DQ DW directive is used to reserve 4 word bytes
(i.e 4 x 8 bits) of memory location , with data
type that may be a
-Constant
-Variable
-String etc; and may be initialized
DIRECTIVES
4. DT DW directive is used to reserve 10 bytes (i.e
10 x 8 bits) of memory location , with data
type that may be a
-Constant ; Variable; String etc
and may be initialized
- Generally processed by numerical
processors 1-May-23 61
Assembler Directives (continued...)
DIRECTIVES
5. END END of program directive marks the end of an
assembly language program (ALP).
-Ignores all source lines available after this line
-Must be used as the last statement in the file
6. ENDP END of procedure directive marks the end of
procedure.
1. In an ALP - subroutines are called procedure.
2. A procedure is an independent program
module
3. - PROCEDURE STAR
-
-
STAR ENDP
1-May-23 62
Assembler Directives (continued...)
DIRECTIVES
7. ENDS END of Segment directive - marks the end
of logical segment.
-Logical segments are assigned with names
using ASSUME directive
-Must be used the last statement in the
segment along with segment name as prefix
8. ASSUME -This directive is used to assign name for
logical segments
-ASSUME directive is a MUST at the
beginning of each ALP.
9. SEGMENT -Marks the starting of logical segment
-Also assigns a name to the logical segment
1-May-23 63
Assembler Directives (continued...)
EXAMPLE
ASSUME CS : CODE, DS : DATA
DATA SEGMENT
STAR DB 20 DUP (?)
:
:
DATA ENDS
CODE SEGMENT
:
:
:
CODE ENDS
END
1-May-23 64
Assembler Directives (continued...)
DIRECTIVES
10. EQU EQU directive is used to assign a label with
a value or symbol
-Used to reduce recurrence of numerical
values or constants in ALP code
-One change in the EQU statement will give
correct and modified code.
-When assembler comes across the label, it
substitutes the numerical values
EXAMPLE
CONST1 EQU 0510H assigns constant 0510h with
label CONST1
ADDITION EQU ADD assigns another label
ADDITION with mnemonic ADD
1-May-23 65
Assembler Directives (continued...)
DIRECTIVES
11. EVEN Align on even memory address directive updates
the location counter to next even address.
- While starting the assembling process, the
assembler initializes a location counter and
updates it sequentially to the program variables;
constants ; modules etc. as required.
EXAMPLE
EVEN
PROCEDURE ROOT
:
:
ROOT ENDP
1-May-23 66
Assembler Directives (continued...)
DIRECTIVES
12. EXTERN • EXTERN directive informs the assembler
and that the names / procedures / labels declared
PUBLIC after this directive have already been defined
in some other ALP module
• In the module where the names,
procedures, labels actually appear must be
declared PUBLIC
MODULE1 SEGMENT
EXAMPLE
PUBLIC FACTORIAL FAR
MODULE1 ENDS
MODULE2 SEGMENT
EXTRN FACTORIAL FAR
MODULE1 ENDS
1-May-23 67
Assembler Directives (continued...)
DIRECTIVES
13. LOCAL • LOCAL directive informs the assembler
that the labels / variables /constants /
procedures declared after this directive are
used ONLY by that particular module
• In some other module same labels /
variables /constants / procedures can be used
for different purposes.
• Single statement can be used to declare all
labels / variables /constants / procedures
1-May-23 68
Assembler Directives (continued...)
DIRECTIVES
14. GLOBAL • LOCAL directive informs the assembler
that the labels / variables /constants /
procedures declared after this directive can
be used by OTHER modules in the program
EXAMPLE
1-May-23 69
Assembler Directives (continued...)
DIRECTIVES
15. GROUP • Forms logical groups of segments with
similar purpose or types
• Assembler informs loader/linker to place
group declared segments or operands must
lie within 64KB memory segment
EXAMPLE
1-May-23 70
Assembler Directives (continued...)
DIRECTIVES
16. LABEL • Used to assign a name to the current
content of the location counter
•The type of the label must be specified (i.e)
NEAR or FAR label, BYTE or WORD label
1-May-23 71
Assembler Directives (continued...)
DIRECTIVES
17. LENGTH Used to refer to the length of a data array or
string
EXAMPLE MOV CX, LENGTH ARRAY
Substitutes the length of the array ARRAY in bytes
DIRECTIVES
18. NAME Used to assign a name to an ALP module
MULTI_PGM NAME
:
:
:
END
1-May-23 72
Assembler Directives (continued...)
DIRECTIVES
19. ORG Directs the assembler to start the memory
allotment for the particular block or code from
the declared address in the ORG statement
Without ORG location counter is initialized to
0000
EXAMPLE ORG 200H
Initializes the location counter to the address 0200h instead
of 0000h
1-May-23 73
Assembler Directives (continued...)
DIRECTIVES
20. PROC Marks the start of a named procedure
1-May-23 74
Assembler Directives (continued...)
DIRECTIVES
21. FAR PTR • Indicates the assembler that the label
following FAR PTR is not within the
same segment
• Address of label is of 32 bits (4 bytes)
[2 bytes offset followed by 2 bytes
segment address]
1-May-23 75
Assembler Directives (continued...)
DIRECTIVES
22. NEAR PTR • Indicates the assembler that the label
following FAR PTR is in the same
segment
• Address of label is of 16 bits (2 bytes)
[2 bytes offset only]
1-May-23 76
Assembler Directives (continued...)
OPERATORS
1. OFFSET OFFSET operator indicates the assembler
to compute the16 bit displacement (offset)
of the label and replace the string ‘OFFSET
LABEL’ by the computed displacement
Used with arrays, strings, labels and procedures to
decide their offset in their default segments
1-May-23 78
Assembler Directives (continued...)
OPERATORS
3. SEG SEG operator is used to decide the segment
address of the label, variable or procedure and
substitutes the segment base address in place of
‘SEG’ label
EXAMPLE
MOV AX, SEG ARRAY
MOV DS, AX
1-May-23 79
Assembler Directives (continued...)
OPERATORS
4. SHORT SHORT operator indicates to the assembler
that only one byte is required to code the
displacement for a jump
By specifying this way the assembler saves
memory.
EXAMPLE JMP SHORT LABEL
OPERATORS
5. +, - Represents arithmetic addition and subtration
1-May-23 81
Assembler Directives (continued...)