Open In App

8085 program to count total even numbers in series of 10 numbers

Last Updated : 30 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Program – Write an assembly language program in 8085 microprocessor to count even numbers in a series of 10 numbers. 

Example –

  

Assumption – Ten 8-bit numbers are stored from starting memory location 2050. Value of count is stored at memory location 3050. 

Algorithm –

  1. Initialize register H with 20 and register L with 4F so that indirect memory points to memory location 204F.
  2. Initialize register C with 00 and register D with 0A.
  3. Increment indirect memory by 1.
  4. Store value of M in accumulator A.
  5. Check whether the content in A is even or odd by performing AND operation of A with 01.
  6. If content of A is 00 after AND operation then the number scanned was even, If so then increment C by 01 else if content of A is 01 after AND operation then number scanned was odd, If so then decrements D by 01.
  7. Check if zero flag is not set i.e. ZF = 0 then jump to step 3 otherwise store value of C at memory location 3050.

Program (Using ANI Instruction) –

MEMORY ADDRESS MNEMONICS COMMENT
2000 LXI H 204F H <- 20, L <- 4F
2003 MVI C, 00 C <- 00
2005 MVI D, 0A D <- 0A
2007 INX H M <- M + 01
2008 MOV A, M A <- M
2009 ANI 01 A <- A (AND) 01
200B JNZ 200F Jump if ZF = 0
200E INR C C <- C + 01
200F DCR D D <- D – 01
2010 JNZ 2007 Jump if ZF = 0
2013 MOV A, C A <- C
2014 STA 3050 M[3050] <- A
2017 HLT END

Explanation – Registers A, B, C, D, H, L are used for general purpose.

  1. LXI H 204F: assign 20 to H and 4F to L.
  2. MVI C, 00: assign 00 to C.
  3. MVI D, 0A: assign 0A to D.
  4. INX H: increment indirect memory location M by 01.
  5. MOV A, M: move content of M to A.
  6. ANI 01: perform AND operation of A with 01 and store the result in A.
  7. JNZ 200F: jump if ZF = 0 to memory location 200F.
  8. INR C: increment C by 01.
  9. DCR D: decrements D by 01.
  10. JNZ 2007: jump if ZF = 0 to memory location 2007.
  11. MOV A, C: moves the content of C to A.
  12. STA 3050: store the content of A to memory location 3050.
  13. HLT: stops executing the program and halts any further execution.

Alternative Approach (Using Rotate Instructions):

For a given set of numbers, If the Least Significant Bit(LSB) of each number’s Binary representation is 1, then the given number is assured to be an Odd Number.

But if the Least Significant Bit (LSB) of each number’s binary representation is 0, then the given number is assured to be an Even Number.

Hence, here we will use Rotate Instructions of 8085 Microprocessor. i.e. RAR Instruction (Rotate Accumulator Right involving Carry flag in Rotation).

If we rotate the given binary number in the right direction by 1-bit then we will get the carry a flag as Zero or One.

If we get Carry Flag = 1, then the given number is ODD, Otherwise EVEN.

MEMORY ADDRESS

Symbols

COMMENT
2000 LXI H,204FH Load HL Pair with Previous location of 2050H , H <- 20, L <- 4F
2003 MVI C,00H For storing count of Even Numbers [C]=0H
2005 MVI D,0AH For series of 10 numbers we have stored array size as [D]=10
2007 INX H Increment memory pointer pointed by HL pair
2008 MOV A,M Move Content of memory location 2050H into Accumulator A. {[A] <- [M]}
2009 RAR Rotate Accumulator Right with Carry .
200B JC 200F After rotating if Carry Flag=1 then we can say that given number is ODD, So we just need to move to next element nothing to do extra here.
200E INR C if we found that Carry Flag=0 then we can say that given Number is EVEN, So we need to increment our count by 1.Hence INR C will happen for all subsequent conditions.
200F DCR D Now if we have found out whether given number is ODD/EVEN then we need to decrement array size because here size is 10 and we need to decrement till 0.
2010 JNZ 2007 Until [D]=0 we have to decrement D and move to next memory location and take input of 10 numbers (This is looping Structure.)
2013 MOV A,C (After whole looping is over)Transfer/Copy Contents of register C which contains total number of even numbers into Accumulator.
2014 STA 3050H Store Accumulator Content which contains count of Even Numbers to Memory Location 3050H as required in Question
2017 HLT End of a Program Execution 

