* Stack Example, by Randy Ding. Shows how to access the stack in ML.
* Input: three bints (#a #b #c)
* Output: #a #b #c (#a+#b+#c) 2*(#a+#b+#c) "Ta Da!, Success!"
::
CK3NOLASTWD
ROT DUPTYPEBINT? NOT?SEMI
ROT DUPTYPEBINT? NOT?SEMI
ROT DUPTYPEBINT? NOT?SEMI
CODE
GOSBVL =SAVPTR at this point, D1 --> first pointer on rpl stack
C=0 A for result, sum of bints will be stored in C(A)
GOSUB ADDSUB
D1=D1+ 5 make D1 --> second pointer on rpl stack (level 2)
GOSUB ADDSUB
D1=D1+ 5 make D1 --> third pointer on rpl stack (level 3)
GOSUB ADDSUB
R0=C.F A copy result in C(A) to R0(A), PUSH# wants it there
GOSBVL =PUSH# does GETPTR, pushes R0(A) as #
GOSBVL =SAVPTR must SAVEPTR after doing each PUSH#
C=R0.F A since PUSH# uses C, get copy of it from R0
C=C+C A mult it by 2
R0=C.F A
GOSBVL =PUSH# now push result*2 to stack
GOSBVL =SAVPTR
GOVLNG =GETPTRLOOP go back to rpl, continues after ENDCODE below
ADDSUB A=DAT1 A get pointer to object on stack, D1 is -->-->bint
D0=A put that pointer in D0, D0 now -->bint prolog
D0=D0+ 5 skip the bint 5 nib prolog, D0 -->bint value
A=DAT0 A read the value, pointed to by D0
C=C+A A add this value to the result in C(A)
RTN
ENDCODE
$ "Ta Da!, Success!"
;