View Course Path

Data Transfer Instructions in 8085 – With example codes

The complete set of instructions supported by a microprocessor is called its Instruction Set. Intel’s 8085 has 246 instructions. A binary value denotes each instruction of the 8085. These 8-bit binary values are called Op-Codes or Instruction Bytes.

The opcode is the first part of an instruction that specifies the operation that is to be performed. Whereas, the operand is the second (or third) part of the instruction on which the operation is performed. You’ll understand this more clearly as we progress through the instruction set.

The 246 instructions of the 8085 are classified into various categories. We’ll take a look at all these categories in this 8085 course. In this post, we’ll start with the data transfer instructions.

There are varying sizes of an instruction depending on the size of the opcode and the operand. The 8085 is an 8-bit processor, and the smallest size of the machine code of its instruction is 8-bit or 1 byte. The size of the machine code of a processor is known as the Instruction word size. For the 8085 (an 8-bit processor), the word size, one word is 8-bits (1 byte). For an ARM Cortex-M3 processor (a 32-bit processor), the word size is 32-bits.

Data Transfer Instructions

These instructions are used to move data between the registers, or between memory and the registers. These instructions perform a simple task – to copy data from a source to a destination. While copying the contents stored in the source are not altered. They are also referred to as copy instructions.

Let’s start with a summary of all the instructions that are used to copy data from one place to another inside the 8085 microprocessor.

In this table, R -> register; M -> Memory (HL register pair); data -> direct data; rp -> any of the three register pairs; A -> Accumulator; SP-> Stack pointer

Operation Instruction Description
Register to register
MOV R1,R2 [R1] <- [R2]
XCHG [HL] <-> [DE]
Register to memory
MOV M,R [[HL]] <- [R]
STA address [address] <- [A]
SHLD address
[address] <- [L] [address+1] <- [H]
STAX rp [[rp]] <- [A]
Memory to register
MOV R,M [R] <- [[HL]]
LDA address [A] <- [[address]]
LHLD address
[L] <- [[address]] [H] <- [[address+1]]
LDAX rp [A] <- [[rp]]
Data to register
MVI R,data [R] <- data
LXI rp,data16
[rp] <- 16-bit data
8 MSBs in upper register
8 LSBs in lower register
Data to memory MVI M,data [[HL]] <- data
Stack operations
PUSH rp
[[SP]-1] <- [rupper] [[SP]-2] <- [rlower] [SP] <- [SP]-2
PUSH PSW
[[SP]-1] <- [A] [[SP]-2] <- [PSW] [SP] <- [SP]-2
POP rp
[rlower] <- [[SP]] [rupper] <- [[SP]+1] [SP] <- [SP]+2
POP PSW [PSW] <- [[SP]] [A] <- [[SP]+1] [SP] <- [SP]+2
XTHL [L] <-> [[SP]] [H] <-> [[SP]+1]
SPHL [SP] <- [HL]
I/O data transfer
IN port address
[A] <- [value at port]
OUT port address
[A] -> [value at port]

Now, we’ll see these data transfer instructions in detail, one at a time.

MOV

The Opcode

The Operands

Description

MOV

R1, R2 Copy between two registers

[R1] <- [R2]
R, M Copy from register to the location pointed by the HL pair (M)

[[HL]] <- [R]
M, R Copy from the location pointed by the HL pair (M) to register

[R] <- [[HL]]

The MOV instruction copies the contents of the source register/location pointed by the HL pair (M) into the destination register/memory location pointed by the HL pair (M). The contents of the source are not altered.

Size of instruction

1 byte

Addressing mode

MOV R1, R2 – Register; MOV M, R – Direct; MOV R, M – Register Indirect

Flags affected

None

Example

  • MOV B, C
  • MOV B, M
  • MOV M, C

MVI

The Opcode The Operands Description

MVI

R, Data

Move immediate 8-bit into a register

[R] <- Data

M, Data

Move immediate 8-bit data into the memory location pointed by the HL pair (M)

[[HL]] <- Data

Here, an 8-bit immediate data is stored in the destination register or a memory location, which is pointed by the HL register pair.

Size of instruction

2 bytes

Addressing mode

Immediate

Flags affected

None

Example

  • MVI A, 57H
  • MVI M, 57H

LXI

The Opcode The Operand Description

LXI

rp, Data

Load the register pair with an immediate value

[rp] <- 16-bit data

8 MSBs in the upper register

8 LSBs in the lower register

This instruction loads a 16-bit immediate data in the memory location pointed by the HL pair (M).

Size of instruction

3 bytes

Addressing mode

Immediate

Flags affected

None

Example

  • LXI H, 2034 H //here 20H is stored in register H, and 34H is stored in register L.

LDA

The Opcode

The Operand

Description

LDA

16-bit address

Load Accumulator with contents stored at an address

[A] <- [[address]]

