Featured

    Featured Posts

Write a program to calculate the sum of the series of even numbers.


Write a program to calculate the sum of the series of even numbers.

Program statement :- Write a program in the ALP of 8085 to calculate the sum of series of even numbers. Assume that the length of the series is stored at memory location D000 H and the series itself begins at memory D001 H. Store the result at memory location E000 H. Draw flowchart.

   Explanation :-
  1. Initialize the sum to zero. Load the count of numbers in register C. Iniialize pointer to start of series.
  2. To check whether the number is even we will AND the number with 01 H. If the result of ANDing is zero it indicates that the number is even. We will add this even number to the initialised sum.
  3. Decrement counter Increment source pointer to next location. Continue the process till sum of all even numbers is found. Store the sum at memory location E000 H.
Program :
Lable
Instruction
Comment

LDA D000H
MOV C,A
MVI B, 00 H
LXI H, D001 H

Initialize counter
sum = 0
Initialize pointer
Back :
MOV A,M
ANI 01 H
JNZ SKIP
MOV A,B
ADD M
MOV B,A
Get the number
Mask Bit 1 to Bit 7
Don’t add if number is Odd
Get sum
SUM = Sum + data
Store result in B register
SKIP:
INX H
DCR C
JNZ BACK
STA E000H
HLT
Increment pointer
Decrement counter
If counter =/ 0 repeat
Store sum (Result)
Terminate program execution


1 comments:

Needed to compose one little word yet thanks for the suggestions that you are contributed here, really very much impressed with this blog please do keep on sharing...
Best Online Software Training Institute | Data Science Training

Reply

Post a Comment

www.CodeNirvana.in

www.posthatke.com. Powered by Blogger.

Google+ Followers

Copyright © www.posthatke.com | Blogger Templates | Designed By posthatke.com