[comp.sys.handhelds] RPL constructs

bson@rice-chex.ai.mit.edu (Jan Brittenson) (10/17/90)

   Could someone who knows, please describe how conditionals, loops,
and CASEs are stored internally? I need it to get SAD 1.02 to
disassemble RPL code. Actually, it already does, but I intend to
supply macros for common RPL constructs to get the indentation
correct.

   Oh, and could someone explain what reals (i.e. 64-bit floating
point words) look like? Things like how the exponent is stored, the
exponent sign, the mantissa sign, etc. I haven't done any thorough
investigation here, and only know vaguely what is what.

   Also, please voice your opinion on the following (PROGRAM and END
are SAD macros, which currently is the only way to define proper
indentation among other things) format:


1cb86   Cmd_TYPE:
1cb86 d9d20    PROGRAM
1cb8b 5aa81      #18aa5
1cb90 d9d20      PROGRAM
1cb95 d9f81        #18f9d
1cb9a 9ff30        Short_1		; ; #3ff9
1cb9f 4b2a2        Real_0		; ; #2a2b4
1cba4 30040        Short_2		; ; #4003
1cba9 9c2a2        Real_1		; ; #2a2c9
1cbae d0040        Short_3		; ; #400d
1cbb3 ed2a2        Real_2		; ; #2a2de
1cbb8 71040        Short_4		; ; #4017
1cbbd 1bdc1        #1cdb1
1cbc2 12040        Short_5		; ; #4021
1cbc7 d13a2        Real_5		; ; #2a31d
1cbcc b2040        Short_6		; ; #402b
1cbd1 233a2        Real_6		; ; #2a332
1cbd6 53040        Short_7		; ; #4035
1cbdb 743a2        Real_7		; ; #2a347
1cbe0 f3040        Short_8		; ; #403f
1cbe5 4ddc1        #1cdd4
1cbea 94040        Short_9		; ; #4049
1cbef 173a2        Real_9		; ; #2a371
1cbf4 d5040        Short_0bh		; ; #405d
1cbf9 7e056        Real_10		; ; #650e7
1cbfe 76040        Short_0ch		; ; #4067
1cc03 3392010      REAL 1.1E1
      0000000
      0000110
1cc18 17040        Short_0dh		; ; #4071
1cc1d 3392010      REAL 1.2E1
      0000000
      0000210
1cc32 b7040        Short_0eh		; ; #407b
1cc37 3392010      REAL 1.3E1
      0000000
      0000310
1cc4c 58040        Short_0fh		; ; #4085
1cc51 3392010      REAL 1.4E1
      0000000
      0000410
1cc66 52140        Short_1fh		; ; #4125
1cc6b 3392010      REAL 2.0E1
      0000000
      0000020
1cc80 03b46        Short_2fh		; ; #64b30
1cc85 3392010      REAL 1.5E1
      0000000
      0000510
1cc9a 11920f3      ADDRESS #3f
      000
1cca4 3392010      REAL 2.1E1
      0000000
      0000120
1ccb9 11920f4      ADDRESS #4f
      000
1ccc3 3392010      REAL 2.2E1
      0000000
      0000220
1ccd8 11920f5      ADDRESS #5f
      000
1cce2 3392010      REAL 2.3E1
      0000000
      0000320
1ccf7 11920f6      ADDRESS #6f
      000
1cd01 3392010      REAL 2.4E1
      0000000
      0000420
1cd16 11920f7      ADDRESS #7f
      000
1cd20 3392010      REAL 2.5E1
      0000000
      0000520
1cd35 e2d46        Short_8fh		; ; #64d2e
1cd3a 3392010      REAL 1.6E1
      0000000
      0000610
1cd4f 06d46        Short_9fh		; ; #64d60
1cd54 3392010      REAL 1.7E1
      0000000
      0000710
1cd69 11920fa      ADDRESS #af
      000
1cd73 3392010      REAL 2.6E1
      0000000
      0000620
1cd88 fef30        Short_0		; ; #3fef
1cd8d 3392010      REAL 2.7E1
      0000000
      0000720
