Sum of Natural Numbers 1+2+3+........+9 for the Basic Computer

/1+2+3+......+9

REP, LDA SUM
ADD TRM
STA SUM
LDA TRM
INC
STA TRM
ISZ CTR
BUN REP
HLT
TRM, DEC 1
SUM, DEC 0
CTR, DEC -9
END

In C Programming,
int s=0;
for(int t=1;t<=9;t++)
    s=s+t;

Like in this, we have to load the sum (s) first, add it with first term (t) and store in the sum (s). Then, we have to update the term (t) and add it again until the counter hits zero (0). The term itself is counter here

No comments:

Post a Comment