The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
[TI-57] Calculate Square Root
10-24-2024, 07:47 AM (This post was last modified: 10-25-2024 09:31 AM by Thomas Klemm.)
Post: #1
[TI-57] Calculate Square Root
Based on a recent thread I took a closer look at the assembly code of the TI-57.
To analyze the code, I extended the RCL-57 emulator's command line tool to track the three registers A, B, and C.

This is the relevant assembly code:
Code:
0x0640: 0x13f4  CALL    0x03f4
0x0641: 0x05a1  LOAD    C,C-1,0000 0000 0000 00FF
0x0642: 0x1e4b  BRC     0x064b
0x0643: 0x05a1  LOAD    C,C-1,0000 0000 0000 00FF
0x0644: 0x1e47  BRC     0x0647
0x0645: 0x0520  LOAD    A,A+1,0000 0000 0000 00FF
0x0646: 0x1a41  BRNC    0x0641
0x0647: 0x0c96  TST     C[13:1]
0x0648: 0x1a4a  BRNC    0x064a
0x0649: 0x0520  LOAD    A,A+1,0000 0000 0000 00FF
0x064a: 0x026d  LOAD    NUL,B>>1,000F FFFF FFFF FF00
0x064b: 0x0c91  CLR     C[13:0]
0x064c: 0x0849  LOAD    B,B-B,0F00 0000 0000 0000
0x064d: 0x0507  MOVE    A,A,0000 0000 0000 00FF
0x064e: 0x0978  LOAD    B,B+R5,FFF0 0000 0000 0000
0x064f: 0x0501  LOAD    A,A-A,0000 0000 0000 00FF
0x0650: 0x0591  LOAD    C,C-C,0000 0000 0000 00FF
0x0651: 0x1a61  BRNC    0x0661
0x0652: 0x036d  LOAD    NUL,B>>1,000F FFFF FFFF FFFF
0x0653: 0x032d  LOAD    NUL,A>>1,000F FFFF FFFF FFFF
0x0654: 0x1a60  BRNC    0x0660
0x0655: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF
0x0656: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF
0x0657: 0x0308  LOAD    A,A+B,000F FFFF FFFF FFFF
0x0658: 0x0385  LOAD    NUL,C-A,000F FFFF FFFF FFFF
0x0659: 0x1a55  BRNC    0x0655
0x065a: 0x0309  LOAD    A,A-B,000F FFFF FFFF FFFF
0x065b: 0x0312  LOAD    C,A+C,000F FFFF FFFF FFFF
0x065c: 0x1a5d  BRNC    0x065d
0x065d: 0x00a5  LOAD    NUL,C-1,000F 0000 0000 0000
0x065e: 0x1a52  BRNC    0x0652
0x065f: 0x03a8  LOAD    C,C<<1,000F FFFF FFFF FFFF
0x0660: 0x036d  LOAD    NUL,B>>1,000F FFFF FFFF FFFF
0x0661: 0x0365  LOAD    NUL,B-1,000F FFFF FFFF FFFF
0x0662: 0x1a56  BRNC    0x0656
0x0663: 0x15b2  CALL    0x05b2

