Open In App

8085 program to check whether the given number is even or odd

Improve
Improve
Like Article
Like
Save
Share
Report

Problem – Write an assembly language program in 8085 microprocessor to check whether the 8 bit number which is stored at memory location 2050 is even or odd. If even, store 22 at memory location 3050 otherwise store 11 at memory location 3050. Example – A number is said to be odd if its lower bit is 1 otherwise even. Therefore to identify whether the number is even or odd, we perform AND operation with 01 by the help of ANI instruction. If number is odd then we will get 01 otherwise 00 in accumulator. ANI instruction also affect the flags of 8085. Therefore if accumulator contains 00 then zero flag becomes set otherwise reset. Algorithm –

  1. Load the content of memory location 2050 in accumulator A.
  2. Perform AND operation with 01 in value of accumulator A by the help of ANI instruction.
  3. Check if zero flag is set, i.e if ZF = 1 then store 22 in accumulator A otherwise store 11 in A.
  4. Store the value of A in memory location 3050

Program –

MEMORY ADDRESS MNEMONICS COMMENT
2000 LDA 2050 A <- M[2050]
2003 ANI 01 A <- A (AND) 01
2005 JZ 200D Jump if ZF = 1
2008 MVI A 11 A <- 11
200A JMP 200F Jump to memory location
200D MVI A 22 A <- 22
200F STA 3050 M[3050] <- A
2012 HLT END

Explanation – Registers used A:

  1. LDA 2050 –loads the content of memory location 2050 in accumulator A
  2. ANI 01 –performs AND operation between accumulator A and 01 and store the result in A
  3. JZ 200D –jump to memory location 200D if ZF = 1
  4. MVI A 11 –assign 11 to accumulator
  5. JMP 200F –jump to memory location 200F
  6. MVI A 22 –assign 22 to accumulator
  7. STA 3050 –stores value of A in 3050
  8. HLT –stops executing the program and halts any further execution

Advantages:

  1. Simple and easy to understand logic
     
  2. Uses only a few instructions, making it efficient in terms of memory usage and execution time
    Can be easily modified to check for other properties of numbers, such as divisibility by certain numbers
     

Disadvantages:

  1. Only works for 8-bit numbers
     
  2. Requires an additional branch instruction (JZ) to check whether the number is even or odd, which can add overhead to the program
     

Last Updated : 25 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads