Write an Assembly Language Program for Intel 8085 microprocessor to calculate the sum of N natural numbers, that is, ΣN = 1+2+3+ … +(N-1)+N.
Fulfil as many constraints as you can:
My Code is :
START: LDA 3000H
MOV B, A
INR A
MOV C, A
MVI A, 00H
LOOP1: ADD B
DCR C
JNZ LOOP1
MVI C, 02H
MVI B, 00H
LOOP2: INR B
SUB C
JNZ LOOP2
MOV A,B
STA 3001H
HLT
I have tried and made the program but with using all these constraints, while the question asks not to use them. So my doubt is whether it is possible to make a program without using these.
I think the following code satisfies all conditions :
START:LDA 3000H
MVI B, 00H
MVI C, 00H
MVI L, 01H
LOOP:MOV H, A
MOV A, C
ADD L
MOV C, A
MOV A, B
ADD C
MOV B, A
MOV A, H
SUB L
JNZ LOOP
MOV A, B
HLT
It doesn't uses guass formula instead add one by one and instead of using increment decrement instructions, it uses add and sub instructions. The result is stored in the accumulator register.