GeeksforGeeks App
Open App
Browser
Continue

# 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:

1. Load the memory location 2000 in HL register pair.
2. Load the memory location 2100 in DE register pair for storing odd numbers.
3. Store the number of elements in register C.
4. Move the next number in the list to accumulator.
5. Perform AND operation with 01H to check whether the number is even or odd.
7. Get the number in accumulator and store in the memory location pointed by DE.
8. Increment DE.
9. Increment HL. Decrement C.

Perform similarly above steps for storing even numbers.

Program:

2000HLXI H, 2000HInitialize memory pointer 1
2003HLXI D, 2100HInitialize memory pointer 2
2006HMVI C, 32HInitialize counter
2008HMOV A, MGet the number
2009HANI 0lHCheck for odd number
200BHJZ 2011HIf EVEN, don’t store
200EHMOV A, MGet the number
200FHSTAX DStore the number in result list
2010HINX DIncrement pointer 2
2011HINX HIncrement pointer l
2012HDCR CDecrement counter
2013HJNZ 2008HIf not zero, repeat
2016HLXI H, 2000HInitialize memory pointer l
2019HLXI D, 2200HInitialize memory pointer2
201CHMVI C, 32HInitialize counter
201EHMOV A, MGet the number
201FHANI 0lHCheck for even number
2021HJNZ 2027HIf ODD, don’t store
2024HMOV A, MGet the number
2025HSTAX DStore the number in result list
2026HINX DIncrement pointer 2
2027HINX HIncrement pointer l
2028HDCR CDecrement counter
2029HJNZ 201EHIf not zero, repeat
202CHHLTStop

My Personal Notes arrow_drop_up