From: grand@sicsoft.epfl.CH ((grand))
Subject: My compiler
Organization: UNCW news/mail gateway service
Date: Fri, 24 Jul 1992 14:38:49 GMT



Hello,

First, I beg your pardon for my bad english. I nevertheless hope that you'll 
understand all the following.

I have just finished written the version 2.2 of my compiler for the HP-48SX. 
It can now compile mixed USER RPL instructions, SYSTEM RPL instructions and 
assembly language.

For example, here is a little program, STRSWAP, which swaps two characters in 
a string. This program is not optimised, it is only a demonstration program 
for my compiler.

Its syntax is :

        3: string
        2: position of the first character
        1: position of the second character

        If you type "ABCDEFGHIJ" 7 2 STRSWAP, the result is "AGCDEFBHIJ"

Here is the listing of STRSWAP :

; Program STRSWAP
; Exchange characters n1 and n2 of a string
; Usage : 3:stirng 2:n1 1:n2 --> 1:string
; Demonstration program for the HP-48 compiler written by Laurent Grand
; E-mail address : grand@sicsoft.epfl.ch

; Compiler's default mode is USER RPL

\<< R\->B SWAP R\->B    ; Transforms X and Y in binary integers
    ROT "" +            ; Makes a copy of the string

SYSRPL                  * Pass in SYSTEM RPL mode
::
        CK3NOLASTWD                 * Check for arguments
        CK&DISPATCH1 #BB3
        ::                          * if arguments are OK

ASSEMBLE

        include addr-48.as      ; Loads the main HP-48 addresses


        nibhex  #18EDF
        nibhex  prolog_system_binary
        nibhex  #00BB3

        nibhex  begin_code
        rel(5)  fincode
        gosbvl  save_reg
        d1=d1+5
        a=dat1  a
        d0=a
        d0=d0+10
        c=dat0  a
        d=c     a       ; d = X
        d=d-1   a
        d=d+d   a
        d1=d1+5
        a=dat1  a
        d0=a
        d0=d0+10
        c=dat0  a
        b=c     a       ; b = Y
        b=b-1   a
        b=b+b   a
        d1=d1-10
        a=dat1  a
        d0=a
        d0=d0+5
        c=0     w
        c=dat0  a
        lahex   #00005
        c=c-a   a
        ?c<=b    a
        goyes   fin     ; skip if Y > size of string
        ?c<=d    a
        goyes   fin     ; skip if X > size of string
        d0=d0+5         ; d0 = ^first character of the string
        ad0ex
        c=a     a
        a=a+b   a
        d0=a
        c=c+d   a
        d1=c
        a=dat0  b
        c=dat1  b
        dat0=c  b
        dat1=a  b
fin     gosbvl  load_reg
        a=dat0  a
        d0=d0+5
        pc=(a)
fincode nibhex  end_prog

        ENDCODE

        ;

USRRPL          ; Back to USER RPL mode

    ROT ROT DROP2 \>>



My compiler produces a downloadable binary file for the HP-48SX.
It optionnaly produces a listing file. Here is the listing file for STRSWAP :

         ; Program STRSWAP
         ; Exchange characters n1 and n2 of a string
         ; Usage : 3:stirng 2:n1 1:n2 --> 1:string
         ; Demonstration program for the HP-48 compiler written by Laurent Grand
         ; E-mail address : grand@sicsoft.epfl.ch
         
         ; Compiler's default mode is USER RPL

D9D20E16 \<<
32       
B9691    R\->B
DBBF1    SWAP
B9691    R\->B
         ; Transforms X and Y in binary integers
E0CF1    ROT
C2A20500 ""
00       
76BA1    +
         ; Makes a copy of the string
         
         SYSRPL
         * Pass in SYSTEM RPL mode
D9D20    ::
86A81    CK3NOLASTWD
         * Check for arguments
