## Sunday, March 20, 2016

### PrgCalcPro: Summation

PrgCalcPro: Summation

Summation

This program uses a loop to determine Σ f(X) from a to b.   The function f(X) starts on Line 22.  Use Memory Register a as X and finish the function with RET.   The sum is stored in Memory 0.

The listing here uses f(X) = X^2 + 1.

To run: enter a, press [ E up-arrow ], b, [RET], [RUN]

0: 4B  ;  MB
1: 14  ;  XY // X<>Y
2: 4A  ;  MA
3: 00  ;  0 // clear memory 0
4: 40  ;  M0
5: 53  ;  SUB // determine f(X), loop starts here
6: 22
7: 60  ;  R0
8: 10  ;  +
9: 40  ;  M0
10: 6A  ;  RA // add 1 to a, prepare for next loop
11: 01  ;  1
12: 10  ;  +
13: 4A  ;  MA
14: 6B  ;  RB
15: 11  ;  -
16: 01  ;  1
17: 11  ;  -
18: 59  ;  X>=0 // is a - (b+1) ≥ 0?
19: 05 // if not repeat the loop
20: 60  ;  R0
21: 50  ;  STOP // terminate
22: 6A  ;  RA // this is where f(X) starts
23: 22  ;  X^2
24: 01  ;  1
25: 10  ;  +
26: 52  ;  RET // don't forget to include RET at the end

Example:

Σ x^2 + 1 from x=0 to x=5.   Result: 61.

This blog is property of Edward Shore,   2016.