Post Reply 
Base conversion for DM41X
10-21-2023, 11:52 PM
Post: #1
Base conversion for DM41X
This program uses the larger display of the DM41X combined with the PPC ROM's BD and TB functions to convert from binary, octal, decimal, or hex to all four and displays them all at once on the DM41X screen.

You need to remember which stack register is which base but they are arranged from top to bottom in ascending base order T=2, Z=8, Y=X=10, ALPHA=16. Since ALPHA covers X you see all four at once.

This has limitations of course but was a fun learning exercise. Any optimization suggestions welcome.


Code:

// Binary, Octal, Decimal, Hex conversion for DM41X
// Uses BD (Base B to Decimal) and TB (Decimal to Base B) from PPC ROM
// Makes use of larger display on DM41X to display all results at once
// 
// Assign USER key to each 'from' base. 
// To assign USER KB keys - [ASN] [ALPHA] "FUNCNAME" [ALPHA] KEY (or SHFT KEY)
// Use -> Enter value, press USER KB key, result displayed as shown below

//  BASE    STK     REG     KEY
//  Binary  T       02       B 
//  Octal   Z       01       O
//  Decimal Y       00       D 
//  Hex     -       ALPHA    H 

// Converts Binary to decimal
LBL "B2D"       ; Value should be in Alpha (KEY B)
2               ; Set base to 2
GTO 01          ; Convert

// Converts Octal to decimal
LBL "O2D"       ; Value should be in Alpha (KEY O)
8               ; Set base to 2
GTO 01          ; Convert

// Converts Hex to decimal
LBL "H2D"       ; Value should be in Alpha (KEY H)
16              ; Set base to 16

LBL 01          ; Converts to decimal -> X
STO 06          ;
XEQ "BD"        ; Leaves decimal value in X


// Convert Decimal value to all bases and display
LBL "D2A"       ; Value should be in X     (KEY D)
STO 00          ; Save decimal value

02              ; BINARY - 
STO 06          ; Set base to 2
RDN             ; Drop base value from stack             
XEQ "TB"        ; Decimal to base, result in Alpha
ANUM            ; Alpha -> Number in X 
STO 02          ; Save for later

RCL 00          ; OCTAL - Get decimal value
OCT             ; Decimal to Octal
STO 01          ; Save for later

16              ; HEX - 
STO 06          ; Set base to 16
RCL 00          ; Get decimal back      
XEQ "TB"        ; Decimal to base, result in Alpha, clears registers

FIX 0           ; Dont display fractional part
CF 29           ; Clear Flag 29, hide radix
RCL 02          ; Binary
RCL 01          ; Octal
RCL 00          ;
ENTER           ; Roll up
AVIEW           ; Show Hex value in Alpha (Hides X)
PSE             ;

RTN             ;
Find all posts by this user
Quote this message in a reply
10-22-2023, 01:54 PM
Post: #2
RE: Base conversion for DM41X
Interesting,
  • TB has a 14 digits accuracy and ANUM convert only the 10 leftmost digits, so binary results over 1023 will be inaccurate.
  • You could also use a single global label to activate the program and use local alpha labels (A..J, a..e) to call the conversion routines.
    FYI, if the key is unassigned, a local alpha label auto-assign itself to its key when the program is active.
  • You could also use ASTO X to store the HEX value string in X (6 chars maximum)

Sylvain Côté
Find all posts by this user
Quote this message in a reply
10-22-2023, 03:33 PM
Post: #3
RE: Base conversion for DM41X
(10-22-2023 01:54 PM)Sylvain Cote Wrote:  [*]You could also use a single global label to activate the program and use local alpha labels (A..J, a..e) to call the conversion routines. FYI, if the key is unassigned, a local alpha label auto-assign itself to its key when the program is active.

I'm not following what you are meaning here. Let's say for example I have a single global label of "MAIN" and four local labels of A,B,C,D. If keys A,B,C,D are not otherwise assigned in user KB then those keys will call the local labels? If multiple programs use the same A,B,C,D local labels how would the machine know which to auto-map to the keys?
Find all posts by this user
Quote this message in a reply
10-22-2023, 04:16 PM
Post: #4
RE: Base conversion for DM41X
(10-22-2023 03:33 PM)Jeff_Birt Wrote:  I'm not following what you are meaning here. Let's say for example I have a single global label of "MAIN" and four local labels of A,B,C,D. If keys A,B,C,D are not otherwise assigned in user KB then those keys will call the local labels? If multiple programs use the same A,B,C,D local labels how would the machine know which to auto-map to the keys?