2BF81    CK&DISPATCH1
119203BB #BB3
00       
D9D20    ::
         * if arguments are OK
         
         ASSEMBLE
         
                 include addr-48.as      ; Loads the main HP-48 addresses
         ; File HP-48.AS
         ; Contains the main addresses of the HP-48SX
         
         
          define load_reg        #067d2
          define save_reg        #0679b
          define write_zeroes    #0675c
          define divide          #65807
          define multiply        #0db9b
          define malloc          #06ad8
          define garb_collect    #0613e
          define divide_by_5     #06a8e
          define copy_nibs       #0670c
          define copy_nibs_back  #066b9
          define begin_prog      d9d20
          define end_prog        b2130
          define begin_code      ccd20
          define prolog_system_binary    #02911
          define prolog_real             #02933
          define prolog_long_real        #02955
          define prolog_complex          #02977
          define prolog_long_complex     #0299d
          define prolog_character        #029bf
          define prolog_array            #029e8
          define prolog_linked_array     #02a0a
          define prolog_string           #02a2c
          define prolog_binary_integer   #02a4e
          define prolog_list             #02a74
          define prolog_directory        #02a96
          define prolog_algebraic        #02ab8
          define prolog_unit             #02ada
          define prolog_tagged           #02afc
          define prolog_graphic          #02b1e
          define prolog_library          #02b40
          define prolog_backup           #02b62
          define prolog_library_data     #02b88
          define prolog_program          #02d9d
          define prolog_code             #02dcc
          define prolog_global_name      #02e48
          define prolog_local_name       #02e6d
          define prolog_xlib_name        #02e92
         
         
         
FDE81            nibhex  #18EDF
11920            nibhex  prolog_system_binary
3BB00            nibhex  #00BB3
         
CCD20            nibhex  begin_code
D8000            rel(5)  fincode
8FB9760          gosbvl  save_reg
174              d1=d1+5
143              a=dat1  a
130              d0=a
169              d0=d0+10
146              c=dat0  a
D7               d=c     a       ; d = X
CF               d=d-1   a
C7               d=d+d   a
174              d1=d1+5
143              a=dat1  a
130              d0=a
169              d0=d0+10
146              c=dat0  a
D5               b=c     a       ; b = Y
CD               b=b-1   a
C5               b=b+b   a
1C9              d1=d1-10
143              a=dat1  a
130              d0=a
164              d0=d0+5
AF2              c=0     w
146              c=dat0  a
80824500         lahex   #00005
00       
E2               c=c-a   a
8B9              ?c<=b    a
52               goyes   fin     ; skip if Y > size of string
8BB              ?c<=d    a
02               goyes   fin     ; skip if X > size of string
164              d0=d0+5         ; d0 = ^first character of the string
132              ad0ex
D6               c=a     a
C0               a=a+b   a
130              d0=a
CB               c=c+d   a
135              d1=c
14A              a=dat0  b
14F              c=dat1  b
14C              dat0=c  b
149              dat1=a  b
8F2D760  fin     gosbvl  load_reg
142              a=dat0  a
164              d0=d0+5
808C             pc=(a)
B2130    fincode nibhex  end_prog
         
                 ENDCODE
         
B2130    ;
         
         USRRPL
         ; Back to USER RPL mode
         
E0CF1    ROT
E0CF1    ROT
3FBF1    DROP2
93632B21 \>>
30       
         
You may choose the width of the code column. In the example, I choosed width 
of 8 characters.


An other example of program is STR2NAME, which transforms a non-empty string 
into an algebraic. Here is the listing file :

                 SYSRPL
                 * Program STR2NAME
                 * Transforms a string in an algebraic
                 * Usage : 1:string -> 1:algebraic
                 
D9D20            ::
2BA81            CK1NOLASTWD
D9F81            CK&DISPATCH0
D0040            str
                 * check for argument 1: string
D9D20            ::
90236            DUPNULL$?
B3A16            ?SEMI
                 * exit if null string
51B50            $>ID
                 * call str->alg routine
B2130            ;
B2130            ;
                 
                 
                 
Fine, no ?

You may include comments in any part of the program.

My compiler is able to compile every USER RPL instructions, even such as

'A*B/-COMB(AA(X,Y),\v/M)'

where \v/ is the symbol given for the square root when you transfer a program 
in ASCII mode, translate code 3, and AA is any function with two arguments.

You can transfer an executable file or a string containing the hexadecimal
code of your program (or your object).

The compiler works in translate code 3, with a '.' for the decimal point.

===> The compiler runs on DOS compatible systems. <===

If you are interested, I sell you a registered version of it (with a little
documentation file) for 20 US dollars or 30 swiss francs. The package contains 
a documentation file about SYSTEM RPL instructions. You can receive it on 
either 5 1/4'' or 3 1/2'' floppy disk. The documentation files are in english. 
All the compiler's messages in english.

My S-mail -> 31. August 1992 :

            Laurent Grand
            Grand-Rue 26
            1820 Montreux
            SWITZERLAND

My S-mail after 31. August 1992 :

            Laurent Grand
            Chemin du Borgeaux
            1817 Brent
            SWITZERLAND

My Email :

             grand@sicsoft.epfl.ch


The easiest (and less expensive) way for the payment is to slip a banknote
in your S-mail.

Have a nice day !

Laurent Grand
Newsgroups: comp.sys.hp48