The contents from the address (addresses in 8085 are 16-bit) are copied to the accumulator register. The contents of the source location remain unaltered.

Size of instruction

3 bytes

Addressing mode

Direct

Flags affected

None

Example

  • LDA 2034H //Contents stored at memory location 2034H are copied into the accumulator.

LDAX

The Opcode

The Operand

Description

LDAX

Either B/D Register Pair

Load accumulator with data at the memory location pointed by the contents of the register pair.

[A] <- [[rp]]

The contents of the mentioned register pair point to a memory location. LDAX instruction copies the contents of that particular memory location into the accumulator register. Neither the contents of the register pair nor that of the memory location is altered.

Size of instruction

3 bytes

Addressing mode

Register Indirect

Flags affected

None

Example

  • LDAX B
  • LDAX D

LHLD

The Opcode

The Operand

Description

LHLD

16-bit address

Load the H-L registers with contents location at memory locations given by the address value

[L] <- [[address]]

[H] <- [[address+1]]

The LHLD instruction copies the contents of a specified memory location pointed out by a 16-bit address into register  L. The contents of the next memory location are copied into register H.

Note that it is confusing to dabble with the 8-bit and 16-bit disparity. Remember this, the address of the memory location is 16-bit, but the content AT that memory location is 8-bit. So it makes sense for the contents at a particular memory location to fit into an 8-bit register.

Size of instruction

3 bytes

Addressing mode

LHLD Memory

Flags affected

None

Example

  • LHLD 2100H

STA

The Opcode

The Operand

Description

STA

16-bit address value

Store from the accumulator into a memory location

[address] <- [A]

The contents of the accumulator register are copied into a memory location, which is specified by the operand.

Size of instruction

3 bytes

Addressing mode

Direct

Flags affected

None

Example

  • STA 1000H

STAX

The Opcode

The Operand

Description

STAX

Register pair

Store contents of the accumulator into other register pair

[[RP]] <- [A]

The contents of the accumulator register are copied into the memory specified by the register pair in the operand.

Size of instruction

1 byte

Addressing mode

Indirect

Flags affected

None

Example

  • STAX B
  • STAX D

SHLD

The Opcode

The Operand

Description

SHLD

16-bit address

Stores from the H-L registers into the specified location

[address] <- [L]

[address+1] <- [H]

The first 8-bit contents of the register L is stored into the memory location specified by the 16-bit address. The next 8-bit contents of the register H are stored into the subsequent memory location.

Size of instruction

3 bytes

Addressing mode

Direct

Flags affected

None

Example

  • SHLD 1200H

XCHG

The Opcode

The Operand

Description

XCHG

None

Exchange H-L with D-E

[HL] <-> [DE]

The contents of register pair H-L are exchanged with the contents of the register-pair D-E. The information stored in register H is exchanged with that of D; similarly, that in register L is exchanged with the contents of the register E.

Size of instruction

1 byte

Addressing mode

Implicit

Flags affected

None

Example

  • XCHG

Stack Control Instructions

PUSH

The Opcode

The Operand

Description

PUSH

R

Pushes onto stack

[[SP]-1] <- [rupper] [[SP]-2] <- [rlower] [SP] <- [SP]-2

The PUSH command pushes the contents of the register onto the stack in 8085, which saves it as a temporary copy. You can read more about stacks and stack pointers in 8085 here.

Size of instruction

1 byte

Addressing mode

Indirect

Flags affected

None

Example

  • PUSH H
  • PUSH B

PUSH PSW

The Opcode

The Operand

Description

PUSH

PSW

Pushes PSW onto the stack

[[SP]-1] <- [A] [[SP]-2] <- [PSW] [SP] <- [SP]-2

The PUSH PSW command pushes the contents of the PSW (Program status word or flag register) onto the stack in 8085, which saves it as a temporary copy.

The stack pointer is first decremented by one, and the contents of the accumulator are copied to that particular location. The stack pointer is again decremented by one, and the contents of the flag register (PSW) are copied to that location.

Size of instruction

1 byte

Addressing mode

Indirect

Flags affected

None

Example

  • PUSH PSW

POP

The Opcode

The Operand

Description

POP

R

Pops from the stack

[rlower] <- [[SP]] [rupper] <- [[SP]+1] [SP] <- [SP]+2

The POP command pops the contents stored onto the stack (where it might have been saved as a temporary copy) to a register.

Size of instruction

1 byte

Addressing mode

Indirect

Flags affected

None

Example

  • POP H
  • POP B

POP PSW

The Opcode

The Operand

Description

POP

PSW

Pops PSW from the stack

[PSW] <- [[SP]] [A] <- [[SP]+1] [SP] <- [SP]+2

The data at the memory location pointed by the stack pointer are copied to the flag register. The stack pointer is incremented by one, and the contents of that location are copied to the accumulator. The stack pointer is again incremented by one.

Size of instruction

