United States International University Africa
Nairobi, Kenya
APT2022: INTRODUCTION TO ASSEMBLY PROGRAMMING
FALL 2021 SEMESTER
Prepared By:
Linus Aloo
E-mail: laloo@usiu.ac.ke
Phone: 0754188380
References
1. Assembly Language for x86 Processors, 6th Ed. Kip R. Irvine, Prentice Hall, 2010
2. Computer organization and Architecture: Designing for Performance, Stallings W.,
Prentice Hall, 8th Edition, 2010.
3. Structured Computer Organization, 5-th edition, Andrew S. Tanenbaum, Prentice
Hall, 2010.
12/07/2021 APT2022 1
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
INSTRUCTION SET OF 8086
Objectives
1. Appreciate the 8086 Instruction set
2. Identify types of 8086 assembly language instructions
3. Describe different 8086 assembly language instructions
4. Apply 8086 microprocessor assembly language
instructions
12/07/2021 APT2022 2
INSTRUCTION SET OF 8086
Instructions refer to the directions which a microprocessor follows to execute a task or part of a ta
8086 microprocessor has a total of 117 basic instructions.
Instructions for 8086 microprocessor can be classified into the following 8 main types on the basis of functions they
perform:
Data Transfer Instructions
Arithmetic Instructions
Bit Manipulation Instructions
Program Execution Transfer Instructions (Branch & Loop Instructions)
Flag Manipulation and Processor Control Instructions
Iteration Control Instructions
Interrupt Instructions
String (manipulation) Instructions
12/07/2021 APT2022 3
INSTRUCTION SET OF 8086
1. Data Transfer Instructions
Data transfer instructions – are used to move data in to registers, a storage location in memory
and I/O ports.
Cannot move data from one memory location to another memory location.
Generally involve two operands: Source operand and Destination operand of the same size.
Source: Register or a memory location or an immediate data
Destination : Register or a memory location.
The size should be a either a byte or a word where 8-bit data can only be moved to 8-bit
register/ memory and a 16-bit data can be moved to 16-bit register/ memory.
12/07/2021 APT2022 4
INSTRUCTION SET OF 8086
1. Data Transfer Instructions
The following instructions come under this group:
a) Instruction to transfer a word
MOV − Used to copy the byte or word from a specified source to the specified destination.
PPUSH − Used to put a word at the top of the stack.
POP − Used to get a word from the top of the stack to the specified location.
PUSHA − Used to put all the registers into the stack.
POPA − Used to get words from the stack to all registers.
XCHG − Used to exchange the data from two locations.
XLAT/XLATB − Reads a byte from the lookup table.
12/07/2021 APT2022 5
INSTRUCTION SET OF 8086
1. Data Transfer Instructions
b) Instructions for input and output port transfer
IN − Transfers data from a port to the accumulator or AX, DX or AL register.
OUT − Used to send out a byte/word from the accumulator to the provided port.
c) Instructions to transfer the address
LEA − Used to load the address of operand into the provided register.
LDS − Used to load DS register and other provided register from the memory
LES − Used to load ES register and other provided register from the memory.
12/07/2021 APT2022 6
INSTRUCTION SET OF 8086
1. Data Transfer Instructions
d) Instructions to transfer flag registers
LAHF − Used to load AH with the low byte of the flag register.
SAHF − Used to store AH register to low byte of the flag register.
PUSHF − Used to copy the flag register at the top of the stack.
POPF − Used to copy a word at the top of the stack to the flag register.
12/07/2021 APT2022 7
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Instruction Set
1. Data Transfer Instructions: Move instruction
The most frequently used data transfer instruction is the move operation,
mnemonic MOV.
Syntax: MOV destination, source ; move data from source to
destination
Example:
MOV AL, BL ; register to register
MOV AL, #16 ; immediate (a value 16) to register
When the segment register is used in a data transfer operation then the move
instruction must be applied to a 16-bit data.
For example, Mov SS, data
where SS represents a segment register, such as DS, ES, then data must be a 16-
bit value.
12/07/2021 APT2022 8
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Instruction Set: Data Transfer Instructions: Move instruction
Mnemonic Meaning Format Operation Flags affected
Table 3.1. Mov Move mov D,S (S) to (D) none
Destination (D) Source (S)
Memory AX
Table 3.1. shows the AX Memory
syntax for the MOV Register Register
instruction and the Register Memory
possible Memory Register
combinations for Register Immediate
Memory Immediate
the source and
Seg-reg Reg16
destination. Seg-reg Mem16
Reg16 Seg-reg
Mem16 Seg-reg
12/07/2021 APT2022 9
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Instruction Set
1. Data Transfer Instructions: Special data transfer instructions
XCHG – exchange data between the source and destination
Syntax : XCHG AX, DX ; value in DX is stored in AX and value in
AX stored in DX
Load effective address (LEA) is a frequently used instruction for saving the
offset address of a variable. This is similar to x = &y in C++ programming!
LEA is a very important operation because it allows you to obtain an address
of a variable or an array then you can apply the relative addressing modes!!!!
Syntax: LEA SI, INPUT ; effective address of INPUT will be stored in SI
register
INPUT in the above example represents a variable
Since an offset address is stored so the destination must be a 16-bit register!
An offset address is a 16-bit value!!!
12/07/2021 APT2022 10
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Instruction Set
1. Data Transfer Instructions: Special data transfer instructions
Load effective address (LEA)
LEA usually is used to access data defined in the program, as shown below.
Example
Dat db 11H, 22H, 33H, 44H
LEA BX, dat
MOV AL, [BX+2] ; this is register relative addressing mode
QUESTION: What is being stored in AL if dat is defined as above??
12/07/2021 APT2022 11
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Instruction Set
1. Data Transfer Instructions: Special data transfer instructions
Load register and DS (LDS)
As its name implies, LDS will load a specified register and the DS register
in a single operation!
Syntax: LDS SI, [200] ; 4 bytes of data will be fetched, the first 2 bytes
(location 200 and 201) stored in SI and the following 2 bytes (locations
202 and 203) stored in DS.
There is also the load register and ES (LES). Similar to LDS, LES will load a
specific register and the ES register.
12/07/2021 APT2022 12
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Instruction Set
1. Data Transfer Instructions: Special data transfer instructions
PUSH: Syntax is PUSH reg16/ mem i.e.
PUSH reg16
PUSH mem
POP: Syntax is POP reg16/ mem i.e
POP reg16
POP mem
12/07/2021 APT2022 13
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Instruction Set
1. Data Transfer Instructions: Special data transfer instructions
IN OUT
IN A, [DX] OUT [DX], A
IN AL, [DX] PORTaddr = (DX) OUT [DX], AL PORTaddr = (DX)
(AL) (PORT) (PORT) (AL)
IN AX, [DX] OUT [DX], AX PORTaddr = (DX)
PORTaddr = (DX)
(AX) (PORT) (PORT) (AX)
IN A, addr8 OUT addr8, A
OUT addr8, AL (addr8) (AL)
IN AL, addr8 (AL) (addr8)
OUT addr8, AX
IN AX, addr8
(AX) (addr8) (addr8) (AX)
12/07/2021 APT2022 14
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Example of Assembly Language Program
12/07/2021 APT2022 15
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Lab Practice Exercise 3
Title: 8086 Instruction Set Practice: Data Transfer Instructions
Objective: To apply Data Transfer Instructions in Assembly Language Programming
1. Enter the following sample program in
Activities:
Emu 8086.
1. Repeat execution of the program with the following and record
2. Redefine the assembler directives to your results for all registers (general purpose, Special function
make the code run. and Flag):
.code ; indicate start of code segment a) AX= 02H , BX=08H and CX=0.
b) AX= 2AH , BX=008EH and CX=05H
.startup ; indicate start of program c) AX= 12345 , BX=4568 and CX=10.
movAX, 00H 2. With CX initialized to zero i.e CX=0, exchange contents of AX
mov BX, 0000H and BX in a)-c) above and record your results.
mov CX, 0 3. Repeat Step 1 and 2 with BX replaced with DX. Comment.
3. Comment on the flow of the program and how the instructions
mov SI, AX are executed.
mov DI, BX 4. Comment on your experience with the mov instruction.
mov BP, CX 5. Using simple examples of your own, show how the
following data transfer instructions may be used with Emu
8086: XCHG, LEA,LDS,PUSH,POP, IN and OUT.
END ; end of file
12/07/2021 APT2022 16