Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program to find the sum of all positive number stored in the memory: ADD

ID: 3940956 • Letter: W

Question

write a program to find the sum of all positive number stored in the memory:

ADDRESS                                  MEMORY

200                                             DEC 10

201                                             DEC -9

202                                             DEC 2

203                                             DEC 0

204                                             DEC 12

205                                             DEC -5

206                                             DEC 25

207                                             DEC 90

208                                             DEC 0

Explanation / Answer

Note: Answering the program based on 8085 micro processor since no specific assembly language was mentioned.

MVI B, 09H :"Initialize counter"   
LXI H, 200H :"Initialize memory pointer"
MVI A, 0H :"Initialize sum count"
MVI D, 210H :"Location to store the output value"
BACK: SHR M, 01 :"Shift and rotate the number in memory by 1 position"
JNC POS :"If there is no change after shift and rotate, then it's a positive number'
INX H :"Increment memory pointer"
DCR B :"Decrement the counter"
JNZ BACK :"if Non-Zero go back"
JMP END :"If counter has reached 0, then input buffer is empty"
POS:ADDA M :"Add positive number to the accumulator"
INX H :"Increment memory pointer"
DCR B :"Decrement the counter"
JNZ BACK :"if Non-Zero go back"
END:
STA D
"Sum of the positive numbers is available in the memory location 210H"