Statement: Calculate the sum of series of numbers. The length of the series is in memory location 4200H and the series begins from memory location 4201H.
a. Consider the sum to be 8 bit number. So, ignore carries. Store the sum at memory location 4300H.
b. Consider the sum to be 16 bit number. Store the sum at memory locations 4300H and 4301H.
|
Sample problem 1:
4200H = 04H
4201H = 10H
4202H = 45H
4203H = 33H
4204H = 22H
Result = 10 +41 + 30 + 12 = H
4300H = H
|
Source program 1:
LDA 4200H
MOV C, A : Initialize counter
SUB A : sum = 0
LXI H, 420lH : Initialize pointer
BACK: ADD M : SUM = SUM + data
INX H : increment pointer
DCR C : Decrement counter
JNZ BACK : if counter 0 repeat
STA 4300H : Store sum
HLT : Terminate program execution
|
Flowchart for Source program1

|
Sample problem 2:
4200H = 04H
420lH = 9AH
4202H = 52H
4203H = 89H
4204H = 3EH
Result = 9AH + 52H + 89H + 3EH = H
4300H = B3H Lower byte
4301H = 0lH Higher byte
|
Source program 2
LDA 4200H
MOV C, A : Initialize counter
LXI H, 4201H : Initialize pointer
SUB A :Sum low = 0
MOV B, A : Sum high = 0
BACK: ADD M : Sum = sum + data
JNC SKIP
INR B : Add carry to MSB of SUM
SKIP: INX H : Increment pointer
DCR C : Decrement counter
JNZ BACK : Check if counter 0 repeat
STA 4300H : Store lower byte
MOV A, B
STA 4301H : Store higher byte
HLT :Terminate program execution
|
|
Related Programs for Beginners: (Click down)
Store 8-bit data in memory
Add two 16-bit numbers
Finding Two's complement of a number
Exchange the contents of memory locations
Pack-the-unpacked-BCD-numbers