2-Data Transfer
2-Data Transfer
INTRODUCTION
2
DATA TRANSFER OPERATIONS
3
IMMEDIATE DATA TRANSFER INSTRUCTIONS
4
EXAMPLE 1
5
EXAMPLE 2
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
9
Direct Data Transfer Instructions
10
Direct Data Transfer Instructions
11
Direct Data Transfer Instructions
12
Direct Data Transfer Instructions
13
INDIRECT DATA TRANSFER INSTRUCTIONS
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
20
STACK DATA TRANSFER INSTRUCTIONS
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
25
MISCELLANEOUS DATA TRANSFER INSTRUQTIONS
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
28
SOLUTION FOR EXAMPLE
Instructions: IN OOH
OUT 01H
HLT
30
Data Transfer
31
Exercises
32
Exercises
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.