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.

a. Sample problem

4200H = 04H

4201H = 10H

4202H = 45H

4203H = 33H

4204H = 22H

Result = 10 +41 + 30 + 12 = H

4300H = H

Source program:

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

b. Sample problem

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:

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

It will give only sum of 8bit no's....

ReplyDeleteBut will it work for more than two 16bit no???????????

No .. U hv to use another

Deletewith carry :p

ReplyDeletecarry ----> D

MVI D 00h

LDA 8500h

MOV C A

SUB A

LXI H 8501h

L: ADD M

JNC L1

INR D

L1: INX H

DCR C

JNZ L

MOV M A

INX H

MOV M D

HLT

4200H = 04H

ReplyDeleteWHY WE ARE STORING 04H AT THIS ADRESS?

It is count of numbers given

Delete