HP-41CX MCODE Stack Functions
#1

I recently began working with MCODE programming on the HP-
41CX. With the advent of the new devices MLDL2000 and NoVram,
using the David Assembler with Mainframe Labels has become quite
easy. Over the years I have programmed some RPL on the HP-
49G. But now getting back to the HP-41CX I decided to add some
MCODE routines to add the Stack manipulation routines of the HP-
49G. I don’t want to upset the pure HP-41 enthusiasts by doing
this, I just wanted to add a modern touch to help extend the
life of the HP-41CX calculator. Although there is no “Rocket
Science” to these functions, It has been an interesting way
to begin my MCODE programming experience. Below is a listing
of the functions I have made. I encourage any and all
comments as there are always several ways to “Skin the Cat”. I
hope you find this article as interesting as I found it to
develop. You can e-mail me at thecoltsman2006@yahoo.com with any
suggestions to make these routines more efficient.
FUNCTION    00C4 ... ... ... "DUP"
F 00C4 3B5 050 ... ?NC XQ 14ED
F 00C6 0F8 ... ... READ ( 3)X
F 00C7 128 ... ... WRIT ( 4)L
F 00C8 3A5 050 ... ?NC XQ 14E9
F 00CA 078 ... ... READ ( 1)Z
F 00CB 028 ... ... WRIT ( 0)T
F 00CC 0B8 ... ... READ ( 2)Y
F 00CD 068 ... ... WRIT ( 1)Z
F 00CE 0F8 ... ... READ ( 3)X
F 00CF 0A8 ... ... WRIT ( 2)Y
F 00D0 3E0 ... ... RTN
Yes, ENTER does the same thing. Lines 00C4-00C8 can be eliminated if T is not saved to the LASTX register.

FUNCTION 00D5 ... ... ... "SWAP"
F 00D5 0F8 ... ... READ ( 3)X
F 00D6 10E ... ... A=C ALL
F 00D7 0B8 ... ... READ ( 2)Y
F 00D8 0E8 ... ... WRIT ( 3)X
F 00D9 0AE ... ... A<>C ALL
F 00DA 0A8 ... ... WRIT ( 2)Y
F 00DB 048 ... ... SETF 4
F 00DC 3E0 ... ... RTN
Yes, X<>Y does the same thing.

FUNCTION 00E1 ... ... ... "DROP"
F 00E1 0F8 ... ... READ ( 3)X
F 00E2 128 ... ... WRIT ( 4)L
F 00E3 3B5 050 ... ?NC XQ 14ED
F 00E5 04E ... ... C=0 ALL
F 00E6 0A8 ... ... WRIT ( 2)Y
F 00E7 3A5 050 ... ?NC XQ 14E9
F 00E9 3A5 050 ... ?NC XQ 14E9
F 00EB 3E0 ... ... RTN


FUNCTION 00F0 ... ... ... "OVER"
F 00F0 3B5 050 ... ?NC XQ 14ED
F 00F2 0F8 ... ... READ ( 3)X
F 00F3 128 ... ... WRIT ( 4)L
F 00F4 078 ... ... READ ( 1)Z
F 00F5 0E8 ... ... WRIT ( 3)X
F 00F6 3E0 ... ... RTN


FUNCTION 00FA ... ... ... "ROT"
F 00FA 078 ... ... READ ( 1)Z
F 00FB 0AE ... ... A<>C ALL
F 00FC 0B8 ... ... READ ( 2)Y
F 00FD 068 ... ... WRIT ( 1)Z
F 00FE 0F8 ... ... READ ( 3)X
F 00FF 0A8 ... ... WRIT ( 2)Y
F 0100 0AE ... ... A<>C ALL
F 0101 0E8 ... ... WRIT ( 3)X
F 0102 3E0 ... ... RTN


FUNCTION 0108 ... ... ... "UNROT"
F 0108 078 ... ... READ ( 1)Z
F 0109 0F8 ... ... READ ( 3)X
F 010A 0AE ... ... A<>C ALL
F 010B 078 ... ... READ ( 1)Z
F 010C 0AE ... ... A<>C ALL
F 010D 068 ... ... WRIT ( 1)Z
F 010E 0B8 ... ... READ ( 2)Y
F 010F 0E8 ... ... WRIT ( 3)X
F 0110 0AE ... ... A<>C ALL
F 0111 0A8 ... ... WRIT ( 2)Y
F 0112 3E0 ... ... RTN


