From: bson@gnu.ai.mit.edu (Jan Brittenson)
Newsgroups: comp.sys.hp48
Subject: Re: <--- need to know basics of machine code progr.
Date: 17 Dec 92 05:44:16
Organization: nil
NNTP-Posting-Host: churchy.gnu.ai.mit.edu
In-reply-to: snill@dhhalden.no's message of 16 Dec 92 19:20:34 GMT

In article <snill.4.724533634@dhhalden.no> snill@dhhalden.no (Tor Atle Lunde) writes:

 > I have now had the hp48 for a while and i was thinking of moving on to
 > the assembly programming area.  Since i've had a Commodore 64 (i still
 > like it a LOT), i am familiar with 6502 (hmmmm) prosessor machine
 > code.  ... I'll most likely need a PC, but is there [a cross assembler for]
 > amiga ???

   There are in fact a bunch of HP-48 assemblers. The two formats used
are HP's and Alonzo Gariepy's. HP's look like nothing else I've ever
seen, whereas AG's look like most other assemblers. The difference can
be illustrated with the following example.

In HP syntax, you'd write:

		A=B A

Whereas in AG syntax you'd write:

		move.a	b, a

(I.e. op.f src, dst)

   HP's assembler's grammar also isn't context-free. This means that
the syntax varies depending on the meaning. For instance, a dash
(``-'') is a valid symbol character (otherwise they wouldn't be able
to create symbols such as ``A=B'' above) if the parser is currently
scanning a symbol name; if it's scanning on the expression level it
means subtraction. In other grammatical contexts it may mean other
things, although I'm not sure whether it actually does. You get the
hint: context-dependent grammars are a bitch to learn. Most research
in this area in the late 60's singularly concluded that context-free
grammars are easier to learn and use -- today virtually no grammars
are context- dependent, and most parser generator tools (such as
``yacc'') are mostly optimized for context-free grammars, and require
extensive workarounds otherwise. This is usually a point left ignored
when people engage in discussions over the respective merits of the
different syntaxes, which is why I elaborate like this.

   The second big issue is error diagnostics. A tool that can produce
correct output for correct input is fine and useful, but the true
litmus of excellence is how the tool tells you it got junk at the
input. Suppose you write the following in HP syntax:

		D=A A

   Now, you can't load register D directly from register A. In the
worst case, the assembler will print ``syntax error'' (we all know
which junky Basic that helped make a famous man rich used to have
tendencies in this direction). A slightly better assembler will print
``unrecognized symbol.'' An even better one will recognize that it's
an instruction, and print ``unrecognized instruction.'' The best one
can hope for is an assembler that has a symbol table that is huge
enough to include all invalid combinations.

If, instead, you write:

		move.a	d, a

An assembler such as STAR, will print:

	"foo.star", line 1: Inconsistent arguments for MOVE

   Now, there is a bunch of assemblers. HP has a non-supported set of
tools that include more than just an assembler (which is its most
redeeming feature), which runs on IBM PC compatibles under MS-DOS.
There are several assemblers for AG syntax, including SASS, STAR, and
a few others I can't seem to recall the name of right now. SASS is
very very slow, since it's written as a perl script. STAR's most
redeeming features are cross-platform compatibility; it currently runs
on most Unixes, MS-DOS, VAX/VMS, AmigaDOS, Atari, and in a very
limited form on Macintosh, as well as its comprehensive macro
capabilities (although with dynamic scoping). It has a few bugs
though. Rumours abound about a version 2 real soon now. :-)


 >   1)	Does one have the same access to each address in the RAM on the hp 
 >	   as on the old 64 ????

   Yes, the HP-48 has a linear address space (unlike the HP-41). The
HP-48 even has a memory map, of sorts.


 >   2)	What compiling-programs does one usually use, and where can i get 
 >	   it ???

   If you have access to FTP, look in pub/star-1.04.4.tar.Z on
ftp.ai.mit.edu. The HP kit can be found on wuarchive.wustl.edu.

   If you're a hardcore assembler programmer, I would definitely
recommend STAR (it's loosely modeled after DEC's Macro-10 and Macro-11
assemblers); you'll probably find it similar to most other assemblers
you have used. Use the HP kit if you plan to write System RPL
programs; I never write System RPL code, except to launch Code objects
(objects consisting of machine code).

   For debugging, you probably want to get the MLDL, it contains a
disassembler and a debugger. It will let you step and examine code
from the HP-48 keyboard, or from over the serial port using a terminal
program on your Amiga (useful for games and other programs that like
to have the display and keyboard to themselves). Get this, too, from
wuarchive.wustl.edu. The latest version is 1.06. The same archive will
also have a lot of documentation on machine code. Reading through the
documentation that comes with HP's kit may also prove meaningful.

Happy hacking!

						-- Jan Brittenson
						   bson@gnu.ai.mit.edu
--
						-- Jan Brittenson
						   bson@gnu.ai.mit.edu