PIPPIN Project 4

This program coputes for a given number limit the sum of arithmetic progression 1+2+...+limit

; initialize INDEX (cell 100) to 1
[0]   LOD #1        ;set ACC to 1
[2]   STO 100       ;and load that into cell INDEX

; initialize running SUM (cell 101) to 0
[4]   LOD #0        ;set ACC to 0
[6]   STO 101       ;and load that into cell SUM

; start of loop. If INDEX < LIMIT (cell 102), jump out of loop
[8]   LOD 100       ;load INDEX into ACC
[10]  SUB 102       ;ACC now contains INDEX-LIMIT
[12]  SUB #1        ;ACC = INDEX-LIMIT-1
[14]  JMZ #28       ;if ACC=0 (i.e. INDEX=LIMIT+1) then exit 

; add INDEX to SUM
[16]  LOD 101       ;load SUM into ACC
[18]  ADD 100       ;ACC=SUM+INDEX
[20]  STO 101       ;store this back into SUM

; increase INDEX by 1
[22]  LOD #1        ;ACC=1
[24]  ADD 100       ;increment INDEX
[26]  JMP #8        ;jump to start of loop in line 5
[28]  HLT           ;out of the loop from JMZ step, done
....
....
[100] ; INDEX
[101] ; SUM
[102] ; LIMIT