The Museum of HP Calculators

HP Forum Archive 15

[ Return to Index | Top of Index ]

HP-41 MCode question
Message #1 Posted by Jeff D on 2 Nov 2005, 1:17 p.m.

I have written the following sequece in MCode
1A0 A=B=C=0
355 ?NC XQ
050 ->14D5
0B8 READ 2(Y)
0AE A<>C ALL
0F8 READ 3(X)
30E ?A<C ALL
017 JC B09A +02
0AE A<>C ALL
070 N=C ALL
10E A=C ALL
135 ?NC XQ
060 ->184D
0E8 WRIT 3(X)
My intention is to find the largest value between the A and C registers and square the value then write it back to the user X register. Unfortunately, when I use a fractional number with no integer value, the program does not produce the correct value.
Any thoughts would be appreciated.
Thanks,
Jeff

      
Re: HP-41 MCode question
Message #2 Posted by Frank Wales on 2 Nov 2005, 4:20 p.m.,
in response to message #1 by Jeff D

(Well, it's been about half a billion seconds since I did any 41 machine code programming, but I think I see the problem...)

You need to perform a floating-point comparison between the two values; the ?A<C ALL is doing a 56-bit binary comparison between the normalized forms of the X and Y register values that you pulled into A and C, which won't work for the vast majority of possible values. (Remember, the X and Y registers can also contain alpha values, and could even include non-normalized values.) The Nut CPU basically hasn't a clue about floating-point operations -- the OS does all that. You need to call an appropriate subroutine in the 41 OS that performs something like the guts of the X<Y? user code instruction, and deal with its return value appropriately. I certainly don't know what that would be off the top of my head, but I suspect someone else might.

Hope that helps.

            
Re: HP-41 MCode question
Message #3 Posted by ECL on 4 Nov 2005, 10:44 p.m.,
in response to message #2 by Frank Wales

Frank,

So about 15 years?

:) ECL

                  
Re: HP-41 MCode question
Message #4 Posted by Frank Wales on 7 Nov 2005, 7:00 p.m.,
in response to message #3 by ECL

Yeah, about that -- I think I last wrote 41 machine code around about 1989 (and probably machine code of any kind around 1994). I just haven't had a reason to get that close to a machine since (and these days, the platforms I'm programming for are things like browsers, VMs and databases, where the 'machine' is abstracted away from the metal).

            
Re: HP-41 MCode question
Message #5 Posted by Jeff D on 9 Nov 2005, 7:15 p.m.,
in response to message #2 by Frank Wales

Thanks for the suggestions. I have tried to use the X<Y? with a X<>Y afterwords. This only yields "NO" whether the larger number is in the X or the Y registers. I understand that when executing these mcode routines from the keyboard will cause only "YES" or "NO" to be displayed, so I ran the routing from a user code program. This eliminated the "YES" or "NO" and left the numbers but still did not execute the X<>Y. I also tried the XX<Y? and still get similar results. My goal is to sort the higher number to a known register. The numbers will be integers with fractional portions.
Any suggestions would be great.
Thanks,
Jeff

                  
Re: HP-41 MCode question
Message #6 Posted by Doug on 13 Nov 2005, 3:40 a.m.,
in response to message #5 by Jeff D

To compare the size of two floating point numbers; subtract the two and check the sign of the result.

Best

      
Re: HP-41 MCode question
Message #7 Posted by Doug Wilder on 3 Nov 2005, 12:05 a.m.,
in response to message #1 by Jeff D

The way the mainframe tackles comparison is to subtract the two FPN's and then test the sign nibble. 1421 does an N=A-N with result also in C. 14D8: check C for Alpha Data Error. 14D5: check both A and C, ends with arguments reversed.

Best Regards

      
Re: HP-41 MCode question
Message #8 Posted by James F. Chumbley on 5 Nov 2005, 4:24 a.m.,
in response to message #1 by Jeff D

Can someone please tell me of any references that provide guidance and instruction on this topic? I've begun trying to learn the techniques of synthetic programming, but the references seem to be scattered, unfortunately. I have Jarett, and Wickes, and the PPC Journal on CD already. Are there any other major (or minor) references I should hunt for?

Thanks a lot, Jim Chumbley

            
Re: HP-41 MCode question
Message #9 Posted by Ángel Martin on 8 Nov 2005, 6:15 a.m.,
in response to message #8 by James F. Chumbley

Definitely get a copy of Ken Emery's "HP-41 MCODE for Beginners". Not sure if it's available on any CD-ROM or DVD set though!

Best, ÁM

                  
Re: HP-41 MCode question
Message #10 Posted by Meindert Kuipers on 8 Nov 2005, 7:11 a.m.,
in response to message #9 by Ángel Martin

Other musts for MCODE programmers: - David Assembler ROM (or image) with Labels and manual - HP41 NOMAS listing

These are all on the DVD of TOS

Meindert

                        
Re: HP-41 MCode question
Message #11 Posted by James F. Chumbley on 10 Nov 2005, 2:24 a.m.,
in response to message #10 by Meindert Kuipers

Meindert,

I don't understand the reference to the DVD by "TOS." Could you please tell me who "TOS" is?

Thanks, Jim Chumbley

                              
Re: HP-41 MCode question
Message #12 Posted by Massimo Gnerucci (Italy) on 10 Nov 2005, 8:12 a.m.,
in response to message #11 by James F. Chumbley

Once and for all (and without breaking any rules... I hope):

Google this and click the obvious.

Greetings,
Massimo

                              
Re: HP-41 MCode question
Message #13 Posted by Jeff O. on 10 Nov 2005, 8:24 a.m.,
in response to message #11 by James F. Chumbley

If you are interested in the background, check here.

                                    
Re: HP-41 MCode question
Message #14 Posted by Massimo Gnerucci (Italy) on 10 Nov 2005, 8:36 a.m.,
in response to message #13 by Jeff O.

Thanks Jeff, but I already know it very well.
I respect Dave's point of view (and I shall, too, since we are all his guests); but I think that a hint to newcomers or clueless people must be given since we are flooded by messages about TOS from time to time.
Rather than replay all the subsequent thread (and bandwidth waste) about why things are the way they are, wouldn't it be simpler to give them what they want? Indirectly maybe...

After all Warren's site is still alive and kickin' and easily found by search engines - if you know what to look for.

Greetings,
Massimo

                                          
Re: HP-41 MCode question
Message #15 Posted by Jeff O. on 10 Nov 2005, 1:01 p.m.,
in response to message #14 by Massimo Gnerucci (Italy)

Massimo,
My intention was to provide Mr. James F. Chumbley with additional information. Sorry for any confusion.
Best Regards.

                                                
Re: HP-41 MCode question
Message #16 Posted by Massimo Gnerucci (Italy) on 10 Nov 2005, 1:33 p.m.,
in response to message #15 by Jeff O.

Jeff,
please excuse my stepping on the pedestal... :-)

Massimo


[ Return to Index | Top of Index ]

Go back to the main exhibit hall