↑ Writing ↑

GEONius.com
14-Oct-2022
 E-mail 

This is the original program.
See the new web page.

Permutations on a TI-58 Programmable Calculator

Pseudo-Design Language: permutations_orig_pdl.txt

C Program: perm.c (implements Horowitz's and Sahni's permutation algorithm)

Emulator Files

NOTE that all the files below (".t58", ".hlp", ".lst", and ".wri") are ASCII files with Windows-style carriage-return/line-feed line endings; the TI58C EMULATOR won't load the files correctly if they have Unix-style line-feed endings.

Files for Pierre Houbert's TI58C EMULATOR:

or, separately:

Simply load "permutations_orig.t58", clicking the "with datas" checkbox so the emulator will automatically load the ".wri" file. The memory registers are preloaded with an example setup which generates all the permutations for "TRY IT". After loading the program and memory registers in one operation, go ahead and run (R/S) the program!

Houbert's emulator can also load the program in Guillaume Tello's ".lst" file format:

 

Memory Registers

Register(s)Usage
0
Total # of permutations printed. (Incremented after printing a string permutation.) R0 must be set to 0 before running the program.
6
Index in A of second character to be swapped? This register must be initialized to N-1, one less that the length of the string, before running the program. The full length of the string, N, is stored in R19.
7
Stack pointer (SP). *R7 points to the memory register containing the current call "frame". Pushing a call frame on the stack increments R7 and popping a frame decrements R7. This register must be set to 8, thus pointing to the initial top of the stack, before running the program.
08 - 18
The call stack, beginning with register 8 and growing upwards (possibly to register 18). One call frame is stored per memory register and is encoded as a number, "nnnnnnnnnn.ik", where the ten integer digits (1-9 and 0) are the current configuration of the permutation indices and the two fractional digits are the values of local variables i and k, respectively. The very first call frame, in register 8, is a setup parameter which must be set prior to running the program; you only need to specify the indices for the initial permutation string, "nnnnnnnnnn" (or fewer digits for a shorter string).
19
The length, 1≤N≤10, of the string being permuted. This is a setup parameter which must be set prior to running the program.
20 - 29
Print codes, one letter per memory register. Registers 20-29 contain the two-digit character codes for the characters corresponding to indices 0, 1, 2, ..., 9 in the permutation string. For strings less than 10 characters in length, index 0 and memory register 20 are reserved for implicit leading blanks used to expand a permuted string to 10 characters for printing; in this case, R20 must be set to 0. The PC-100 alphanumeric character codes (decimal numbers, not octal!) from Guillaume Tello's Texas Instruments TI 58C/TI 59 page:
TI PC-100 character codes
 

Program Listing

Step Opcode Command Comments
000 29 CP
001 43 RCL 06
002 06 06
003 22 INV
004 77 GE 107 if (R6 > 0) then
005 01 01
006 07 07
007 42 STO 05
008 05 05
009 43 RCL 05
010 05 05
011 32 X >< T
012 43 RCL 06
013 06 06
014 67 EQ 083
015 00 00
016 83 83
017 22 INV
018 28 LOG
019 42 STO 04
020 04 04
021 73 RC* 07
022 07 07
023 55 /
024 32 X >< T
025 22 INV
026 28 LOG
027 42 STO 03
028 03 03
029 55 /
030 01 1
031 00 0
032 95 =
033 22 INV
034 59 INT
035 65 *
036 01 1
037 00 0
038 95 =
039 59 INT
040 42 STO 02
041 02 02
042 94 +/-
043 42 STO 01
044 01 01
045 32 X >< T
046 55 /
047 43 RCL 04
048 04 04
049 55 /
050 01 1
051 00 0
052 95 =
053 22 INV
054 59 INT
055 65 *
056 01 1
057 00 0
058 95 =
059 59 INT
060 44 SUM 01
061 01 01
062 22 INV
063 44 SUM 02
064 02 02
065 43 RCL 01
066 01 01
067 65 *
068 43 RCL 03
069 03 03
070 95 =
071 74 SM* 07
072 07 07
073 43 RCL 02
074 02 02
075 65 *
076 43 RCL 04
077 04 04
078 95 =
079 74 SM* 07
080 07 07
081 43 RCL 06
082 06 06
083 55 /
084 01 1
085 00 0
086 00 0
087 85 +
088 43 RCL 05
089 05 05
090 55 /
091 01 1
092 00 0
093 85 +
094 73 RC* 07
095 07 07
096 59 INT
097 95 =
098 72 ST* 07
099 07 07
100 69 OP
101 27 27
102 72 ST* 07
103 07 07
104 69 OP
105 36 36
106 81 RST endif
107 73 RC* 07
108 07 07
109 55 /
110 05 5
111 22 INV
112 28 LOG
113 95 =
114 42 STO 01
115 01 01
116 59 INT
117 22 INV
118 44 SUM 01
119 01 01
120 55 /
121 05 5
122 22 INV
123 28 LOG
124 95 =
125 42 STO 02
126 02 02
127 43 RCL 19
128 19 19
129 32 X >< T
130 05 5
131 77 GE 143
132 01 01
133 43 43
134 25 CLR
135 42 STO 03
136 03 03
137 05 5
138 71 SBR 200 call AssembleWord (5)
139 02 02
140 00 00
141 69 OP
142 02 02
143 43 RCL 01
144 01 01
145 42 STO 02
146 02 02
147 25 CLR
148 42 STO 03
149 03 03
150 05 5
151 71 SBR 200 call AssembleWord (5)
152 02 02
153 00 00
154 69 OP 03
155 03 03
156 69 OP 05
157 05 05
158 69 OP 20
159 20 20
160 43 RCL 07
161 07 07
162 32 X >< T
163 08 8
164 77 GE 235
165 02 02
166 35 35
167 69 OP 37
168 37 37
169 73 RC* 07
170 07 07
171 22 INV
172 59 INT
173 65 *
174 01 1
175 00 0
176 95 =
177 42 STO 06
178 06 06
179 59 INT
180 42 STO 05
181 05 05
182 22 INV
183 44 SUM 06
184 06 06
185 01 1
186 00 0
187 49 PRD 06
188 06 06
189 29 CP
190 69 OP 35
191 35 35
192 43 RCL 05
193 05 05
194 77 GE 009
195 00 00
196 09 09
197 61 GTO 160
198 01 01
199 60 60
200 42 STO 05 proc AssembleWord (N)
201 05 05 R5 := N ;
202 01 1 repeat
203 00 0
204 00 0
205 49 PRD 03 R3 := R3 * 100 ;
206 03 03
207 01 1
208 00 0
209 49 PRD 02 R2 := R2 * 10 ;
210 02 02
211 02 2
212 00 0
213 44 SUM 02 R2 := R2 + 20 ;
214 02 02
215 73 RC* 02
216 02 02
217 44 SUM 03 R3 := R3 + *R2 ;
218 03 03
219 43 RCL 02
220 02 02
221 59 INT
222 22 INV
223 44 SUM 02 R2 := R2 - int (R2) ;
224 02 02
225 97 DSZ 05 202 R5 := R5 - 1 ;
226 05 05 until (R5 = 0) ;
227 02 02
228 02 02
229 43 RCL 03
230 03 03 return (R3) ;
231 92 RTN endproc ;
232 00 0
233 00 0
234 00 0
235 98 ADV
236 43 RCL 00
237 00 00
238 99 PRT
239 91 R/S

Alex Measday  /  E-mail