Previous Article
Next Article

Similar Reads

8085 program to count total odd numbers in series of 10 numbers
Program - Write an assembly language program in 8085 microprocessor to count odd numbers in series of 10 numbers. Example - Assumption - Ten 8-bit numbers are stored from starting memory location 2050. Value of count is stored at memory location 3050. Algorithm - Initialize register H with 20 and register L with 4F so that indirect memory points to
3 min read
8085 program to count number of elements which are less than 0A
Problem - Write an assembly language program in 8085 microprocessor to count number of elements which are less than 0A in series of 10 numbers. Example - Assumption - Series of 10 numbers is stored from starting memory location 2050. Value of count is stored at memory location 3050 Algorithm - Initialize register H with 20 and register L with 4F so
3 min read
8085 program to show masking of lower and higher nibbles of 8 bit number
Problem - Write an assembly language program in 8085 microprocessor to show masking of lower and higher nibble of 8 bit number. Example - Assumption - 8 bit number is stored at memory location 2050. After masking of nibbles, lower order nibble is stored at memory location 3050 and higher order nibble is stored at memory location 3051. Algorithm - L
3 min read
8085 program to exchange content of HL register pair with DE register pair
Problem - Write an assembly language program in 8085 microprocessor to exchange content of HL register pair with DE register pair using PUSH and POP instructions. Example - Assumption - Content is already present in HL and DE register. Algorithm - Initialize stack pointer (SP) by 3FFF.Push the content of H and L register into the stack. Decrements
2 min read
8085 program for pulse waveform
Problem - Write a program to generate continuous square wave. Use D0 bit to output the square wave. The required waveform is: Explanation - The alternate pattern of 0/1 bits can be provided by loading the accumulator with AAH(10101010) and rotating the pattern once through each loop. Bit D0 of the output port is used to proved logic 0 and 1. Theref
2 min read
8085 program to perform AND operation in nibbles of 8 bit number
Problem - Write an assembly language program in 8085 microprocessor to perform AND operation between lower and higher order nibble of 8 bit number. Example - Assumption - 8 bit number is stored at memory location 2050. Final result is stored at memory location 3050. Algorithm - Load the content of memory location 2050 in A. Perform masking of nibbl
2 min read
8085 program to check whether both the nibbles of 8 bit number are equal or not
Problem - Write an assembly language program in 8085 microprocessor to check whether both the nibbles of 8 bit number are equal or not. If nibbles are equal then store 00 in memory location 3050 otherwise store FF in memory location 3050. Example - Assumption - Number, to check for similar nibbles is stored at memory location 2050. Algorithm - Load
3 min read
8085 program for hexadecimal counter
Write a program to count continuously in hexadecimal from FFH to 00H in a system with clock frequency 0.5 microseconds. Use register C to set up a delay of 1ms between each count and display output at one of the output ports. Problem Analysis: The hexadecimal counter is set by loading a register with starting number and decrementing it till zero is
2 min read
Total count of sorted numbers upto N digits in range [L, R] (Magnificent necklace combinatorics problem)
Given three integers N, L, and R, the task is to print the total count of ways to form a necklace of at most N pearls such that the values of a pearl lie in the range [L, R] and are in ascending order. Examples: Input: N = 3, L = 6, R = 9Output: 34Explanation:The necklace can be formed in the following ways: The necklaces of length one that can be
8 min read
Count of total anagram substrings
Given a string of lower alphabet characters, count total substring of this string which are anagram to each other. Examples: Input : str = “xyyx”Output : 4Total substrings of this string whichare anagram to each other are 4 which can be enumerated as,{“x”, “x”}, {"y", "y"}, {“xy”, “yx”}, {“xyy”, “yyx”}Input : str = "geeg"Output : 4The idea is to cr
4 min read
Article Tags :
Practice Tags :