BasicForthOps

See RetroChallenge201610.

Variable key:

ST$[] = stack
SP = stack pointer
V$ = value obtained from stack
V = numeric value obtained from V$
RH = right-hand value in operation
LH = left-hand value in operation
RT = result

21000 REM push
21010 SP = SP + 1
21020 ST$[SP] = V$
21030 RETURN

22000 REM pop
22010 V$ = ST$[SP]
22020 SP = SP - 1
22030 RETURN

30400 REM emit
30410 V$ = ST$[SP]
30420 V = VAL(V$)
30430 PRINT CHR$(V)
30440 RETURN

30500 REM .
30510 GOSUB 22000
30520 PRINT V$
30530 RETURN

30700 REM dup
30710 V$ = ST$[SP]
30720 SP = SP + 1
30730 ST$[SP] = V$
30740 SP = SP + 1
30750 ST$[SP} = V$
30760 RETURN

30800 REM CR
30810 PRINT CHR$(13)
30820 RETURN

30900 REM drop
30910 GOSUB 22000
30920 RETURN

31200 REM +
31210 GOSUB 22000
31220 RH = VAL(V$)
31230 GOSUB 22000
31240 LH = VAL(V$)
31250 RT = LH + RH
31260 V$ = STR$(RT)
31270 GOSUB 21000
31280 RETURN

32200 REM -
32210 GOSUB 22000
32220 RH = VAL(V$)
32230 GOSUB 22000
32240 LH = VAL(V$)
32250 RT = LH - RH
32260 V$ = STR$(RT)
32270 GOSUB 21000
32280 RETURN

33200 REM *
33210 GOSUB 22000
33220 RH = VAL(V$)
33230 GOSUB 22000
33240 LH = VAL(V$)
33250 RT = LH * RH
33260 V$ = STR$(RT)
33270 GOSUB 21000
33280 RETURN

34200 REM /
34210 GOSUB 22000
34220 RH = VAL(V$)
34230 GOSUB 22000
34240 LH = VAL(V$)
34250 RT = LH / RH
34260 V$ = STR$(RT)
34270 GOSUB 21000
34280 RETURN