It would probably be good for you and save much time if you would go on and read the Owner's Handbook, which explains everything in a simple yet complete manner and in fact it's quite an enjoyable, productive read.

The information you're asking about local alpha labels is perfectly explained in pages 188 and 189, so do yourself a favor and read it before asking here.

V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
10-22-2023, 06:41 PM
Post: #5
RE: Base conversion for DM41X
(10-22-2023 04:16 PM)Valentin Albillo Wrote:  It would probably be good for you and save much time if you would go on and read the Owner's Handbook, which explains everything in a simple yet complete manner and in fact it's quite an enjoyable, productive read.

The information you're asking about local alpha labels is perfectly explained in pages 188 and 189, so do yourself a favor and read it before asking here.

V.

I have read through all of Part I of the HP-41CX Owner's manual and am using Part II as a reference. Forgive me for not committing 400+ pages of technical documentation to memory in two weeks. If part of the purpose of a forum is not to ask questions than what is the point? Scolding someone who is new to a particular machine for asking a question is not particularly friendly nor constructive.

Looking at volume on of the HP-41CX User's manual this is found on page 88. From reading this I could not guess as this auto-assignment of A-F scheme.

"Local labels are not listed in catalog 1 and cannot be assigned to the User keyboard. This is because local labels are for strictly “local” use; they can only be used within the context of a single program."


Looking at the HP-41CX User's manual volume 2 on page 300 reveals this:

"Local Alpha labels require two bytes of program memory and can be used for branching any distance within a program. They are designed for manual execution: when the User keyboard is active, a local Alpha label is automatically assigned to each key on the top two rows (as described in “The Top Two Rows” in section 9). You can then use these keys to execute the corresponding local Alpha labels in the current program."

Then if you look up Section 9 it goes into more detail. To summarize while the HP-41C manual you linked to does mention this auto-assignment up front the HP141CX manual does not. In fact, the first mention of local labels in volume 1 would suggest the opposite to the new reader. One has to read three separate sections to get the full picture of this one feature.

To answer my own question about how the machine knows what program these top two rows of keys might be assigned to its scope is the 'current program'. If one has not executed the base conversion program, you would need to GTO to its global label to bring it into scope first. This is an interesting functionality and could be very handy for repetitive operations.
Find all posts by this user
Quote this message in a reply
10-22-2023, 07:41 PM (This post was last modified: 10-23-2023 12:39 PM by Sylvain Cote.)
Post: #6
RE: Base conversion for DM41X
The following non-optimized program works on all 41's (C, CV, CX, 41CL, DM41X, etc) and assumes that the top row key is unassigned.

Local alpha label demo program:
Code:
01 LBL "ALD"         // alpha label demo
02 SF 27             // activate user keyboard
03 LBL 00            // menu label
04 "A  B  C  D E"    // menu string
05 LBL 01            // display entry point (before alpha labels so next local alpha label execution is fast)
06 PROMPT            // display string and stop
07 GTO 00            // menu loop
08 LBL A             // local alpha label *** notice, there is no quotes surrounding local alpha label ***
09 "A KEY"           // key pressed string
10 GTO 01            // display label used
11 LBL B             // local alpha label
12 "B KEY"           // key pressed string
13 GTO 01            // display label used
14 LBL C             // local alpha label
15 "C KEY"           // key pressed string
16 GTO 01            // display label used
17 LBL D             // local alpha label
18 "D KEY"           // key pressed string
19 GTO 01            // display label used
20 LBL E             // local alpha label
21 "E KEY"           // key pressed string
22 GTO 01            // display label used
23 END               // program space separator

Usage:
Code:
[XEQ][ALPHA]ALD[ALPHA]    // display: "A  B  C  D E"
[R/S]                     // display: "A  B  C  D E"
[R/S]                     // display: "A  B  C  D E"
[A]                       // display: "A KEY"
[B]                       // display: "B KEY"
[C]                       // display: "C KEY"
[R/S]                     // display: "A  B  C  D E"
[D]                       // display: "D KEY"

