# 8085 program to separate odd and even nos from a given list of numbers

**Problem:** Write an assembly language program in 8085 microprocessor to separate odd and even numbers from the given list of 50 numbers. Store odd nos in another list starting from memory location 2100H. Store even nos in another list starting from memory location 2200H. Starting address of the list is 2000H.

**Examples:**

**Explanation:**

A number is said to be odd if its least significant bit is 1 otherwise it is even. Therefore to identify whether the number is even or odd, we perform AND operation with 01 by the help of ANI instruction. If the number is odd then we will get 01 otherwise 00 in the accumulator. ANI instruction also affects the flags of 8085. Therefore if accumulator contains 00 then zero flag gets set otherwise it gets reset.

**Algorithm:**

- Load the memory location 2000 in HL register pair.
- Load the memory location 2100 in DE register pair for storing odd numbers.
- Store the number of elements in register C.
- Move the next number in the list to accumulator.
- Perform AND operation with 01H to check whether the number is even or odd.
- If even, jump to step 9.
- Get the number in accumulator and store in the memory location pointed by DE.
- Increment DE.
- Increment HL. Decrement C.
- If C is not zero, jump to step 4.

Perform similarly above steps for storing even numbers.

**Program:**

Memory Location | Mneumonics | Comments |
---|---|---|

2000H | LXI H, 2000H | Initialize memory pointer 1 |

2003H | LXI D, 2100H | Initialize memory pointer 2 |

2006H | MVI C, 32H | Initialize counter |

2008H | MOV A, M | Get the number |

2009H | ANI 0lH | Check for odd number |

200BH | JZ 2011H | If EVEN, don’t store |

200EH | MOV A, M | Get the number |

200FH | STAX D | Store the number in result list |

2010H | INX D | Increment pointer 2 |

2011H | INX H | Increment pointer l |

2012H | DCR C | Decrement counter |

2013H | JNZ 2008H | If not zero, repeat |

2016H | LXI H, 2000H | Initialize memory pointer l |

2019H | LXI D, 2200H | Initialize memory pointer2 |

201CH | MVI C, 32H | Initialize counter |

201EH | MOV A, M | Get the number |

201FH | ANI 0lH | Check for even number |

2021H | JNZ 2027H | If ODD, don’t store |

2024H | MOV A, M | Get the number |

2025H | STAX D | Store the number in result list |

2026H | INX D | Increment pointer 2 |

2027H | INX H | Increment pointer l |

2028H | DCR C | Decrement counter |

2029H | JNZ 201EH | If not zero, repeat |

202CH | HLT | Stop |

## Recommended Posts:

- 8085 program to separate (or split) a byte into two nibbles
- 8085 program to count total odd numbers in series of 10 numbers
- 8085 program to count total even numbers in series of 10 numbers
- 8085 program to add two 8 bit numbers
- 8085 program to add 2-BCD numbers
- 8085 program to add two 16 bit numbers
- 8085 program to sum of two 8 bit numbers without carry
- 8085 program to swap two 8-bit numbers
- 8085 program to multiply two 16-bit numbers
- 8085 program to divide two 16 bit numbers
- 8085 program to multiply two 8 bit numbers
- 8085 program to add numbers in an array
- 8085 program to divide two 8 bit numbers
- 8085 program to find the sum of series of even numbers
- 8085 program to subtract two 16-bit numbers with or without borrow

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.