[comp.sys.handhelds] Machine code on the HP48

tjb@tadtec.uucp (Tim Bissell) (09/04/90)

Hi there!

I am trying to get started writing machine code for the hp48sx.  I have
got a copy of the Sass 2.31 assembler running on a Unix box, and a
HP48SX with revision A ROMs.  I can assemble the supplied cht.s example
program, and get this in ->SYS mode:

%%HP: T(3);
{
# 1231641961231341h
# 2314412313417E47h
# C808461241h
}

The \->SYS I use is one I have is listed identically in two different articles,
and as uploaded from my 48 looks like this -- note that my checksum is
different to the checksums listed, although the text is identical:

@ \->SYS [ # 5507h / 88.5 ]
%%HP: T(3)A(D)F(.);
\<< " " + LIST\-> 2
SWAP
  START # 5193h
SYSEVAL
  NEXT # 4003h
SYSEVAL # 56B6h
SYSEVAL DROP
\>>

When I try and make a code object by recalling the list to the stack
and running \->SYS on it, an 'External' object rather than a 'Code' object
is created.  Could it be that the Sysevals in \->SYS don't work on
Rev. A ROMs?

How does one translate the output of Sass -c/-p/-pc into a form which
can be downloaded as a code object? can you just translate ASCII bytes
into binary bytes, or do you need to do some word/byte or nibble swapping?

Any help would be appreciated.  If you post suggestions etc. to me
I will summarise the results and post a "getting started in HP48 machine code"
article to this group.

Thanks in advance,

Tim.

-- 
Tim Bissell  Tadpole Technology | (tjb@tadtec.UUCP || ...!mcsun!ukc!tadtec!tjb)
Cambridge Science Park 		| "Is life worth living?              DoD#174
Cambridge ENGLAND		|  That depends on the liver"         CBR 600

bson@wheat-chex.ai.mit.edu (Jan Brittenson) (09/05/90)

In article <TJB.90Sep4133352@tadtec.uucp> tjb@tadtec.uucp (Tim Bissell) writes:

 > I can assemble the supplied cht.s example
 > program, and get this in ->SYS mode:

 > HP: T(3);
 > {
 > #1231641961231341h
 > #2314412313417E47h
 > #C808461241h
 > }

   This is not a code object. You have to include an a-sized (5
nibbles) type (02DCC stored backwards) followed by an a-sized length.
The length is the size of the actual code, 2*16+10 (#2Ah) in your
example.  So try:

	{
	#2313410002A02DCCh
	#417E471231641961h
	#4612412314412313h
	#C808h
	}

	->SYS

   I've never used sass, but you should be able to insert a type
constant and a length at the beginning if sass doesn't do it for you.
(Seems silly if it doesn't, since the output wouldn't be ->SYS
compatible.)

bson@rice-chex.ai.mit.edu (Jan Brittenson) (09/05/90)

In article <10430@life.ai.mit.edu> I wrote:

>The length is the size of the actual code, 2*16+10 (#2Ah) in your
>example.  So try:
>
>	{
>	#2313410002A02DCCh

Should read `2*16+10+5 (#2Fh)' and `#2313410002F02DCCh' respectively.


   I ftp'd sass23.tar.Z from calvin.stanford.edu (I think) and
unpacked it. It wouldn't compile with gcc nor cc (SunOS 4.something),
nor would using bison instead of yacc or Gnu lex instead of /bin/lex
help. Inserting an "extern YYSTYPE yylval" into scan.c (the lexified
scan.l) made it pass.

   Later examining the code revealed that you have to specify -xc to
get a code object. You already know what -x by itself will give you.
:-)

And oh, there doesn't seem to be any provision for arithmetic, i.e.

	da	endpt-startpt

won't work. Another annoyance it that it blocks/hangs whenever an
error is encountered. Is this an old version? 

n233dk@tamuts.tamu.edu (Rick Grevelle) (09/05/90)

The ->SYS routine is obsolete.  It requires the code to be typed in backwards
and in increments of sixteen.  Eventhough I still use some of the SYSEVALs in
->SYS to "bootstrap" machine routines into programs, since the STRING->CODE
routine has been written there is little reason to use it.  

STRING->CODE takes a string of hex code as its argument and returns a Code
object.  There is no need to mess with calculating the length and replacing
the prolog as this is all done by the routine.

For example, the machine routine CHT can be converted from string to Code
simply by placing the string of hex code for that routine on the stack.

1: "143132169146132174E7143132144132142164808C"

Here is the routine that will create the STRING->CODE conversion program.

CS->C [7B4]

/<<
   /<< "" + A 
   />> 4
# 01DD641001231341h
# C4616316D241461Ah
# 731602F918631AD2h
# 1775A802A2C43901h
# 1810C1CD3317145Ch
# 30131DEE94113A41h
# 1476E90913504A6Bh
# E90513A6B0196015h
# 5DC0151A0AA03336h
# C434C1541704C1BAh
# 14133111154102DCh
# 1CD2113311110096h
# C80846124123101h
1 12 
  START # 5193h SYSEVAL
  NEXT # 2DCCh
# 5A03h SYSEVAL
# 5ACCh SYSEVAL
# 1D524h SYSEVAL
# 54AFh SYSEVAL
# 5445h SYSEVAL
/>>

It should also be noted that the CHT routine is obsolete.  The above program  
uses two SYSEVALs which perform the same task.  Here is the SYSEVAL equivalent.

CHT 

/<<
# 5A03h SYSEVAL
# 5ACCh SYSEVAL
/>>

If there are any questions about the applications of these programs, please ask.

Rick Grevelle