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.
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.
- Load the content of memory location 2050 in accumulator A.
- Perform AND operation with 01 in value of accumulator A by the help of ANI instruction.
- Check if zero flag is set, i.e if ZF = 1 then store 22 in accumulator A otherwise store 11 in A.
- Store the value of A in memory location 3050
|2000||LDA 2050||A <- M|
|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 <- A|
Explanation – Registers used A:
- LDA 2050 –loads the content of memory location 2050 in accumulator A
- ANI 01 –performs AND operation between accumulator A and 01 and store the result in A
- JZ 200D –jump to memory location 200D if ZF = 1
- MVI A 11 –assign 11 to accumulator
- JMP 200F –jump to memory location 200F
- MVI A 22 –assign 22 to accumulator
- STA 3050 –stores value of A in 3050
- HLT –stops executing the program and halts any further execution
- 8085 program to check whether the given 16 bit number is palindrome or not
- 8085 program to check whether both the nibbles of 8 bit number are equal or not
- 8085 program to reverse 8 bit number
- 8085 program to reverse 16 bit number
- 8085 program to convert an 8 bit number into Grey number
- 8085 program to convert an 8 bit BCD number into hexadecimal number
- 8085 program to find the factorial of a number
- 8085 program to find sum of digits of 8 bit number
- 8085 program to count number of elements which are less than 0A
- 8085 program to determine if the number is prime or not
- 8085 program to find 1’s and 2’s complement of 16-bit number
- 8085 program to convert a BCD number to binary
- 8085 program to find square of a 8 bit number
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to find nth power of a number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.