Here is a typical output:
Code:
(…)
0x0659: 0x1a55  BRNC    0x0655                          A=1000400000000000 B=0000100000000000 C=0002900000000000
0x0655: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF       A=1000400000000000 B=0000100000000000 C=0002500000000000
0x0656: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF       A=1000400000000000 B=0000100000000000 C=0002100000000000
0x0657: 0x0308  LOAD    A,A+B,000F FFFF FFFF FFFF       A=1000500000000000 B=0000100000000000 C=0002100000000000
0x0658: 0x0385  LOAD    NUL,C-A,000F FFFF FFFF FFFF     A=1000500000000000 B=0000100000000000 C=0002100000000000
0x0659: 0x1a55  BRNC    0x0655                          A=1000500000000000 B=0000100000000000 C=0002100000000000
0x0655: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF       A=1000500000000000 B=0000100000000000 C=0001600000000000
0x0656: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF       A=1000500000000000 B=0000100000000000 C=0001100000000000
0x0657: 0x0308  LOAD    A,A+B,000F FFFF FFFF FFFF       A=1000600000000000 B=0000100000000000 C=0001100000000000
0x0658: 0x0385  LOAD    NUL,C-A,000F FFFF FFFF FFFF     A=1000600000000000 B=0000100000000000 C=0001100000000000
0x0659: 0x1a55  BRNC    0x0655                          A=1000600000000000 B=0000100000000000 C=0001100000000000
0x0655: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF       A=1000600000000000 B=0000100000000000 C=0000500000000000
0x0656: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF       A=1000600000000000 B=0000100000000000 C=0009900000000000
0x0657: 0x0308  LOAD    A,A+B,000F FFFF FFFF FFFF       A=1000700000000000 B=0000100000000000 C=0009900000000000
0x0658: 0x0385  LOAD    NUL,C-A,000F FFFF FFFF FFFF     A=1000700000000000 B=0000100000000000 C=0009900000000000
0x0659: 0x1a55  BRNC    0x0655                          A=1000700000000000 B=0000100000000000 C=0009900000000000
0x065a: 0x0309  LOAD    A,A-B,000F FFFF FFFF FFFF       A=1000600000000000 B=0000100000000000 C=0009900000000000
0x065b: 0x0312  LOAD    C,A+C,000F FFFF FFFF FFFF       A=1000600000000000 B=0000100000000000 C=0000500000000000
0x065c: 0x1a5d  BRNC    0x065d                          A=1000600000000000 B=0000100000000000 C=0000500000000000
0x065d: 0x00a5  LOAD    NUL,C-1,000F 0000 0000 0000     A=1000600000000000 B=0000100000000000 C=0000500000000000
0x065e: 0x1a52  BRNC    0x0652                          A=1000600000000000 B=0000100000000000 C=0000500000000000
0x065f: 0x03a8  LOAD    C,C<<1,000F FFFF FFFF FFFF      A=1000600000000000 B=0000100000000000 C=0005000000000000
0x0660: 0x036d  LOAD    NUL,B>>1,000F FFFF FFFF FFFF    A=1000600000000000 B=0000010000000000 C=0005000000000000
0x0661: 0x0365  LOAD    NUL,B-1,000F FFFF FFFF FFFF     A=1000600000000000 B=0000010000000000 C=0005000000000000
0x0662: 0x1a56  BRNC    0x0656                          A=1000600000000000 B=0000010000000000 C=0005000000000000
0x0656: 0x0381  LOAD    C,C-A,000F FFFF FFFF FFFF       A=1000600000000000 B=0000010000000000 C=0004400000000000
0x0657: 0x0308  LOAD    A,A+B,000F FFFF FFFF FFFF       A=1000610000000000 B=0000010000000000 C=0004400000000000
0x0658: 0x0385  LOAD    NUL,C-A,000F FFFF FFFF FFFF     A=1000610000000000 B=0000010000000000 C=0004400000000000
0x0659: 0x1a55  BRNC    0x0655                          A=1000610000000000 B=0000010000000000 C=0004400000000000
(…)

However, we simply list the line 0x0659 to get the relevant data when calculating \(\sqrt{41}\):

