Skip to main content

Calculate the sum of series of odd numbers

Calculate the sum of series of odd numbers

  1. LDA 2500H  
  2. MOV C, A            : "Initialize counter"  
  3. LXI H, 2501H        : "Initialize pointer"  
  4. MVI E, 00           : "Sum low = 0"  
  5. MOV D, E            : "Sum high = 0"  
  6. BACK: MOV A, M      : "Get the number"  
  7. ANI 01H             : "Mask Bit 1 to Bit-7"  
  8. JZ SKIP             : "Don't add if number is even"  
  9. MOV A, E            : "Get the lower byte of sum"  
  10. ADD M               : "Sum = sum + data"  
  11. MOV E, A            : "Store result in E register"  
  12. JNC SKIP  
  13. INR D               : "Add carry to MSB of SUM"  
  14. SKIP: INX H         : "Increment pointer"  

Comments