[comp.sys.handhelds] HP 48: machine code

alonzo@microsoft.UUCP (Alonzo GARIEPY) (03/17/90)

The biggest problem with using the memory scanner to enter machine
code is that it can be difficult to find the correct location.
Unlike the HP 28, this first variable has no fixed position.

	*	*	*	*	*

A BETTER WAY TO ENTER MACHINE CODE 

Here is an HP 48 version of Rick Grevelle's scheme for creating CODE 
objects.  Note that these particular SYSEVAL addresses may not work 
on future HP 48 rom revisions (but the new ones will be easy to find 
when the time comes).

Below I have reproduced Rick's original text modified to work on the
HP 28.

------------------------------------------------------------------------

Alonzo,
      I have found the solution to the code problem. You can now
code quickly and painlessly with less chance of error by using a
machine subroutine from the ROM. It allows for easy documentation
of user written machine programs and eleminates the problem of check
sums not being able to differentiate between system objects. The ROM
address of the machine routine that allows you to do this is [#5193h].
According to [Alonzo's] ROM map: [05193]  +_1string2string. This is a bit
over simplified in that the routine will allow binary integers to be
used as well as strings. I discovered that the routine works by using
the prolog of the object in level 1 to determine the the object type
after the addition. What this means is, if level 2 contains a binary
integer and level 1 a null string, or any string, the prolog for the
binary integer [#2A4Eh] is discarded for that of the string [#2A2Ch].
Here I will use PIG as an example. I think you'll agree that there is
no contest between using this approach to enter and run machine programs
and any of the other previous ones.

Enter PIG as follows:  PIGS  [7243]

                      { #3012310003B02DCCh
                        #1631641961031341h
                        #3117451961031765h
                        #C808461241231h  }

Now you are ready to enter the program that will turn the binary
integers into executable form.

           ->SYS  [6453] 
           <<  
	      " "  +  LIST->  2  SWAP      ; Intialize null string
              START #5193h  SYSEVAL        ; Begin code loop
              NEXT  #4003h  SYSEVAL        ; End loop, set pointer
              #56B6h SYSEVAL DROP          ; End program, get object
	   >> 

Rick Grevelle
------------------------------------------------------------------------

Rick's example PIG does no error checking, so it is a little too dangerous.
Applying ->SYS to Dave Kaffine's PEEK, you would use the array:

PEEKS  [7619]

{ #B196BB2361E02D9D
  #410003002DCC1969
  #1731741971607317
  #173170F951731FB5
  #2B23639C80846124
  #031
}

PEEKS ->SYS 'PEEK' STO

gives you

PEEK  [A1BC]
<< B->R R->B Code >>

	*	*	*	*	*

EASY ENTRY OF HEXADECIMAL INTEGER ARRAYS

1)  First I'll show you how to enter hexadecimal integers more easily.

Create the program HINT in your HOME directory.  *a designates the
greek alpha character (alpha-shift blue-shift A).

	HINT  [F654] 
	<<
	    "" { "# h" *a V 3 }
	    IFERR INPUT OBJ->
	    THEN DROP DROP END
	>>

Run this program and you'll see it makes entering hex integers easy.
The IFERR stuff allows you press ON to abort entry without getting
extraneous stuff on the stack.

To make this program really useful, bind it to the EEX key (or any
other key) in USER mode.  Since I rarely use exponential notation,
the EEX key is ideal for me.  To do the binding, type:

	'HINT' 53.1 ASN

To enter user mode type:

	gold-shift USR

Now, to enter a binary number, just press EEX first.  It will put
the # h on the command line, put you in alpha entry mode and position
the cursor.  Press ENTER when you have entered the number.

2)  Now, here's how to enter binary arrays

Enter each binary number on the stack.  For the PEEK program, you
would type the first integer with

	EEX B 1 9 6 B B 2 3 6 1 E 0 2 D 9 D ENTER

Type the remaining integers the same way.

Once you have them all on the stack, press up arrow.  Continue to 
press up arrow until you reach the first integer (#B196BB2361E02D9Dh).
Now press ->LIST.  The stack editor will package the 6 integers on
the stack into a LIST.  Now type

	'PEEKS' STO

Check that you have typed everything correctly with:

	'PEEKS' BYTES

The answer should be:  [7619]

	*	*	*	*	*

Don't get frustrated by all the ways of entering machine code.  The
important thing is to understand what is going on in each case.  My
HP 28 processor notes can help with this.  These methods are mainly
for those who want to program in machine code.  If you just want to
use such programs, your best bet is to load them into your HP 48 in
binary mode using the serial port.  Following is a uuencoded version
of the PEEK program above.  

-----------------------cut here------------------------------------
begin 600 peek
M2%!(4#0X+4&=+>!A([N6L6D9S"T``P!!%W-@<1ET,1>U'W-1^7`Q%R1AA("<
%8R,K,0`X
`
end
-----------------------and here------------------------------------

In the next posting is a SYSEVAL based PEEK that doesn't even need
machine code.

Alonzo Gariepy
alonzo@microsoft