ch2 - Lec3 - 8086 Instruction Set - 1 (Data Movement)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Microprocessor and

Interfacing
Ch2_lec3_ Instruction Set: Data
Movement Instructions

Kassahun Tamir 1
Instruction Sets
 8086 instruction set is categorized into:-

✗ Data Movement Instructions

✗ Arithmetic and Logic Instructions

✗ String Manipulation Instructions

✗ Program Control Instructions


Kassahun Tamir 2
Data Movement Instruction

 These types of instructions are used to transfer data


from source operand to destination operand.

 All the store, move, load, exchange, input and output


instructions belong to this category.

Kassahun Tamir 3
MOV:- Move
 This data transfer instruction transfers data from one
register/memory location to another register/memory
location.

 The source may be any one of the segment registers or


other general or special purpose registers or memory
location, another register or memory location may act
as destination.

Kassahun Tamir 4
MOV:- Move
 Example
MOV AX, 2000H
MOV DS, AX
MOV AX, [2000H]
MOV [BX], CX
MOV CS, DS Illegal:
segment registers can’t be together

Kassahun Tamir 5
PUSH:- Push to Stack
 This instruction pushes the contents of the specified
register/memory location on to the stack.
 The stack pointer is decremented by 2, after each
execution of the instruction.

 Example
 PUSH AX
 PUSH DS
 PUSH AL Illegal, must push a word
Kassahun Tamir 6
PUSHF:- Push Flags to Stack

 The push flag instruction pushes the flag register onto


the stack; first the upper byte and then the lower bye
will be pushed onto the stack.

 The SP is decremented by 2, for each push operation.

Kassahun Tamir 7
POP:- Pop from Stack
 When this instruction is executed, it loads the specified
register/memory location with the contents of the
memory location of which the address is formed using
the current stack segment and stack pointer as usual.
 The stack pointer is incremented by 2.
 Example
POP AX
POP DS
POP CS Just Illegal
Kassahun Tamir 8
POPF:- Pop Flags from Stack
 The pop flags instructions loads the flag register
completely (both byte) from the word contents of the
memory location currently addressed by SP and SS.

 The SP is incremented by 2 for each pop operation.

Kassahun Tamir 9
XCHG:- Exchange
 This instruction exchanges the contents of the specified
source and destination operands, which may be a
registers or one of them may be memory location.
 However, exchange of data contents of two memory
location is not permitted.

 Example
XCHG [5000H], AX
XCHG BL, CH
Kassahun Tamir 10
XCHG:- Exchange
MOV AX, 125AH
MOV AH, 23H
XCHG AL, AH

 After the execution the above set of Instruction what will


be the value of the following registers?
AX= ________
5A23H
AL = _____
23H
AH = _____
5AH
Kassahun Tamir 11
INPUT:- 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 l6-
bit input operations.
 DX is the only register (implicit) which is allowed to
carry the port address.
 Example
IN AL, 0030H
MOV DX, 0130H
Kassahun Tamir 12
IN AX, DX
OUT:- Out the Port
 This instruction is used for writing an input port.
 The address of the input port may be specified in
the instruction directly or indirectly.
 AL and AX are the allowed sources for 8 and l6-bit
input operations.
 DX is the only register (implicit) which is allowed to
carry the port address.
 Example
OUT 0030H, AL
MOV DX, 0230H
Kassahun Tamir 13
OUT DX, AX
LEA:- Load Effective Address
 The load effective address instruction loads the
offset of an operand in the specified register.

 Example:
LEA BP, SS:STACK_TOP ;Load BP with offset of
;STACK_TOP in SS

LEA CX, [BX]+[DI] ;Load CX with


; EA = (BX)+(DI)
Kassahun Tamir 14
LDS/LES:- Load Pointer to DS/ES
 The instruction, Load DS/ES with pointer, loads the
DS or ES register and specified destination register
in the instruction with the content of memory
location specified as source in the instruction.
 Example
LDS BX, [5000H]
LES BX, [5000H]
BX YY XX XX 5000H
YY 5001H
DS/
nn mm mm 5002H
ES
nn 5003H
15
XLAT/XLATB:- Translate
 The translate instruction is used for finding out the
codes in case of code conversion problems, using
lookup table.
AL = DS:[BX + AL]
 Example 1
MOV AX, SEG TABLE
MOV DS, AX
MOV AL, CODE
MOV BX, OFFSET TABLE
XLAT Kassahun Tamir 16
XLAT/XLATB:- Translate
 Example 2

dat DB 11h, 22h, 33h, 44h, 55h

LEA BX, dat


MOV AL, 2
XLATB ; AL = 33h

Kassahun Tamir 17
LAHF:- Load AH from lower byte of
Flag
 This instruction loads the AH register with the lower
bye of the flag register.

 This instruction may be used to observe the status


of all the condition code flag (except overflow) at a
time.

Kassahun Tamir 18
SAHF:- Store AH from lower byte of
Flag
 This instruction sets or resets the condition code
flags (except overflow) in the lower byte of the flag
register depending upon the corresponding bit
positions in AH.

Kassahun Tamir 19
Example
 Explain what does the following set of instructions do?

MOV AX, B800H ;Set AX to hexadecimal value of B800h


MOV DS, AX ; copy value of AX to DS
MOV CL, 128 ; set CL to decimal value
MOV CH, 11011111b ; set CH to binary value
MOV BX, 015EH ; set BX to 15Eh
MOV [BX], CX ; copy contents of CX = DF80H to
memory at B800:015E
Kassahun Tamir 20
Example
 Determine the contents of the GP registers after
these programs got executed.

MOV AX, 1234H


MOV BX, 5678H
PUSH AX
PUSH BX
POP AX
POP BX

AX= 5678H BX= 1234H


Kassahun Tamir 21
Exercise
 Write a program that loads AX register by 4567H
and BL by 34H and then copy that to a memory
address of 45234H and DL registers respectively.
(Assume DS starts at 4000H)
 Solution:
MOV AX, 4567H
MOV BL, 34H
MOV CX, 4000H
MOV DS, CX
MOV [5234H], AX
MOV DL, BL Kassahun Tamir 22
Exercise
 Write a program to accept an input 8-bit data from
port number 125H and store the data to memory
address of 51000H
 Solution:
MOV DX, 125H
IN AL, DX
MOV BX, 5000H
MOV DS, BX
MOV [1000H], AL
Kassahun Tamir 23
Exercise
 Write a program to display an output 16-bit data to
port number 25H from a memory address of
51000H.

 Solution:
MOV AX, 5000H
MOV DS, AX
MOV AX, [1000H]
MOV DX, 25H
OUT DX, AX Kassahun Tamir 24
Questions?

Kassahun Tamir 25

You might also like