The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

RPL 32
Message #1 Posted by David Hayden on 10 Nov 2013, 11:22 a.m.

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

      
Re: RPL 32
Message #2 Posted by Tim Wessman on 10 Nov 2013, 12:11 p.m.,
in response to message #1 by David Hayden

Cool!

>but it can't fix C++ pointers that may exist.

Good luck... :-| (this is where it all falls apart)

TW

Edited: 10 Nov 2013, 12:11 p.m.

            
Re: RPL 32
Message #3 Posted by David Hayden on 10 Nov 2013, 2:23 p.m.,
in response to message #2 by Tim Wessman

Quote:
Good luck... :-| (this is where it all falls apart)
:) The voice of experience no doubt.

I have a couple of ideas that might work. I'll let you know how it goes.

Dave

                  
Re: RPL 32
Message #4 Posted by Marcus von Cube, Germany on 10 Nov 2013, 3:39 p.m.,
in response to message #3 by David Hayden

16 Bit Windows uses handles instead of pointers. All APIs use these handles which allows for moving around the associated memory objects.

If you store a reference count in such a handle, removing unreferenced objects becomes a little easier. Objects containing handles to other objects need a recursive approach for the garbage collector. This is what Java seems to have implemented.

                        
Re: RPL 32
Message #5 Posted by David Hayden on 11 Nov 2013, 11:34 a.m.,
in response to message #4 by Marcus von Cube, Germany

Thanks for the tip Marcus. I'd forgotten about that approach.

Dave


[ Return to Index | Top of Index ]

Go back to the main exhibit hall