What's cool about this System RPL program that solves the quadratic equation? It's a slighly modified version of the program on page 53 of An Introduction to HP 48 System RPL and Assembly Language Programming by Jim Donnelley (page 63 of the PDF version on hpcalc.org). The change is that it includes the inputs (%1 % -4 %3) and a non-standard "showStack" word at the end:
DEFINE a 6GETLAM
DEFINE b 5GETLAM
DEFINE c 4GETLAM
DEFINE root1 3GETLAM
DEFINE root1STO 3PUTLAM
DEFINE root2 2GETLAM
DEFINE root2STO 2PUTLAM
DEFINE Subr 1GETLAM%1 % -4 %3
::
0LASTOWDOB! CK3NOLASTWD
CK&DISPATCH0 3REAL
::
%0 %0
' :: a %2 %* %/ ;
{
NULLLAM
NULLLAM
NULLLAM
NULLLAM
NULLLAM
NULLLAM
}
BIND
b DUP %* a c %* %4 %* %-
DUP %0< casedrop
:: "Complex Roots" ABND ;
%SQRT
b %CHS OVER %+ Subr EVAL
root1STO
b %CHS SWAP %- Subr EVAL
root2STO
root1
root2
ABND
;
;
showStack
HALT
The answer is that it runs on my 32-bit RPL system written in C++.
So far the system supports BINTs, secondaries, LISTS, REALs, STRINGs, loop environments, temporary environments and local variables (LAMs). It does error jumps, and argument validation. The garbage collector can run incrementally.
I've taken a few shortcuts of course, but only a few. REALs are currently binary instead of BCD. This let me get them working quickly and it can be fixed later without affecting the rest of the system.
I'm still trying to figure out a way to deal with low memory conditions. Real RPL does garbage collection as soon as it needs to, which means that objects can move around almost any time. The garbage collector fixes RPL pointers but it can't fix C++ pointers that may exist. Dealing with this in C++ would be very error prone.
I should be writing Prime programs but this is just way too much fun :)
Dave