FUNCTION 0117 ... ... ... "DUP2"
F 0117 0F8 ... ... READ ( 3)X
F 0118 068 ... ... WRIT ( 1)Z
F 0119 0B8 ... ... READ ( 2)Y
F 011A 028 ... ... WRIT ( 0)T
F 011B 3E0 ... ... RTN


FUNCTION 0122 ... ... ... "DUPDUP"
F 0122 0B8 ... ... READ ( 2)Y
F 0123 028 ... ... WRIT ( 0)T
F 0124 0F8 ... ... READ ( 3)X
F 0125 0A8 ... ... WRIT ( 2)Y
F 0126 068 ... ... WRIT ( 1)Z
F 0127 3E0 ... ... RTN


FUNCTION 012D ... ... ... "DROP2"
F 012D 04E ... ... C=0 ALL
F 012E 0E8 ... ... WRIT ( 3)X
F 012F 0A8 ... ... WRIT ( 2)Y
F 0130 3A5 050 ... ?NC XQ 14E9
F 0132 3A5 050 ... ?NC XQ 14E9
F 0134 3E0 ... ... RTN


FUNCTION 0138 ... ... ... "NIP"
F 0138 0F8 ... ... READ ( 3)X
F 0139 0A8 ... ... WRIT ( 2)Y
F 013A 3A5 050 ... ?NC XQ 14E9
F 013C 04E ... ... C=0 ALL
F 013D 028 ... ... WRIT ( 0)T
F 013E 3E0 ... ... RTN

FUNCTION 0110 ... ... ... "ROLLD"
F 0110 3A5 050 ... ?NC XQ 14E9
F 0112 3E0 ... ... RTN


FUNCTION 0119 ... ... ... "ROLLD2"
F 0119 3A5 050 ... ?NC XQ 14E9
F 011B 3A5 050 ... ?NC XQ 14E9
F 011D 3E0 ... ... RTN


FUNCTION 0124 ... ... ... "ROLLD3"
F 0124 3A5 050 ... ?NC XQ 14E9
F 0126 3A5 050 ... ?NC XQ 14E9
F 0128 3A5 050 ... ?NC XQ 14E9
F 012A 3E0 ... ... RTN


FUNCTION 013B ... ... ... "PICK3"
F 013B 078 ... ... READ ( 1)Z
F 013C 028 ... ... WRIT ( 0)T
F 013D 3B5 050 ... ?NC XQ 14ED
F 013F 3E0 ... ... RTN


FUNCTION 0145 ... ... ... "PICK4"
F 0145 3B5 050 ... ?NC XQ 14ED
F 0147 3E0 ... ... RTN



Edited: 21 Feb 2008, 5:34 p.m. after one or more responses were posted

#2

Hi,

looks nice:-)

If you want something similar to the RPL functions,

have you considered taking a look at the FORTH ROM for the HP-41 ?

