Skip to main content

Calculate the sum of series of even numbers

Calculate the sum of series of even numbers

  1. LDA 2500H  
  2. MOV C, A            : "Initialize counter"  
  3. MVI B, 00H          : "sum = 0"  
  4. LXI H, 2501H        : "Initialize pointer"  
  5. BACK: MOV A, M      : "Get the number"  
  6. ANI 01H             : "Mask Bit l to Bit7"  
  7. JNZ SKIP            : "Don't add if number is ODD"  
  8. MOV A, B            : "Get the sum"  
  9. ADD M               : "SUM = SUM + data"  
  10. MOV B, A            : "Store result in B register"  
  11. SKIP: INX H         : "increment pointer"  
  12. DCR C               : "Decrement counter"  
  13. JNZ BACK            : "if counter 0 repeat"  
  14. STA 2505H           : "store sum"  
  15. HLT                 : "Stop" 

Comments