hp41programs

Roman Roman Numerals for the HP-41

Overview

-Roman numerals use the following equivalences:                       M = 1000 ; D = 500 ; C = 100 ; L = 50 ; X = 10 ; V = 5 ; I = 1
-These letters are sorted in decreasing order
and the numerical values are added, for instance:                       MCCXV = 1000 + 100 + 100 + 10 + 5 = 1215
-However, if a smaller numeral appears before a larger one,
it must be subtracted instead of added, for example:                 XC = -10 + 100 = 90   ;    MCMXLIV =  1000 - 100 + 1000 - 10 + 50 - 1 + 5 = 1944
-These 2 rules are used in the following conversion programs.

1°)  Arabic Numerals  >>>  Roman Numerals

Data Registers: /
Flags: /
Subroutines: /

 01  LBL "A-R" 02  " "       03  LBL 01 04   E3 05  X>Y? 06  GTO 00 07  - 08  >"M"    09  GTO 01 10  LBL 00           11  CLX 12  900 13  X<=Y? 14  >"CM" 15  X>Y? 16  CLX 17  - 18  500 19  X<=Y?      20  >"D"    21  X>Y? 22  CLX 23  - 24  400 25  X<=Y? 26  >"CD"    27  X>Y? 28  CLX 29  - 30  LBL 02           31   E2 32  X>Y? 33  GTO 00     34  - 35  >"C"    36  GTO 02 37  LBL 00           38  CLX      39  90 40  X<=Y? 41  >"XC" 42  X>Y? 43  CLX 44  - 45  50 46  X<=Y? 47  >"L"    48  X>Y? 49  CLX 50  - 51  40 52  X<=Y? 53  >"XL"   54  X>Y? 55  CLX 56  - 57  LBL 03           58  10 59  X>Y? 60  GTO 00 61  - 62  >"X" 63  GTO 03     64  LBL 00 65  DSE X 66  X<=Y? 67  >"IX" 68  X>Y? 69  CLX 70  - 71  5 72  X<=Y? 73  >"V" 74  X>Y? 75  CLX 76  -      77  4 78  X<=Y? 79  >"IV"    80  X>Y? 81  CLX 82  - 83  LBL 04           84  1 85  X>Y? 86  GTO 00     87  - 88  >"I"   89  GTO 04 90  LBL 00 91  AVIEW 92  END

( 154 bytes / SIZE 000 )

 STACK INPUTS OUTPUTS X Number /

Examples:

1444   XEQ "A-R"  >>>>   MCDXLIV                            ( in 3 seconds )
4888         R/S         >>>>   MMMMDCCCLXXXVIII    ( in 9 seconds )
2345         R/S         >>>>   MMCCCXLV                       ( in 4 seconds )

-The result is in the alpha register and it is displayed line 91.

2°)  Roman Numerals  >>>  Arabic Numerals    ( X-Functions Module required )

Data Registers: /
Flags: /
Subroutines: /

 01  LBL "R-A" 02  CLST 03  * 04  LBL 01           05  ATOX 06  X=0? 07  GTO 09 08  77 09  X=Y? 10  GTO 02 11  DSE X 12  X=Y? 13  GTO 03 14  CLX 15  68 16  X=Y? 17  GTO 04         18  DSE X 19  X=Y? 20  GTO 05 21  CLX 22  88 23  X=Y? 24  GTO 06 25  CLX 26  86 27  X=Y? 28  GTO 07 29  CLX 30  73 31  X#Y? 32  CLX 33  X#0? 34  SIGN 35  ENTER^ 36  GTO 08    37  LBL 02           38   E3 39  GTO 08 40  LBL 03 41  50 42  GTO 08 43  LBL 04 44  500 45  GTO 08 46  LBL 05           47   E2 48  GTO 08    49  LBL 06 50  10 51  GTO 08 52  LBL 07 53  5 54  LBL 08 55  R^ 56  X<>Y 57  LASTX 58  XY 68  END

( 106 bytes / SIZE 000 )

 STACK INPUTS OUTPUTS X / Number

Examples:

[ alpha ]   MMMMDCCCLXXXVIII   [ alpha ]   XEQ "R-A"  >>>>  4888   ( in 16 seconds )
[ alpha ]   MCDXLIV  [ alpha ]                                    R/S       >>>>  1444   ( in 7 seconds )
[ alpha ]   MMCCCXLV  [ alpha ]                               R/S       >>>>  2345   ( in 8 seconds )

-If the alpha string contains other symbols, they will be neglected ( = zero )
-When the program stops, the alpha register is cleared.
-Here is a shorter & faster version of this program:

 01  LBL "R-A" 02  CLST 03  LBL 01 04  ATOX 05  X=0? 06  GTO 00 07  RDN 08  XEQ IND T 09  X<>Y 10  X

( 65 bytes / SIZE 000 )

 STACK INPUTS OUTPUTS X / Number

Examples:

[ alpha ]   MMMMDCCCLXXXVIII   [ alpha ]   XEQ "R-A"  >>>>  4888   ( in 9 seconds )
[ alpha ]   MCDXLIV  [ alpha ]                                    R/S       >>>>  1444   ( in 4 seconds )
[ alpha ]   MMCCCXLV  [ alpha ]                               R/S       >>>>  2345   ( in 5 seconds )

Note:

-Here, there will be a NONEXISTENT message if the alpha register contains other characters.