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 –

Load accumulator with the content of any one location (either 2500 or 2501 or any given location).

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.

Store the content of accumulator to another location (data of 2501 to 2500).

Load accumulator with content of register and then store it to another address location.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.