Edit: available local alpha labels are:
Code:
LBL A
LBL B
LBL C
LBL D
LBL E

LBL F
LBL G
LBL H
LBL I
LBL J

LBL a    // [SHIFT][A]
LBL b    // [SHIFT][B]
LBL c    // [SHIFT][C]
LBL d    // [SHIFT][D]
LBL e    // [SHIFT][E]

Sylvain Côté
Find all posts by this user
Quote this message in a reply
10-22-2023, 11:32 PM
Post: #7
RE: Base conversion for DM41X
(10-22-2023 06:41 PM)Jeff_Birt Wrote:  I have read through all of Part I of the HP-41CX Owner's manual and am using Part II as a reference. Forgive me for not committing 400+ pages of technical documentation to memory in two weeks.

Forgiven, but those "400+ pages of technical documentation" you mention aren't meant to be memorized but consulted when necessary. In this particular case, simply look in the back cover of the HP-41CX Owner's Manual Volume 2: Operation in detail and you'll see there the line "20: Branching (page 298)". Looking in that page you'll quickly find at p.300 the following paragraph (my highlights):
    "Local Alpha Labels. Local Alpha labels require two bytes of program memory and can be used for branching any distance within a program. They are designed for manual execution: when the User keyboard is active, a local Alpha label is automatically assigned to each key on the top two rows (as described in “The Top Two Rows” in section 9). You can then use these keys to execute the corresponding local Alpha labels in the current program."
I found the above information in about one minute, and I didn't need to have the whole 400+ page manual memorized, I just consulted it. I see that eventually you found this paragraph too, so you see.

Quote:Scolding someone who is new to a particular machine for asking a question is not particularly friendly nor constructive.

Far from "scolding" you, I was trying to give you some allegedly useful advice, as I did here and here, but if you see my well-meant attempt here as "scolding", rest assured you'll get no further advice or suggestions from me in the future.

V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
10-23-2023, 06:54 AM
Post: #8
RE: Base conversion for DM41X
I would say that it is rather acceptable for someone to not be aware of or understand all the 41's gory details after only two weeks, even having read the manual cover-to-cover.
Do keep asking your questions here, Jeff. We are only too happy to show off our knowledge on the subject ;-)

Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
10-23-2023, 01:05 PM
Post: #9
RE: Base conversion for DM41X
(10-22-2023 11:32 PM)Valentin Albillo Wrote:  [/i], rest assured you'll get no further advice or suggestions from me in the future.
V.

Valentin, I do appreciate your helpfulness. In person it is easy for us to pick up on the speech pattern's someone uses, their expressions and body language to gauge the full meaning of their words. In a forum such as this we have only words; we miss out on all the other communication clues. Those to whom we are communicating in writing my not interpret our words as we intended.

Using reference material is great when are well versed in a subject but need to find some finer detail. If I am well versed in French for example, I can make good use of reference materials such as a dictionary, thesaurus, etc. Not having studied French for 35 years it is more of an effort for me. I can sometimes divine the meaning of a sentence. I can sometimes use Google translate, but sometimes there is no substitute for asking a native speaker. Someone fluent in the language can quickly find a reference to correct grammar usage, or a colloquial expression that a student will struggle with.

In fact, your link to the HP-41C manual and my looking up the same information in the HP-41CX manuals led me to a bit of information that related to something I heard at one of the HHC presentations that was tangentially related.
Find all posts by this user
Quote this message in a reply
10-23-2023, 06:13 PM
Post: #10
RE: Base conversion for DM41X
(10-23-2023 01:05 PM)Jeff_Birt Wrote:  Valentin, I do appreciate your helpfulness. [...]

Good. I do appreciate your appreciation. Let bygones be bygones.

Regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
10-24-2023, 02:33 PM
Post: #11
RE: Base conversion for DM41X
(10-22-2023 07:41 PM)Sylvain Cote Wrote:  The following non-optimized program works on all 41's (C, CV, CX, 41CL, DM41X, etc) and assumes that the top row key is unassigned.

Thanks Sylvain, this was helpful.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)