(Should be on Warren's site)

Raymond

#3

Good to see some HP41 mcode again here!

The stack manipulation commands are a good exercise to start in mcode. Keep watching for the new release of the MLDL2000 manager. I was in a software mood last weekend and improved the HP41 disassembler with the mainframe labels and some other goodies. Need to do a bit more work and fix a few bugs before the final release!

In your SWAP function you set flag 4, wasn't that for the stack lift enable/disable? Why are you not using this in any of the other functions?

BTW. Implementing the system labels was easy for some of the obvious entry points, since these are available in digital format in various sources (V41 for example). If there are users on the forum who have the complete set of (local) labels for all HP41 system modules (Printer, XFUN, IL, TIMER, etc) in a digital format this would be very helpful ...

Meindert

#4

I don't know anything about MCODE, but I'm curious about some of your "new" (not available as 49 series UserRPL commands) stack manipulations.

What's the functional difference between OVER and PICK2? Or between UNROT and ROLLD3?

Regards,
James

#5

It would be good to se a list of top mainframe entry points (as going through the VASM listings is an interesting but looong exercise). Any takes for the most important entry points?

#6

I think the most important MF entries are in the MF Labels ROM already.

There might be missing some important ones, but as Mr. Bill Wickes said in another context: 'Life is short and ROM is full' .

AFAIK the general Labels ROM format is documented, so you (we?) could make an additional Labels ROM, maybe for the HP-IL peripherals.

Raymond

#7

I have not seen the format for labels in the Label ROM anywhere, so any pointers for this would be very helpful.

I do have a list of the most important entry points (everything which is in the David Assembler) plus a few more from sources of V41 and D41 and some other programs, but this is only the label and address, never a description. If someone wants these files, just send me an email ....

And my VASM listing is only printed. I have tried to scan a few pages and feed it through an OCR program, but the quality is too poor for succes.

Apart from what is described in the obvious books I think we really need to depend on what is in the VASM listings ....

Meindert

#8

I knew I had it somewhere ... and I found it: a list (in alphabetical order and in address order) of the HP41 system labels with some comments. This is simply at the end of (my copy) of the VASM listings. It certainly is not part of the official VASM listing, since it is not present in the files of the DVD's that are available.

The labels consist of a comment and address as follows (example):

output ALPHA register to display 310 12 20 2C10 ARGOUT

The 310 12 20 refers to the location in the VASM listing: 320 is the page number in the VASM listing, 12 being the 12th 1K in the HP41 system ROM, 20 the address (octal of course) of the entry. Since there is a hex address, I assume that it has another source. Anyone has the real digital source?

Meindert

#9

James,
You are correct. The Over and the Pick2 routines do exactly the same thing. I will eliminate the pick2 from my routine list. The UNROT and the ROLLD3 are a little different.
X: 1
Y: 2
Z: 3
T: 4
UNROT
X: 2
Y: 3
Z: 1
T: 4

My current ROLLD3 routine is wrong after I reviewed the 49G function. The 49G only rolls the X,Y,Z registers. Mine rolls the entire stack. If I do it the correct method you are correct, the two functions UNROT and ROLLD3 are the same.
Thanks for picking that up.
I will also eliminate the ROLLD3 function and possibly the other ROLLD functions also.
Jeff

#10

For what it's worth, here are stack diagrams for what I'd suggest
for some possible added stack manipulation routines for 4-register
fixed-stack models:

DROP

T:4 -> T:4
Z:3 Z:4
Y:2 Y:3
X:1 X:2


DROP2

T:4 -> T:4
Z:3 Z:4
Y:2 Y:4
X:1 X:3


DROP3

T:4 -> T:4
Z:3 Z:4
Y:2 Y:4
X:1 X:4


SWAP (or ROLL2 or ROLLD2)

T:4 -> T:4
Z:3 Z:3
Y:2 Y:1
X:1 X:2


ROT (or ROLL3)

T:4 -> T:4
Z:3 Z:2
Y:2 Y:1
X:1 X:3


UNROT (or ROLLD3)

T:4 -> T:4
Z:3 Z:1
Y:2 Y:3
X:1 X:2


ROLL4

T:4 -> T:3
Z:3 Z:2
Y:2 Y:1
X:1 X:4


ROLLD4

T:4 -> T:1
Z:3 Z:4
Y:2 Y:3
X:1 X:2


DUP (or PICK1)

T:4 -> T:3
Z:3 Z:2
Y:2 Y:1
X:1 X:1


OVER (or PICK2)

T:4 -> T:3
Z:3 Z:2
Y:2 Y:1
X:1 X:2


PICK3

T:4 -> T:3
Z:3 Z:2
Y:2 Y:1
X:1 X:3


PICK4

T:4 -> T:3
Z:3 Z:2
Y:2 Y:1
X:1 X:4


UNPICK2

T:4 -> T:4
Z:3 Z:3
Y:2 Y:1
X:1 X:1


UNPICK3

T:4 -> T:4
Z:3 Z:1
Y:2 Y:2
X:1 X:1


UNPICK4

T:4 -> T:1
Z:3 Z:3
Y:2 Y:2
X:1 X:1


DUP2

T:4 -> T:2
Z:3 Z:1
Y:2 Y:2
X:1 X:1


DUPDUP

T:4 -> T:2
Z:3 Z:1
Y:2 Y:1
X:1 X:1

Which ones would be useful enough to bother implementing, I don't
know. And of course naming conventions could be different; for
example, 4RD instead of ROLLD4.

It does seem to make some sense for ROT and UNROT to roll the
entire stack up or down (like ROLL4 and ROLLD4 above), but I think
that that would be confusing for anyone accustomed to RPL models
as well.

My UNPICK commands differ from the RPL UNPICK, which is a
2-argument command. For example, the UNPICK4 above would
accomplish the same as the RPL sequence DUP 4 UNPICK. Basically,
they copy the X register to another register without disturbing
the other registers.

Regards,
James

#11

I was more looking at for a top 20 list of MF entry points, or a bigger list if it is well categorized (error messages, stack manipulations, math functions, programming tools etc.)

#12

Hi Meindert,

the DA manual describes most parts in principle,

like how you can access the Label ROM including I/O and data formats,

and which conditions have to be met to add another Label ROM to the search chain.

See the DA manual from page 41 (intentionally:-) on...

Regards

Raymond

#13

James,
Thanks for the advice. I have modified the routines and they are posted below. Thanks for your assistance with the stack diagrams.
Thanks
Jeff

FUNCTION    008C ... ... ... "DAVIS 1A"
F 008C 3E0 ... ... RTN
FUNCTION 0090 ... ... ... "DUP"
F 0090 3B5 050 ... ?NC XQ 14ED
F 0092 0B8 ... ... READ ( 2)Y
F 0093 0E8 ... ... WRIT ( 3)X
F 0094 3E0 ... ... RTN
FUNCTION 0099 ... ... ... "SWAP"
F 0099 0F8 ... ... READ ( 3)X
F 009A 10E ... ... A=C ALL
F 009B 0B8 ... ... READ ( 2)Y
F 009C 0E8 ... ... WRIT ( 3)X
F 009D 0AE ... ... A<>C ALL
F 009E 0A8 ... ... WRIT ( 2)Y
F 009F 3E0 ... ... RTN
FUNCTION 00A4 ... ... ... "DROP"
F 00A4 3A5 050 ... ?NC XQ 14E9
F 00A6 078 ... ... READ ( 1)Z
F 00A7 028 ... ... WRIT ( 0)T
F 00A8 3E0 ... ... RTN
FUNCTION 00AD ... ... ... "OVER"
F 00AD 3B5 050 ... ?NC XQ 14ED
F 00AF 078 ... ... READ ( 1)Z
F 00B0 0E8 ... ... WRIT ( 3)X
F 00B1 3E0 ... ... RTN
FUNCTION 00B5 ... ... ... "ROT"
F 00B5 078 ... ... READ ( 1)Z
F 00B6 0AE ... ... A<>C ALL
F 00B7 0B8 ... ... READ ( 2)Y
F 00B8 068 ... ... WRIT ( 1)Z
F 00B9 0F8 ... ... READ ( 3)X
F 00BA 0A8 ... ... WRIT ( 2)Y
F 00BB 0AE ... ... A<>C ALL
F 00BC 0E8 ... ... WRIT ( 3)X
F 00BD 3E0 ... ... RTN
FUNCTION 00C3 ... ... ... "UNROT"
F 00C3 078 ... ... READ ( 1)Z
F 00C4 078 ... ... READ ( 1)Z
F 00C5 0AE ... ... A<>C ALL
F 00C6 0F8 ... ... READ ( 3)X
F 00C7 068 ... ... WRIT ( 1)Z
F 00C8 0B8 ... ... READ ( 2)Y
F 00C9 0E8 ... ... WRIT ( 3)X
F 00CA 0AE ... ... A<>C ALL
F 00CB 0A8 ... ... WRIT ( 2)Y
F 00CC 3E0 ... ... RTN
FUNCTION 00D1 ... ... ... "DUP2"
F 00D1 0F8 ... ... READ ( 3)X
F 00D2 068 ... ... WRIT ( 1)Z
F 00D3 0B8 ... ... READ ( 2)Y
F 00D4 028 ... ... WRIT ( 0)T
F 00D5 3E0 ... ... RTN
FUNCTION 00DC ... ... ... "DUPDUP"
F 00DC 0B8 ... ... READ ( 2)Y
F 00DD 028 ... ... WRIT ( 0)T
F 00DE 0F8 ... ... READ ( 3)X
F 00DF 0A8 ... ... WRIT ( 2)Y
F 00E0 068 ... ... WRIT ( 1)Z
F 00E1 3E0 ... ... RTN
FUNCTION 00E7 ... ... ... "DROP2"
F 00E7 3A5 050 ... ?NC XQ 14E9
F 00E9 3A5 050 ... ?NC XQ 14E9
F 00EB 0B8 ... ... READ ( 2)Y
F 00EC 068 ... ... WRIT ( 1)Z
F 00ED 028 ... ... WRIT ( 0)T
F 00EE 3E0 ... ... RTN
FUNCTION 00F2 ... ... ... "NIP"
F 00F2 0F8 ... ... READ ( 3)X
F 00F3 0A8 ... ... WRIT ( 2)Y
F 00F4 3A5 050 ... ?NC XQ 14E9
F 00F6 078 ... ... READ ( 1)Z
F 00F7 028 ... ... WRIT ( 0)T
F 00F8 3E0 ... ... RTN
FUNCTION 00FC ... ... ... "RD4"
F 00FC 3A5 050 ... ?NC XQ 14E9
F 00FE 3E0 ... ... RTN
FUNCTION 0104 ... ... ... "DROP3"
F 0104 3B5 050 ... ?NC XQ 14ED
F 0106 0F8 ... ... READ ( 3)X
F 0107 0A8 ... ... WRIT ( 2)Y
F 0108 068 ... ... WRIT ( 1)Z
F 0109 028 ... ... WRIT ( 0)T
F 010A 3E0 ... ... RTN
FUNCTION 0110 ... ... ... "ROLL4"
F 0110 3B5 050 ... ?NC XQ 14ED
F 0112 3E0 ... ... RTN
FUNCTION 0118 ... ... ... "PICK3"
F 0118 078 ... ... READ ( 1)Z
F 0119 028 ... ... WRIT ( 0)T
F 011A 3B5 050 ... ?NC XQ 14ED
F 011C 3E0 ... ... RTN
FUNCTION 0122 ... ... ... "PICK4"
F 0122 3B5 050 ... ?NC XQ 14ED
F 0124 3E0 ... ... RTN
FUNCTION 012C ... ... ... "UNPICK2"
F 012C 0F8 ... ... READ ( 3)X
F 012D 0A8 ... ... WRIT ( 2)Y
F 012E 3E0 ... ... RTN
FUNCTION 0136 ... ... ... "UNPICK3"
F 0136 0F8 ... ... READ ( 3)X
F 0137 068 ... ... WRIT ( 1)Z
F 0138 3E0 ... ... RTN
FUNCTION 0140 ... ... ... "UNPICK4"
F 0140 0F8 ... ... READ ( 3)X
F 0141 028 ... ... WRIT ( 0)T
F 0142 3E0 ... ... RTN


Edited: 24 Feb 2008, 4:07 p.m.



Possibly Related Threads...
Thread Author Replies Views Last Post
  HP 50g - select characters on the stack, copy/paste Sean Freeman 7 978 11-20-2013, 07:11 AM
Last Post: Sean Freeman
  Prime: Placing more than 1 item on the RPN stack in a single program? John Colvin 4 733 11-19-2013, 08:59 AM
Last Post: Miguel Toro
  emu48 - copy stack doesn't work (as expected) Thomas Radtke 2 738 11-11-2013, 02:19 PM
Last Post: Thomas Radtke
  HP Prime - CAS functions in Spreadsheet App CR Haeger 6 944 11-11-2013, 12:37 AM
Last Post: Michael de Estrada
  HP Prime Stack operations from within a program John Colvin 1 516 11-08-2013, 09:45 PM
Last Post: Helge Gabert
  [41CL] New Extra Functions version Monte Dalrymple 0 406 11-08-2013, 04:32 PM
Last Post: Monte Dalrymple
  HP-41 MCODE: The Last Function - at last! Ángel Martin 0 384 11-08-2013, 05:11 AM
Last Post: Ángel Martin
  HP Prime: in need of help with defining functions Alberto Candel 14 1,564 10-27-2013, 10:48 AM
Last Post: Alberto Candel
  Prime: Anyway to refresh stack? kris223 5 744 10-16-2013, 05:09 PM
Last Post: kris223
  hp prime - sending program results to the stack giancarlo 6 832 10-15-2013, 02:00 AM
Last Post: Giancarlo

Forum Jump: