Skip to content
Related Articles

Related Articles

8085 program to find the sum of a series
  • Last Updated : 15 May, 2018
GeeksforGeeks - Summer Carnival Banner

Problem – Write a program to find the sum of a series where series starts from 3001 memory address and count of series is at 3000 memory address where starting address of the given program is 2000 store result into 4000 memory address.

Example –

Algorithm –

  1. Move 00 to register B immediately for carry
  2. Load the data of memory [3000] into H immediately
  3. Move value of memory into register C
  4. Decrease C by 1
  5. Increase H-L pair by 1
  6. Move value of memory into accumulator
  7. Increase H-L pair by 1
  8. Add value of memory with accumulator
  9. Jump if no carry to step 11
  10. Increase value of register B by one
  11. Decrease register C by 1
  12. Jump if not zero to step-7
  13. Store content of accumulator into memory [4000] (result)
  14. Move content of register B into accumulator
  15. Store content of accumulator into memory [4001] (carry)
  16. Stop

Program –

MemoryMnemonicsOperandsComment
2000MVIB, 00[B] <- 00
2002LXIH, [3000][H-L] <- [3000]
2005MOVC, M[C] <- [M]
2006DCRC[C] <- [C] – 1
2007INXH[H-L] <- [H-L] + 1
2008MOVA, M[A] <- [M]
2009INXH[H-L] <- [H-L] + 1
200AADDM[A] <- [A] + [M]
200BJNC200Fjump if no carry
200EINRB[B] <- [B] + 1
200FDCRC[C] <- [C] – 1
2010JNZ2009jump if not zero
2013STA[4000]result
2016MOVA, B[A] <- [B]
2017STA[4001]carry
201AHLTStop

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

  1. MVI is used to load an 8-bit given register immediately (2 Byte instruction)
  2. LXI is used to load register pair immediately using 16-bit address (3 Byte instruction)
  3. MOV is used to transfer the data from accumulator to register(any) or register(any) to accumulator (1 Byte)
  4. RAR is used to shift ‘A’ right with carry (1 Byte instruction)
  5. STA is used to store data from accumulator into memory direct using 16-bit address (3 Byte instruction)
  6. INR is used to increase given register by 1 (1 Byte instruction)
  7. JNC is used to jump to the given step if their is no carry (3 Byte instruction)
  8. JNZ is used to jump to the given step if their is not zero (3 Byte instruction)
  9. DCR is used to decrease given register by 1 (1 Byte instruction)
  10. INX is used to increase register pair by 1 (1 Byte instruction)
  11. ADD is used to add value of accumulator with the given value (1 Byte instruction)
  12. HLT is used to halt the program

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 :