You are on page 1of 35

1

INTRODUCTION

2
DATA TRANSFER OPERATIONS

3
IMMEDIATE DATA TRANSFER INSTRUCTIONS

4
EXAMPLE 1

5
EXAMPLE 2

Load the accumulator A with the data byte 82H


(the letter H indicates hexadecimal number), and
save the data in register B.

Instructions: MVI A, 82H,


MOV B,A

The first instruction is a 2-byte instruction that


loads the accumulator with the data byte 82H, and
the second instruction MOV B,A copies the
contents of the accumulator in register B without
changing the contents of the accumulator.
6
Data Transfer

PROBLEM STATEMENT
• Load the hexadecimal number 37H in register B, and
display the number at the output port labeled
PORT1.

PROBLEM ANALYSIS
• Step 1: Load register B with a number.
• Step 2: Send the number to the output port.

7
Move Immediate Instructions

8
Move Immediate Instructions

The memory location, which is indirectly


addressed by the HL register pair, appears
as the letter M in all instructions.

9
Direct Data Transfer Instructions

10
Direct Data Transfer Instructions

11
Direct Data Transfer Instructions

12
Direct Data Transfer Instructions

Copies the contents of


stores the contents of the
location 1000H into the L
L register at memory
register and the contents
location I200H and the H
of location 1001 H into
register at location 1201H
the H register

13
INDIRECT DATA TRANSFER INSTRUCTIONS

With register indirect addressing, a register pair


holds the address of the memory location
accessed by the instruction.
The contents of the register pair indirectly
addresses a memory location.
Whenever, the letter M appears instead of a
register, the HL register pair indirectly addresses a
memory location.

14
INDIRECT DATA TRANSFER INSTRUCTIONS

15
INDIRECT DATA TRANSFER INSTRUCTIONS

16
REGISTER DATA TRANSFER INSTRUCTIONS

17
REGISTER DATA TRANSFER INSTRUCTIONS

18
STACK DATA TRANSFER INSTRUCTIONS

19
STACK DATA TRANSFER INSTRUCTIONS

The programmer decides what portion of the


read/write memory is to function as the stack, and
then loads the SP with the top location plus one
byte.
The byte location above the stack is never used,
but must be the initial value of the stack pointer.
The SP always points to the current exit point.
The stack is a LIFO stack.

20
STACK DATA TRANSFER INSTRUCTIONS

If data are pushed (placed) onto the stack, they


move into the memory locations addressed by
SP-1 and SP-2.
• Note that pairs of registers always move to the
stack.
• A PUSH instruction stores the high-order register
first (SP - 1), followed by the low-order register
(SP -2).

21
STACK DATA TRANSFER INSTRUCTIONS

22
STACK DATA TRANSFER INSTRUCTIONS

23
STACK DATA TRANSFER INSTRUCTIONS
It is also important to note that PUSHes and POPs
must occur in pairs:
• one PUSH, one POP,
• two PUSHes, two POPs, and so on.

Note: POP PSW will copy the data from location pointed by
SP into flag register and data from (SP+1) will copy into A. The
SP=SP+2.

24
MISCELLANEOUS DATA TRANSFER INSTRUQTIONS

Exchange DE with HL (XCHG)


• The XCHG instruction exchanges the contents of
the HL register pair with the contents of the DE
register pair.
Load SP from HL (SPHL)
• Is a one-byte instruction, copies the contents of the
HL register pair into the SP.

25
MISCELLANEOUS DATA TRANSFER INSTRUQTIONS

Exchange HL with Stack Data (XTHL)


• This instruction exchanges the contents of the HL
pair with the most recent data on the stack.
Input/Output Data Transfer Instructions
• IN : instruction inputs data from an I/O device into
the accumulator.
• OUT : sends accumulator data out to an I/O device.

26
EXAMPLE
Write instructions to read 8 ON/OFF switches connected to the input
port with the address OOH, and turn on the devices connected to the
output port with the address 01H, as shown in Figure 6.1.

27
SOLUTION FOR EXAMPLE

The input has eight switches that are connected to


the data bus through the tri-state buffer.
• Any one of the switches can be connected to +5 V
(logic 1) or to ground (logic 0),
• and each switch controls the corresponding device
at the output port.
• The microprocessor needs to read the bit pattern on
the switches and send the same bit pattern to the
output port to turn on the corresponding devices.

28
SOLUTION FOR EXAMPLE
Instructions: IN OOH
OUT 01H
HLT

 When MPU executes the instruction IN 00H, it enables the tri-


state buffer.
 The bit pattern 4FH formed by the switch positions is placed
on the data bus and transferred to the accumulator (reading
an input port).
 When MPU executes OUT 01H,
 it places the contents of the accumulator on the data bus and
enables the output port O1H (writing to output port).
 The output port latches the bit pattern and turns ON/OFF the
devices connected to the port according to the bit pattern.
29
Data Transfer

30
Data Transfer

31
Exercises

Write instructions to read the data at input PORT


07H and at PORT 08H. Display the input data
from PORT 07H at output PORT OOH, and store
the input data from PORT 08H in register B.

Explain the program with drawing:


Push B
Push H
Pop B
Pop h

32
Exercises

Write a sequence of immediate instructions that


store a 16H into memory location 1200H and a
17H in memory location 1202H.
Write a sequence of instructions that use register
indirect addressing to transfer the contents of A
into location 2800H, B into 2801H, and C into
2802H.
Write a sequence of instructions that use register
indirect addressing to transfer the number stored
in memory location 1300H into memory location
2302H.

33
Consider the given problem statement. Let us write a program to move a
block of 16-bit data stored from DF10H to DF1FH to a target location from
DF70H to DF7FH

LXI H, DF10H
LXI D, DF70H
MVI B, 10H
LOOP:MOV A, M
STAX D
INX H
INX D
DCR B
JNZ LOOP
HLT
Let us go through the step by step analysis of our program.

LXI H, DF10H
We first load the memory address DF10H into the register pair H-L.

LXI D, DF70H
We then load the memory address DF70H into the register pair D-E.

MVI B, 10H
Since we need to move 16 bits of data, we need to set a counter for 16 counts. Thus, we assign 10H (hex for 16) counts for register B.

LOOP : MOV A, M
We shall now move the first bit of data from the memory location DF10H to the accumulator register.

STAX D
The data copied to the accumulator is now copied to the register pair D-E, which in turn moves to the memory location DF70H.

INX H
Now that we have copied the value from the first memory location, we increment the pointer to the next location.

INX D
We do not want to overwrite on the same memory location, do we? So we increment the destination address by one value too.

DCR B
As we have finished moving one bit, we decrease the counter by one value.

JNZ LOOP
Until register B is not zero, we jump back to the label LOOP and repeat the steps until everything has been copied.

HLT
After completing the program, we put an end / halt the program by using the HLT instruction.

We can now see that our 16-bit data has been moved to the memory locations from DF70H to DF7FH.

About the author

You might also like