1cda2 b2130      END
1cda7 b9f06      #60f9b
1cdac b2130    END
1cdb1 d9d20    PROGRAM
1cdb6 88130      Dup			; ; #3188
1cdbb b3226      #6223b
1cdc0 8da16      #61ad8
1cdc5 3f2a2      Real_3			; ; #2a2f3
1cdca 803a2      Real_4			; ; #2a308
1cdcf b2130    END
1cdd4 d9d20    PROGRAM
1cdd9 9af16      #61fa9
1cdde da916      Branch_if_true		; ; #619ad
1cde3 c53a2      Real_8			; ; #2a35c
1cde8 d2a62      #26a2d
1cded 39916      Branch_if_false	; ; #61993
1cdf2 3392010    REAL 1.8E1
      0000000
      0000810
1ce07 3392010    REAL 1.9E1
      0000000
      0000910
1ce1c b2130    END

n233dk@tamuts.tamu.edu (Rick Grevelle) (10/17/90)

In article <11408@life.ai.mit.edu> you write:
>
>   Could someone who knows, please describe how conditionals, loops,
>and CASEs are stored internally? I need it to get SAD 1.02 to
>disassemble RPL code. Actually, it already does, but I intend to
>supply macros for common RPL constructs to get the indentation
>correct.
>

I not quite sure what it is that you're asking; are you wanting someone
to explain how machine code handles these items, or are you asking about
the prefixed machine routines that RPL calls to handle decision making?
By common RPL constructs I assume you mean the later; but please explain 
further.

>   Oh, and could someone explain what reals (i.e. 64-bit floating
>point words) look like? Things like how the exponent is stored, the
>exponent sign, the mantissa sign, etc. I haven't done any thorough
>investigation here, and only know vaguely what is what.

Alonzo Gariepy explains this in his Processor Notes in terms of the various
fields used within the internal registers.  Here is a simplification of it.

                         Internal Real
                 
                    s mmmmmmmmmmmm s ee ppppp
    
i)   The lower case s's indicate the sign of the mantissa and exponent.  For 
     positive values a zero is used, and a nine is used for negative values.

ii)  The twelve lower case m's represent the mantissa.

iii) The two lower case e's are the exponent.

iv)  And the lower case p's are the prolog #02933h.

>   Also, please voice your opinion on the following (PROGRAM and END
>are SAD macros, which currently is the only way to define proper
>indentation among other things) format:

Whoa!  I don't know about this; it could be a potential copy right violation.
Don't get me wrong, you're doing an extraordinaryly good job; obviously you're
quite knowledgeable.  But HP is a rather large and powerful corporation, with
high dollar attorneys on retainer.  Posting, without permission, portions of
code from the 48's ROM on which HP holds the copyright is a very grey area.

Personally, I'm little paranoid about much of the material alluded to in my
postings.  I am almost certain that by now HP must hate me.  However, I once
discussed the matter with Alonzo, from whose opinion I formed my currenlty
used guidelines for posting to the net, so there is probably no reason for
me to worry.
 
As for as my opinion on your format is concerned; it is EXCELLENT!  It looks
almost identical to RPL disassemblies I've been doing by hand since the 28.
I'm looking forward to this latest version of SAD, with it I could cover ten
times the amount of territory than in the past.  No one has yet to produce,
outside of HP, an RPL disassembler this accurate; at least of which I know.

Rick Grevelle

bson@rice-chex.ai.mit.edu (Jan Brittenson) (10/18/90)

In article <9206@helios.TAMU.EDU> 
   n233dk@tamuts.tamu.edu (Rick Grevelle) writes:

 > I not quite sure what it is that you're asking; 

   Perhaps I should have been more precise: this may dumbfound you,
but all I want to know is how they are stored. I remember someone
mentioning a while ago that there is more to how an IF clause is
stored than just the keywords (RPL addresses of IF, THEN, etc). I have
also noticed there are several more branch (switch on types, for
instance) instructions used internally.

 >> Oh, and could someone explain what reals (i.e. 64-bit floating point
 >> words) look like? Things like how the exponent is stored, the exponent
 >> sign, the mantissa sign, etc. I haven't done any thorough
 >> investigation here, and only know vaguely what is what.

 > Alonzo Gariepy explains this in his Processor Notes in terms of the
 > various fields used within the internal registers.  Here is a
 > simplification of it.

 >
 >                         Internal Real
 >                 
 >                    s mmmmmmmmmmmm s ee ppppp

 >iii) The two lower case e's are the exponent.

   Is the exponent stored as an 8-bit integer (i.e. 0-255), or as two
