The Museum of HP Calculators

HP Forum Archive 01

[ Return to Index | Top of Index ]

HP41 Program "Decompiler"
Message #1 Posted by Dan McDonald on 24 June 1999, 8:24 p.m.

HP41C code "Decompiler"

I've just spent a bunch of time writing a code "decompiler" for HP-41 programs that runs on the PC. This code will take 41C/V/X binary program files and print out a HP41 program listing. Probably somebody has done this in the past, but I found it a good way to learn both some 41C internal workings and some mainstream software.

This "decompiler" assumes that the binary program resides in a DOS file somewhere. How'd it get there? Well, from the HP-IL, either via the 82973 Interface Board, or the 9114 disk drive. There are plenty of these files available on the ftp server ( )

While this may not seem useful to anybody but me :-), I'm finding it a helpful tool to figure out what all those files I got from the ftp archive might do. If anybody else might find such a tool useful, we can discuss it here or via email.

I have another, simpler program that will lop off the extraneous header info in the DOS/LIF file (if it was created by the HP82973 board - all the ones on the ftp archive site were) while remembering the important pieces. This allows those (like me) who don't have the interface board but DO have a disk drive to easily send these files to the HP41 (or 71 or 75...)and have them work as programs (or lex files or whatever).

My code is written in "MS Visual Basic" to run within "MS Excel," but I'm sure it could be made to work in other environments. I just went with what was available to me. Discussions of evil empires and world domination through proliferation of mundane software should be taken somewhere else....

Advantages of my decompiler code:

Will take a binary 41 program file in DOS and create a correct DOS text HP41 program listing. This is much faster (and sometimes handier) than using the HP-41 itself to drive other printers.


You've got to have a way to get the file from the HP-41 to DOS. This means extra hardware - HP-IL and a 9114 disk drive or the 82973 interface board, or some other creative interface.

Right now, it will print out only the XROM numbers (XROM xx, yy) but doesn't tell you what the program is. It is easy to ID the module numbers (xx), but I don't have a Synthetic Quick Reference Guide (Jeremy Smith) to get to the detail of all the program numbers (yy). I do have a moderate supply of modules that I will use to automatically add their correct info to the printouts as time allows, but it is far from complete.

Doesn't print out all printable or displayable characters. Easy enough to insert the byte hex value on the printout, or whatever else would make it useful. Synthetic text strings are the worst, but that's pretty much the case for all program listings I've seen so far.

It's not yet the user-friendliest, but there's always room for improvement, isn't there? I won't have a lot of time to dedicate to this project for some time to come, so I thought I'd take a pause for now and see what happens.

Re: HP41 Program "Decompiler"
Message #2 Posted by Steve on 25 June 1999, 8:31 p.m.,
in response to message #1 by Dan McDonald

I have been working on and off on code that also does this.

The major problems for me are the common characters used by the HP41 that have no obvious replacements in normal characters.

I refer to the append character, and sigma. The append character is probably the worst as it appears frequently enough in normal (i.e. non-synthetic) programs. In addition it has a rather specific symbolic meaning that is not made any clearer by printing the value in hex.

One of the problms you'll find with converting XROM codes to mnemonics is that several modules use the same XROM codes.

Re: HP41 Program "Decompiler"
Message #3 Posted by Dan McDonald on 28 June 1999, 3:16 p.m.,
in response to message #2 by Steve

Steve raises some very good points about printing a program listing:

1. How to print out 'append' and 'sigma', very common yet important characters, or other special characters. 2. Multiple modules with the same XROM number.

Luckily(?) for me, my listings are concatenations of strings from "MS Excel" worksheet cells. As such, I can put anything of any length in the appropriate master lookup cell. So, for problem #1, and a step of ("append-character" =) my listing might show

104 "'app'="

just like that. Sure 'app' is not as concise as the real thing, but it's enough to let me know what it is. Similar adjustments can be made for all the other non-displayable characters.

For problem #2, I envision that I can leave the XROM xx, yy as it is, but print out a list of all the possible XROM functions (ModName:CommName) it could be to the right of the program line on the 8.5x11 (or A4!) paper. I see a max of 3 possible duplicate XROM functions - plenty of space for that - then the reader of the listing can decide by context what the command should be. Maybe not too elegant, but I can think of a lot worse!


Re: HP41 Program "Decompiler"
Message #4 Posted by Mike on 29 June 1999, 4:45 p.m.,
in response to message #3 by Dan McDonald

How about a tilde (~) for the append character. It's not used very often, and a text line in a listing like


is clearly ment to be appendet. Isn't it?


[ Return to Index | Top of Index ]

Go back to the main exhibit hall