- Related Questions & Answers
- Find the element that appears once in sorted array - JavaScript
- Find the element that appears once in an array where every other element appears twice in C++
- Program to find which element occurs exactly once in Python
- Finding two missing numbers that appears only once and twice respectively in JavaScript
- Take an array and find the one element that appears an odd number of times in JavaScript
- 8085 Program to find the smallest number
- 8085 program to count number of once in the given 8-bit number
- Return the element that appears for second most number of times in the array JavaScript
- Create a tooltip that appears when the user moves the mouse over an element with CSS
- 8085 program to find the sum of a series
- 8085 program to find the factorial of a number
- 8085 program to find the set bit of accumulator
- Maximum difference between two elements such that larger element appears after the smaller number in C
- Count Derangements (Permutation such that no element appears in its original position) in C++
- How to find the one integer that appears an odd number of times in a JavaScript array?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this program we will see how to find a number who appears only once in an array of elements.

Write 8085 Assembly language program to find a number who appears only once in an array of elements. The size of the array is stored at location F100; the numbers are stored from memory location F101 onwards. The result will be stored at F150.

The logic behind this problem is simple. Though it may find some wrong results in some cases. It can find the number if there is only one number which is appeared once, and rest of the numbers are appeared even number of times.

We are doing the XOR operation on the numbers. If one number is already present, and we XOR it with the same number it will be 0. So if the same numbers appeared even number of times we can get 0. After cumulative XOR operations, the final number will be that number whose frequency is one.

Address | Data |
---|---|

| . . . |

F100 | 05 |

F101 | 0C |

F102 | 0A |

F103 | 01 |

F104 | 01 |

F105 | 0C |

| . . . |

Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|

F000 | 21, 00, F1 | | LXI H,F100 | Point to get count of numbers |

F003 | AF | | XRA A | Clear accumulator |

F004 | 4E | | MOV C,M | Load count from memory to C |

F005 | 23 | | INX H | Point to next location |

F006 | 46 | LOOP | MOV B,M | Load memory to B |

F007 | A8 | | XRA B | XOR B with Accumulator |

F008 | 23 | | INX H | Point to next location |

F009 | 0D | | DCR C | Decrease C by 1 |

F00A | C2, 06, F0 | | JNZ LOOP | Jump to LOOP until Z = 1 |

F00D | 32, 50, F1 | | STA F150 | Store number at F150 |

F010 | 76 | | HLT | Terminate the program |

Address | Data |
---|---|

| . . . |

F150 | 0A |

| . . . |

Advertisements