RPL 32



#6

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


#7

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.


#8

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


#9

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.


#10

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

Dave


Possibly Related Threads...
Thread Author Replies Views Last Post
  Writing RPL programs on OS X Sean Freeman 18 745 11-30-2013, 03:59 PM
Last Post: Sean Freeman
  48G vs 49G+ User RPL Speed Comparison John Colvin 7 274 11-16-2013, 10:07 PM
Last Post: Han
  Where to the 32-bit version of User Code Utiltiy for HP-41 ? Olivier (Wa) 2 155 09-26-2013, 01:55 AM
Last Post: Olivier (Wa)
  HHC / HP Museum Programming Contest for RPN and RPL machines Gene Wright 18 719 09-22-2013, 09:39 AM
Last Post: Miguel Toro
  Last HP emulation, 32 & 01 Olivier De Smet 0 135 09-07-2013, 08:27 AM
Last Post: Olivier De Smet
  RPL long vs. short names peacecalc 5 254 10-30-2012, 01:25 PM
Last Post: peacecalc
  Mini-challenge: HHC2012 RPL programming contest with larger input David Hayden 14 558 10-05-2012, 10:36 PM
Last Post: David Hayden
  HHC 2012 RPL Programming Contest Gene Wright 33 1,038 09-27-2012, 01:57 AM
Last Post: Werner
  HHC 2012 programming contests coming soon (RPN and RPL) Gene Wright 9 395 09-21-2012, 03:38 PM
Last Post: Paul Dale
  RPL prog for Fibonacci on HP 48G needs minor modification. help. wildpig 68 1,581 07-09-2012, 09:38 AM
Last Post: Gilles Carpentier

Forum Jump: