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
Post Reply 


Messages In This Thread
Base conversion for DM41X - Jeff_Birt - 10-21-2023 11:52 PM
RE: Base conversion for DM41X - Jeff_Birt - 10-22-2023, 03:33 PM
RE: Base conversion for DM41X - Jeff_Birt - 10-22-2023, 06:41 PM
RE: Base conversion for DM41X - Jeff_Birt - 10-23-2023, 01:05 PM
RE: Base conversion for DM41X - Jeff_Birt - 10-24-2023, 02:33 PM
RE: Base conversion for DM41X - Werner - 10-23-2023, 06:54 AM



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