Tutorialspoint.dev

8085 program to swap two 8-bit numbers

Problem – Write an assembly language program to swap two 8-bit numbers stored in 8085 microprocessor.

Assumption – Suppose there are two 8-bit numbers. One 8-bit number is stored at location 2500 memory address and another is stored at location 2501 memory address. Let 05 is stored at location 2500 and 06 is stored at location 2501 (not necessarily, can be any two 8-bit numbers).

Example –



Algorithm –

  1. Load accumulator with the content of any one location (either 2500 or 2501 or any given location).
  2. Move the contents of accumulator to any register (say B) so that another location’s content can be loaded to accumulator and the previous data of accumulator get saved in register.
  3. Store the content of accumulator to another location (data of 2501 to 2500).
  4. Load accumulator with content of register and then store it to another address location.

Program –

Address Mnemonics Comments
2000 LDA 2500 A<-[2500]
2003 MOV B,A B<-A
2004 LDA 2501 A<-[2501]
2007 STA 2500 2500<-[A]
200A MOV A,B A<-B
200B STA 2501 2501<-[A]
200E HLT Terminates the program

Explanation –

  1. LDA 2500 – Load accumulator with content of location 2500
  2. MOV B,A – Copy content of accumulator to register B
  3. LDA 2501 – Load accumulator with content of location 2501
  4. STA 2500 – Store content of accumulator to location 2500
  5. MOV A,B – Copy content of register B to accumulator
  6. STA 2501 – Store content of accumulator to location 2501
  7. HLT – Terminates the program


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter