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

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the **CS Theory Course** at a student-friendly price and become industry ready.