digits (00-99)? It would make sense to me if also bits of the exponent
sign nibble were used, since the exponent range is -499 to 500.
Perhaps it's three digits (000-999), with a xsn digit of '5' or higher
denoting negation? What about the mantissa sign - are mantissa signs
of 0-4 considered positive while 5-9 are considered negative?

 > Whoa!  I don't know about this; it could be a potential copy right
 > violation.  ...HP is a rather large and powerful corporation, with
 > high dollar attorneys on retainer.  Posting, without permission,
 > portions of code from the 48's ROM on which HP holds the copyright is
 > a very grey area.

   If this is a problem, I can volunteer to set up a mailing list to
which I only add people after they submit me a message stating their
48's serial number, and its place and date of purchase. I'll be more
careful with posting things like this to the net.

 > Personally, I'm little paranoid about much of the material alluded to
 > in my postings.  I am almost certain that by now HP must hate me.

   Does HP even care? If nothing else, it's probably just good for
their sales and image.

n233dk@tamuts.tamu.edu (Rick Grevelle) (10/18/90)

In article <11423@life.ai.mit.edu> bson@rice-chex.ai.mit.edu (Jan Brittenson) writes:

> Perhaps I should have been more precise: this may dumbfound you,
> but all I want to know is how they are stored. I remember someone
> mentioning a while ago that there is more to how an IF clause is
> stored than just the keywords (RPL addresses of IF, THEN, etc). I have
> also noticed there are several more branch (switch on types, for
> instance) instructions used internally.

Jan, it was me to whom you refer.  I now know what it is you're asking, but
this should be an easy task for you.  The difficult task is deciphering the
numerous machine routines used internally by RPL to handle these structures.
The relatively few prefixed machine routines used to support keywords such as
these are just the tip of the iceberg as far as the internal world of RPL is
concerned.

