Post Reply 
Dismal Arithmetic & 3 Progs for 49G & Others
05-08-2015, 01:35 AM
Post: #19
RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S
For those of you who have already died of boredom, here's a TI-95 version. It's not terribly fast. Even with all the control transfer statements ASMed, it took 42 seconds to compute 435,821 * 2,949,229.

Run the program to get the main menu, then separate your two arguments with x~t and press F1 or F2 to add or multiply. (As if anybody here besides me has a TI-95 and cares enough to try this.)

Code:
280 Bytes

DFN CLR
DFN F1:ADD@AD
DFN F2:MLT@ML
RTN

LBL NL
IF= 014
RTN
ABS
LOG
+
1
=
INT
RTN

LBL DG
-
1
=
INV
LOG
x~t
/
x~t
=
INT
/
10
=
FRC
*
10
=
RTN

LBL AD
STO 001
SBL NL
STO 002
x~t
STO 000
SBL NL
IF> 002
STO 002
1
STO 003
0
STO 005
STO 014

LBL A1
RCL 000
x~t
RCL 003
SBL DG
STO 004
RCL 001
x~t
RCL 003
SBL DG
IF< 004
RCL 004
*
(
RCL 003
-
1
)
INV
LOG
=
ST+ 005
INC 003
RCL 003
INV
IF> 002
GTL A1
RCL 005
RTN

LBL ML
STO 007
SBL NL
STO 010
x~t
STO 006
SBL NL
STO 008
0
STO 013
STO 014

LBL M1
0
STO 012
RCL 007
x~t
RCL 010
SBL DG
STO 011
1
STO 009

LBL M2
RCL 006
x~t
RCL 009
SBL DG
IF> 011
RCL 011
*
(
RCL 009
-
1
)
INV
LOG
=
ST+ 012
INC 009
RCL 009
INV
IF> 008
GTO M2
RCL 013
*
10
=
x~t
RCL 012
SBL AD
STO 013
DSZ 010
GTL M1
RCL 013
RTN


Labels
NL - Number length
DG - Get digit

AD - Add
A1 - Add loop

ML - Multiply
M1 - Multiply outer loop
M2 - Multiply inner loop


Variables
000 - Addend 1
001 - Addend 2
002 - Addend max length (loop end)
003 - Add loop counter
004 - Addition scratch register
005 - Sum

006 - Factor 1
007 - Factor 2
008 - Factor 1 length (inner loop end)
009 - Inner loop counter, incrementing (factor 1)
010 - Outer loop counter, decrementing (factor 2)
011 - Outer loop current digit (factor 2)
012 - Product
013 - Sum of products

014 - Zero (constant for comparison tests)

Some notes:

If you ASM and then subsequently INV ASM the program, the GTL M1 instruction doesn't get converted back from the step number. No idea why.

The comparison tests are very flexible, yet limited at the same time. You can compare the display register (x) with any storage register and skip the next instruction if false, but there's no way to compare x with 0 without storing 0 somewhere, and you can't directly test x against t unless you unprotect the system and access it via system register number 2079.

The lack of ISG is surprisingly annoying.

I may attempt doing this on the TI-66 if I hit my head and forget how awful the comparison tests are on that. (You only get x=t, x!=t, x>=t, and x<t, and you're only able to have an implied GTO after it, so doing a conditional RTN requires a label followed by a RTN floating around in your program somewhere.)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S - Dave Britten - 05-08-2015 01:35 AM



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