1 byte

Addressing mode

Indirect

Flags affected

None

Example

  • POP PSW

XTHL

The Opcode

The Operand

Description

XTHL

Exchange the contents at the top of the stack with HL pair

[L] <-> [[SP]] [H] <-> [[SP]+1]

Contents of L register are exchanged with top of the stack. The stack pointer is incremented, and the contents of the next location of the stack are exchanged with H register. The contents of the stack pointer register are not altered.

Size of instruction

1 byte

Addressing mode

Indirect

Flags affected

None

Example

  • XTHL

SPHL

The Opcode

The Operand

Description

SPHL

Move contents of HL pair to SP register

[SP] <- [HL]

Contents of L register are exchanged with top of the stack. The stack pointer is incremented, and the contents of the next location of the stack are exchanged with H register. The contents of the stack pointer register are not altered.

Size of instruction

1 byte

Addressing mode

Register

Flags affected

None

Example

  • SPHL

I/O Data Transfer Instructions

IN

The Opcode

The Operand

Description

IN

8-bit port address

Input contents at port shifted to the accumulator

[A] <- [value at port]

The current 8-bit contents available at the PORT# mentioned will be shifted to the Accumulator register.

Let us consider the PORT having 8 DIP switches connected. Let the states of these switches be ON-OFF-OFF-ON-ON-OFF-OFF-ON. Thus, after the execution of the IN PORT# command, the accumulator register’s contents will be updated to 1001 1001.

Size of instruction

2 bytes

Addressing mode

Direct

Flags affected

None

Example

  • IN 15

OUT

The Opcode

The Operand

Description

OUT

8-bit port address

Contents of the accumulator shifted to port

[A] -> [value at port]

The 8-bit value stored in the accumulator register gets copied on to the PORT#.

Let us consider the initial contents of the Accumulator register to be 0011 0011. An LED system consisting of 8 LEDs is connected with the 8-bit port. Thus, after the execution of the instruction OUT PORT#, the LEDs will have the ON-OFF states as displayed below.

LED Orientation
LED Orientation

Size of instruction

2 bytes

Addressing mode

Direct

Flags affected

None

Example

  • OUT 35

Simulation using the Sim8085 Emulator

The example codes in this 8085 course have been executed in an online development environment called Sim8085. It is a simple environment that is really user-friendly for beginners. You can write codes for the Intel 8085 microprocessor, debug the assembly code, and then simulate the 8085 microprocessor. Check it out here.

Let us walk through the simulator and see how to use it and run our programs.

Sim8085 - Main Page
Sim8085 – Main Page

When you open the Sim8085 page, you will see the above image. Let us go through each of the functionalities of this page and begin with our programming!

guide to the sim8085 simulator

  • CODE EDITOR (1) –   You can enter your ALP code here.
  • PROGRAMMING BUTTONS(2)  – Let us go through each of these buttons in detail.

A. Compile Button
This button is used for compiling and loading the compiled opcodes into the memory. The compiled output is then displayed in the editor.

B. Run Button
Once you have compiled your 8085 code, run the program by pressing this button.     

C. Step Button
Want to know how the contents of the registers changes in each step? Click this button for the step-by-step analysis of the code.     

D. Stop Button
You can stop the execution of the program by clicking this button.     

E. Reset Button
Reset all the registers, memory locations’ contents, and flags by pressing this button.

  • REGISTER VIEW AND EDITING(3) –  Here, you can see the value of the registers, or also edit them. (SP and PC cannot be edited.)
  • FLAGS VIEW AND EDITING(4) –  You can see the contents of the Flags here. You can also set/unset them manually, as per your convenience.
  • MEMORY LOCATION VIEW AND EDITING(5) -The memory location view displays the total 65536 (0xFFFF) memory cells which are available in 8085. You can also edit them by double-clicking on them.
  • MEMORY VIEW STARTING ADDRESS(6) – Since there are so many locations to be viewed, this dropdown helps to set the range of values to see the memory view.
  • RANGE CONTROL FOR THE MEMORY ADDRESS(7) – You can slide this to get a finer control on viewing the memory locations.
  • ADDRESS FINDER(8) – Tired searching for one particular address? Enter it here and jump directly to the mentioned location!

Assembly Language Programming Using Data Transfer Instructions

We shall now see an Assembly Language Programme using these instructions and see how these instructions are put to use.

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.

  1. LXI H, DF10H

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

  2. LXI D, DF70H

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

  3. 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.

  4. LOOP : MOV A, M

    We shall now move the first bit of data from the memory location DF10H to the accumulator register.

  5. 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.

  6. INX H

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

  7. 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.

  8. DCR B

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

  9. JNZ LOOP

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

  10. 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.

2 thoughts on “Data Transfer Instructions in 8085 – With example codes

  1. I am preparing for my exams, and these articles on 8085 instructions are the best to learn from

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.