A=1000100000000000 B=0000100000000000 C=0004100000000000
A=1000200000000000 B=0000100000000000 C=0003900000000000
A=1000300000000000 B=0000100000000000 C=0003500000000000
A=1000400000000000 B=0000100000000000 C=0002900000000000
A=1000500000000000 B=0000100000000000 C=0002100000000000
A=1000600000000000 B=0000100000000000 C=0001100000000000
A=1000700000000000 B=0000100000000000 C=0009900000000000
A=1000610000000000 B=0000010000000000 C=0004400000000000
A=1000620000000000 B=0000010000000000 C=0003180000000000
A=1000630000000000 B=0000010000000000 C=0001940000000000
A=1000640000000000 B=0000010000000000 C=0000680000000000
A=1000650000000000 B=0000010000000000 C=0009400000000000
A=1000641000000000 B=0000001000000000 C=0009760000000000
A=1000640100000000 B=0000000100000000 C=0003360000000000
A=1000640200000000 B=0000000100000000 C=0002079800000000
A=1000640300000000 B=0000000100000000 C=0000799400000000
A=1000640400000000 B=0000000100000000 C=0009518800000000
A=1000640310000000 B=0000000010000000 C=0000950700000000
A=1000640320000000 B=0000000010000000 C=0009670080000000
A=1000640311000000 B=0000000001000000 C=0002463590000000
A=1000640312000000 B=0000000001000000 C=0001182968000000
A=1000640313000000 B=0000000001000000 C=0009902344000000
A=1000640312100000 B=0000000000100000 C=0004786248000000
A=1000640312200000 B=0000000000100000 C=0003505623800000
A=1000640312300000 B=0000000000100000 C=0002224999400000
A=1000640312400000 B=0000000000100000 C=0000944374800000
A=1000640312500000 B=0000000000100000 C=0009663750000000
A=1000640312410000 B=0000000000010000 C=0002400311600000
A=1000640312420000 B=0000000000010000 C=0001119686780000
A=1000640312430000 B=0000000000010000 C=0009839061940000
A=1000640312421000 B=0000000000001000 C=0004153431180000
A=1000640312422000 B=0000000000001000 C=0002872806338000
A=1000640312423000 B=0000000000001000 C=0001592181494000
A=1000640312424000 B=0000000000001000 C=0000311556648000
A=1000640312423100 B=0000000000000100 C=0008878378287000
A=1000640312423200 B=0000000000000100 C=0007597753440800
A=1000640312423300 B=0000000000000100 C=0006317128594400
A=1000640312423400 B=0000000000000100 C=0005036503747800
A=1000640312423500 B=0000000000000100 C=0003755878901000
A=1000640312423600 B=0000000000000100 C=0002475254054000
A=1000640312423700 B=0000000000000100 C=0001194629206800
A=1000640312423800 B=0000000000000100 C=0009914004359400
A=1000640312423710 B=0000000000000010 C=0004902855407300
A=1000640312423720 B=0000000000000010 C=0003622230559880
A=1000640312423730 B=0000000000000010 C=0002341605712440
A=1000640312423740 B=0000000000000010 C=0001060980864980
A=1000640312423750 B=0000000000000010 C=0009780356017500
A=1000640312423741 B=0000000000000001 C=0003566371988660
A=1000640312423742 B=0000000000000001 C=0002285747141178
A=1000640312423743 B=0000000000000001 C=0001005122293694
A=1000640312423744 B=0000000000000001 C=0009724497446208

This is a largely literal translation of the code for the HP-42S:
Code:
00 { 39-Byte Prgm }     ; C=x
01 12                   ; n=12 C
02 STO 00               ; n C
03 SIGN                 ; B=1 C
04 X<>Y                 ; C B
05 0                    ; A=0 C B
06 GTO 01               ; X:A Y:C Z:B
07▸LBL 00               ; 
08 STO- ST Y            ; 0x0655: LOAD    C,C-A,000F FFFF FFFF FFFF
09▸LBL 01               ; 
10 STO- ST Y            ; 0x0656: LOAD    C,C-A,000F FFFF FFFF FFFF
11 RCL+ ST Z            ; 0x0657: LOAD    A,A+B,000F FFFF FFFF FFFF
12 X≤Y?                 ; 0x0658: LOAD    NUL,C-A,000F FFFF FFFF FFFF
13 GTO 00               ; 0x0659: BRNC    0x0655
14 RCL- ST Z            ; 0x065a: LOAD    A,A-B,000F FFFF FFFF FFFF
15 STO+ ST Y            ; 0x065b: LOAD    C,A+C,000F FFFF FFFF FFFF
16 10                   ; 
17 STO× ST Z            ; 0x065f: LOAD    C,C<<1,000F FFFF FFFF FFFF
18 STO÷ ST T            ; 0x0660: 0x036d  NUL,B>>1,000F FFFF FFFF FFFF
19 R↓                   ; 
20 DSE 00               ; 0x0661: LOAD    NUL,B-1,000F FFFF FFFF FFFF
21 GTO 01               ; 0x0662: BRNC    0x0656
22 END                  ;

Example

41
R/S

6.40312423743


For those who want to use this, I have added the relevant files:

Archive:  ti-57.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      364  10-24-2024 09:44   Makefile
     5085  10-24-2024 09:44   cli/app_ti57.c
    11280  10-24-2024 09:44   engine/ti57.c
    83798  10-24-2024 09:44   engine/asm.c
      122  10-24-2024 09:44   engine/asm.h
---------                     -------
   100649                     5 files


Attached File(s)
.zip  ti-57.zip (Size: 19.26 KB / Downloads: 4)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
[TI-57] Calculate Square Root - Thomas Klemm - 10-24-2024 07:47 AM



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