Further, many of these are multifacited in that they will perform differently
depending on what conditions exist at the time of execution.  Take for example 
the prefixed machine routine responsible for both keywords START and DO.  The
routine's address is #71A2h.  Here is an example of how this routine works.

     Used as START

     02D9D  begin RPL
     23754  list_{ 'noname 'stop }
            (these are local variables used to store the start and end of loop)
     074D0  store_local_variables
     071A2  start
     .....
     .....  (loop clause)

     2326A  next
     0312B  end RPL


     Used as DO

     02D9D  begin RPL
     071A2  do
     .....
     .....
    
     071C8  end? (requires boolean #3A81h, true; or #3AC0h, false)

Here are some other clause addresses I've currently documented in the 48:

073C3  start 0 to n-1 1short
073C3  start 1 to n-1 1short
073DB  start 1 to n-1 1short
073F7  start n2 to n1 1short2short
07221  current loop increment
07249  n of loop
07334  next
073A5  step

If you're interested in how these routines manipulate data, do what I did and
disassemble them.  If it's the keyword structures such as DO UNTIL END, START
NEXT, or IF THEN ELSE in which you're interested, store them in the top of the
RAM and PEEK at what is there.  The manner in which these are stored is fairly
straight foward; there is some nesting which occurs, but it shouldn't be any
sort of a problem for you.  If you should have any specific questions about
you findings, post them here or send via <email>.

>  Is the exponent stored as an 8-bit integer (i.e. 0-255), or as two
> digits (00-99)? It would make sense to me if also bits of the exponent
> sign nibble were used, since the exponent range is -499 to 500.
> Perhaps it's three digits (000-999), with a xsn digit of '5' or higher
> denoting negation? What about the mantissa sign - are mantissa signs
> of 0-4 considered positive while 5-9 are considered negative?

You are quite right, I stand corrected.  The exponent for a real is stored as
twelve bits.  The quick and dirty way to determine what negative exponents will
look like when stored internally is to add the negative exponent to a thousand.

For example, to determine what 1.23E-456 would look like internally, add -456
to 1000.  The negative exponent would be stored as 544.  Here is how the real
looks internally.

012300000000054402933

As far as the sign field of the mantissa is concerned, it remains as previously
described; a zero for a positive and nine for negative mantissas.  Also note
that the mantissa utilizes only decimal numerals, hex characters A-F never
appear.

>  If this is a problem, I can volunteer to set up a mailing list to
> which I only add people after they submit me a message stating their
> 48's serial number, and its place and date of purchase. I'll be more
> careful with posting things like this to the net.

>  Does HP even care? If nothing else, it's probably just good for
> their sales and image.

The mailing list sounds great to me.  Does HP care?... I don't know.. I don't
think I'd want to find out, at least in a court of law I wouldn't.  Now about
it being good for their sales image, it wouldn't seem so.  Eventhough this news
group is read around the world, I'd bet you that were only a very small percent
of HP users.  For instance, there are 44,000 students enrolled this Fall here 
at A&M.  I've seen 48s all over, especially within the college of engineering,
but I personally know of only a couple of individuals who actively read this 
board.

Rick Grevelle

frechett@boulder.Colorado.EDU (-=Runaway Daemon=-) (10/19/90)

In article <9250@helios.TAMU.EDU-> n233dk@tamuts.tamu.edu (Rick Grevelle) writes:
->
->In article <11423@life.ai.mit.edu> bson@rice-chex.ai.mit.edu (Jan Brittenson) writes:
->
->>  Does HP even care? If nothing else, it's probably just good for
->> their sales and image.
->The mailing list sounds great to me.  Does HP care?... I don't know.. I don't
->think I'd want to find out, at least in a court of law I wouldn't.  Now about
->it being good for their sales image, it wouldn't seem so.  Eventhough this news
->group is read around the world, I'd bet you that were only a very small percent
->of HP users.  For instance, there are 44,000 students enrolled this Fall here 
->at A&M.  I've seen 48s all over, especially within the college of engineering,
->but I personally know of only a couple of individuals who actively read this 
->board.
->
->Rick Grevelle

I think the point here is that it doesn't hurt HP.  And I think that it does
boost sales just a bit.  I have convinced two people to buy 48s based on what I
showed them I could do and on the information that this newsgroup exists.  When
I see the useful information on this machine on this group it increases my
inthusiasm for the product and I actually "sell" calculators for HP.  Two of my
friends bought 48s less than a day after I showed it to each one of them.  I
know 3 other people that are getting information from me in preparation to
selling the calculator.  Some of they stuff that people find impressive is
machine language programs that people have written using this information.  
I know that this sounds roundabout but it sells calculators and isn't that
really what HP wants?   As long as the calculator still interests me I will
continue to recomend it to people that I know and don't know.  

	I have a question too... It seems that we have tracked down the problem
of the screwed up batteries in the hp28 but I couldn't remember that the easy
fix was.  I have a friend that is having probs with his 28 with it losing
memory so I told him what I knew but I don't remember what dimension it was
that was wrong...  What could he stick in there to make it work.  Is it just to
stop the battery from wiggling or it the distance from contact to contact
wrong?  If so then one would have to put something conductive in to fill the
gap.  IF you have a solution to this, please mail me or post as you like.
Thanks.  

	ian

--

	-=Runaway Daemon=-

akcs.dnickel@hpcvbbs.UUCP (Derek Scott Nickel) (10/22/90)

BCD numbers (binary coded decimal) are represented by a mantissa,
sign and exponent fields.  There are two kinds of BCD numbers in 
the HP 48SX, 12-form and 15-form BCD numbers, called BCD12 and
BCD15 in the field descriptions.

Both kinds have several things in common:

    *    A mantissa.  Each digit of the number is represented by 
         one nibble in the mantissa.  12-form BCD numbers have a
         12 digit mantissa and 15-form BCD numbers have a 15
         digit mantissa.  There is an implied decimal point after
         the Most Significant Digit (msd) with respect to the 
         exponent.

    *    A sign nibble.  Positive numbers are represented by a 
         0 and negative numbers are represented by a 9.

    *    An exponent.  The exponent is in 10's compement.
         12-form BCD numbers have a 3 nibble exponent and 15-form
         BCD numbers have a 5 digit exponent.

12-form BCD numbers are the basis for Real Number, Complex 
Number, Real Array and Complex Array data types.

15-form BCD numbers are the basis for Long Real and Long
Complex data types.

BCD12:

 15 14                     3  2   0
+--+------------------------+------+
|S | msd..  Mantissa  ..lsd | Exp  |
+--+------------------------+------+
 1             12              5

BIN15:

 21 20                           5  4       0
+--+------------------------------+----------+
|S | msd...    Mantissa    ...lsd |   Exp    |
+--+------------------------------+----------+
 1                15                   5

------------
This is from my 'HP 48SX Internals' document that is getting close to its
first posting.  Hope it helps.

Take a look at the Real Number and Long Real objects starting with 
0 (Real Number) at 2A2B4 to 10 (Long Real) at 2A596.  There are 34
objects in that range.  Most are simple.  But includes PI and MAXR...

    Good Luck!

    Derek S. Nickel