HP-41 MCode question



#17

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


#18

(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.


#19

Frank,

So about 15 years?

:)
ECL


#20

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).

#21

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


#22

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

Best

#23

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

#24

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


#25

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


#26

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


#27

Meindert,

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

Thanks,
Jim Chumbley


#28

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

Google this and click the obvious.

Greetings,
Massimo

#29

If you are interested in the background, check here.


#30

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


#31

Massimo,

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

Best Regards.


#32

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

Massimo


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP-41(CL): The easiest way to transfer FOCAL programs from a Linux PC to the HP-41 Geir Isene 13 939 12-05-2013, 02:40 AM
Last Post: Hans Brueggemann
  HP-41 MCODE: The Last Function - at last! Ángel Martin 0 198 11-08-2013, 05:11 AM
Last Post: Ángel Martin
  Non-Prime question alert: Hp-41 and synthetic instructions Marcel Samek 11 724 11-04-2013, 09:31 PM
Last Post: sjthomas
  41-MCODE: Auto XEQ+ALPHA possible? Ángel Martin 5 382 05-29-2013, 06:15 AM
Last Post: Ángel Martin
  HP 41 Mcode related Questions Michael Fehlhammer 4 325 05-10-2013, 07:09 PM
Last Post: Michael Fehlhammer
  41-MCODE: Breaking the FAT barrier. Ángel Martin 0 157 09-03-2012, 06:31 AM
Last Post: Ángel Martin
  41-MCODE: Dr. Jekyll & Mr. Hyde Ángel Martin 9 535 07-09-2012, 09:41 AM
Last Post: Monte Dalrymple
  hp 41 series wire-wrapped connector question. Matt Kernal 3 254 06-19-2012, 01:48 AM
Last Post: Luiz C. Vieira (Brazil)
  HP41C: Factorial (kind of) in MCODE Frido Bohn 7 455 05-26-2012, 09:18 AM
Last Post: Frido Bohn
  41-MCODE: SOLVE & INTEG - 4k ROM Ángel Martin 9 523 04-19-2012, 05:29 AM
Last Post: fhub

Forum Jump: