Skip to content
Related Articles

Related Articles

8085 program to count number of elements which are less than 0A
  • Last Updated : 20 Jun, 2018

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 –

  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 01.
  4. Move the content of M in accumulator A.
  5. Compare the content of A with 0A by help of CPI instruction. This instruction will update flags of 8085.
  6. Check if carry flag is set, if true then increment content of C by 01.
  7. Decremented content of D by 01.
  8. Check if zero flag is reset, if true then jump to step 3.
  9. Move the content of C to A.
  10. Store the content of A to memory location 3050.

Program –

2000LXI H 204FH <- 20, L <- 4F
2003MVI C, 00C <- 00
2005MVI D, 0AD <- 0A
2007INX HM <- M + 01
2008MOV A, MA <- M
2009CPI 0AA – 0A
200BJNC 200FJump if CY = 0
200EINR CC <- C + 01
200FDCR DD <- D – 01
2010JNZ 2007Jump if ZF = 0
2013MOV A, CA <- C
2014STA 3050M[3050] <- A

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

  1. LXI H 204F: assign 20 to register H and 4F to register L
  2. MVI C, 00: assign 00 to register C
  3. MVI D, 0A: assign 0A to register D
  4. INX H: increment indirect memory location by 01
  5. MOV A, M: moves the content of indirect memory location M to accumulator A
  6. CPI 0A: subtracts 0A from content of A and update the flags of 8085
  7. JNC 200F: jump to memory location 200F if CY = 0
  8. INR C: increment content of C by 01
  9. DCR D: decrement content of D by 01
  10. JNZ 2007: jump to memory location 2007 if ZF = 0
  11. MOV A, C: moves the content of C to A
  12. STA 3050: store the content of A in memory location 3050
  13. HLT: stops executing the program and halts any further execution

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :