Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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.
  6. If even, jump to step 9.
  7. Get the number in accumulator and store in the memory location pointed by DE.
  8. Increment DE.
  9. Increment HL. Decrement C.
  10. 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


Last Updated : 28 May, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads