In: Computer Science
: Please write a MARIE program to calculate 1+2+3+...+100.
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
LDA 301BH
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 301CH
HLT
Explanation:
Algorithm:
Taking N as the input, increment it to obtain N+1.
Multiply N with N+1.
Divide the obtained product obtained by 2.
Steps:
Load the data from the memory location (301BH, random choice)
into the accumulator
Move the data into B
Increment the value in the accumulator by one and move it to the
register C
Initialize the accumulator with 0
Multiplication step: Keep adding B to accumulator. The B has to be
added equal number of times as the value of C
Initialize B with 00H. B will store the quotient of the
division
Initialize C with 02H. This is the divisor for the division
Division step: Keep subtracting C from A till A becomes 0. For each
subtraction, increment B by one
The final answer is in B. Move it to A. Then store the value of A
in 301CH (again random choice)
Kindly revert for any queries
Thanks.