Calculate the sum of series of odd numbers
- LDA 2500H
- MOV C, A : "Initialize counter"
- LXI H, 2501H : "Initialize pointer"
- MVI E, 00 : "Sum low = 0"
- MOV D, E : "Sum high = 0"
- BACK: MOV A, M : "Get the number"
- ANI 01H : "Mask Bit 1 to Bit-7"
- JZ SKIP : "Don't add if number is even"
- MOV A, E : "Get the lower byte of sum"
- ADD M : "Sum = sum + data"
- MOV E, A : "Store result in E register"
- JNC SKIP
- INR D : "Add carry to MSB of SUM"
- SKIP: INX H : "Increment pointer"
Comments
Post a Comment