Post Reply 
(HP48) Assembler Question
02-14-2023, 01:19 PM (This post was last modified: 06-16-2023 08:19 PM by Giuseppe Donnini.)
Post: #2
RE: (HP48) Assembler Question
1. HOW TO CALL POP1%

POP1% already contains a jump to SAVPTR. Here is what its disassembly looks like (I’ve added some comments to make it as readable as possible):

Code:
29FDA          =POP1%
29FDA 147               C=DAT1  A         * Read address of real number object on stack level 1.
29FDD 137               CD1EX             * D1:Point to real number object; C[A]:Save RPL variable D (Data Stack Pointer).
29FE0 174               D1=D1+  5         * Skip prologue address of real number object (DOREAL).
29FE3 1537              A=DAT1  W         * Read value of real number object.
29FE7 135               D1=C              * Restore RPL variable D (Data Stack Pointer).
29FEA 174               D1=D1+  5         * (D1 holds RPL variable D) Point to address of next object. \ Effectively drops real
29FED E7                D=D+1   A         * (D[A] holds RPL variable M) Increment free memory counter. /   number from stack.
29FEF 05                SETDEC            * Set decimal arithmetic mode.
29FF1 8DB9760           GOVLNG  =SAVPTR   * Get RPL variables out of the way by saving them in reserved system RAM.

So, here’s the right way to do it:

Code:
        GOSBVL  =POP1%
* ...
        SETHEX
        GOVLNG  =GETPTRLOOP

Also note that GETPTRLOOP passes control back to System RPL, so you should use GOVLNG instead of GOSBVL. It’s not a good idea to leave garbage on the hardware return stack.

 
2. LOOP vs. Loop

In the world of RPL and SATURN Assembly, everything is case sensitive.

LOOP can be one of two things:

  1. Either it is an RPL primitive code object used together with DO (or a similar object) in order to build a definite loop control structure in System RPL.
    This is obviously not what you want, since your program is written in SATURN assembly.

     
  2. Or it is a (macro-like) compiler directive instructing the compiler to replace the LOOP statement by the following actual code, representing the RPL inner loop:

    Code:
            A=DAT0  A
            D0=D0+  5
            PC=(A)

    Whether LOOP, in the sense at hand, is recognized or not, depends on the compiler you are using. RPLCOMP.EXE does recognize it, SASM.EXE (which is not a compiler) doesn't. (Note that LOOP is recognized by RPLCOMP.EXE if it is either the first word on the line, or the second word preceded by a label.)


Loop, on the other hand, is the machine-language entry point you are looking for.

Code:
2D564          =Loop
2D564 142               A=DAT0  A
2D567 164               D0=D0+  5
2D56A 808C              PC=(A)

 

To sum it all up: If you want to give control back to the RPL world:
  • Use the following in-line code:

    Code:
            A=DAT0  A
            D0=D0+  5
            PC=(A)

     
  • Or, to save some typing, use the LOOP statement, if you are using RPLCOMP.EXE (or a compiler that recognizes the LOOP statement). This will obviously result in the exact same compiled code.

     
  • Or jump to Loop at the end of your assembly program.

    Code:
    8D465D2           GOVLNG  =Loop

    This method is slower than in-line code, because it takes some CPU cycles to carry out the jump to address #2D564h, but it will save three nibbles of space (7 vs. 10).

     
  • If, before going back to RPL, you also need to restore the RPL variables, you can jump to a (machine-language) entry point that combines both actions, e.g. GETPTRLOOP, which dissassembles to:

    Code:
    05143          =GETPTRLOOP
    05143 8E9861            GOSUBL  =GETPTR
    05149 142               A=DAT0  A
    0514C 164               D0=D0+  5
    0514F 808C              PC=(A)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(HP48) Assembler Question - Hiwi - 02-14-2023, 08:52 AM
RE: (HP48) Assembler Question - Giuseppe Donnini - 02-14-2023 01:19 PM
RE: (HP48) Assembler Question - Hiwi - 02-15-2023, 11:08 AM
RE: (HP48) Assembler Question - Hiwi - 03-02-2023, 10:53 AM



User(s) browsing this thread: 1 Guest(s)