Le Compte est Bon for the HP-41
Overview
1°) Progam#1
2°) M-Code Routine
3°) Program#2
-"Le compte est bon" is a French TV game:
-6 numbers ( n1 , n2 , n3 , n4
, n5 , n6 ) are choosen at random among the
24 integers:
1 - 1 - 2 - 2 - 3 - 3 - 4 - 4 - 5 - 5 - 6 - 6 - 7 - 7 - 8 - 8 - 9 - 9 - 10 - 10 - 25 - 50 - 75 - 100 ( for instance 1 - 9 - 8 - 4 - 3 - 100 )
and you have to find another random number N ( between 100 and
999 inclusive ) , say N = 629 , using the 6 numbers above (
or less )
and the 4 basic operations: addition, subtraction, multiplication,
division.
-For example, one solution of the above problem is:
100 - 1 = 99
99 / 3 = 33
33 + 4 = 37
9 + 8 = 17
37 * 17 = 629
-A solution has - at most - 5 operations and the same number cannot
be used several times.
-More exactly, you can use "ni" twice or less if there are
2 "ni"s
and you can use "ni" once or less if there is
1 "ni"
-The following programs can help you to find one or several solution(s)
to this problem.
1°) Program#1
Data Registers: •
R01 = n1 • R02 = n2 ..........
• R06 = n6 • R07 = N
( these 7 registers are to be initialized before executing "LCEB"
)
R00 & R08 thru R17: temp
Flags: F05-F06-F07
Subroutines: /
-Lines 01 to 39 and 127 to 356 search a solution where the result of
an operation is immediately used in the next one.
-If - at this step - no solution is found, lines 40 thru 124 add a
few other combinations.
-The append character is denoted ~
01 LBL "LCEB"
02 6 03 STO 12 04 5 05 STO 13 06 STO 16 07 4 08 STO 14 09 STO 17 10 3 11 STO 00 12 STO 15 13 LBL 01 14 RCL 07 15 RCL 07 16 RCL 01 17 / 18 STO 08 19 CF 05 20 X#Y? 21 FRC 22 X=0? 23 XEQ 02 24 RCL 07 25 RCL 01 26 - 27 STO 08 28 SF 05 29 XEQ 02 30 RCL 07 31 RCL 01 32 + 33 STO 08 34 XEQ 02 35 RCL 01 36 X<> IND 12 37 STO 01 38 DSE 12 39 GTO 01 40 6.001 41 STO 12 42 STO 13 43 LBL 12 44 RCL 07 45 RCL 01 46 RCL 02 47 + 48 STO 08 49 / 50 STO 09 51 CF 06 52 FRC 53 X=0? 54 XEQ 03 55 RCL 07 56 RCL 07 57 RCL 01 58 RCL 02 59 X=Y? 60 GTO 00 |
61 -
62 ABS 63 STO 08 64 / 65 STO 09 66 X#Y? 67 FRC 68 X=0? 69 XEQ 03 70 LBL 00 71 RCL 01 72 RCL 02 73 X<Y? 74 X<>Y 75 STO Z 76 * 77 X=Y? 78 GTO 00 79 STO 08 80 RCL 07 81 - 82 ABS 83 STO 09 84 SF 06 85 XEQ 03 86 RCL 07 87 RCL 08 88 + 89 STO 09 90 XEQ 03 91 RCL 07 92 RCL 01 93 RCL 02 94 X>Y? 95 X<>Y 96 / 97 STO 08 98 - 99 STO 09 100 FRC 101 X#0? 102 GTO 00 103 XEQ 03 104 RCL 07 105 RCL 08 106 + 107 STO 09 108 XEQ 03 109 LBL 00 110 RCL 02 111 X<> IND 13 112 STO 02 113 DSE 13 114 GTO 12 115 RCL 12 116 INT 117 2 118 - 119 ST+ 13 120 RCL 01 |
121 X<> IND 12
122 STO 01 123 DSE 12 124 GTO 12 125"Nb NOT FOUND" 126 PROMPT 127 LBL 02 128 RCL 02 129 RCL 08 130 X=Y? 131 GTO 10 132 X<Y? 133 X<>Y 134 STO Z 135 X<>Y 136 / 137 STO 09 138 CF 06 139 X#Y? 140 FRC 141 X=0? 142 XEQ 03 143 FS? 05 144 GTO 00 145 RCL 08 146 RCL 02 147 - 148 ABS 149 STO 09 150 SF 06 151 XEQ 03 152 RCL 08 153 RCL 02 154 + 155 STO 09 156 XEQ 03 157 LBL 00 158 RCL 02 159 X<> 03 160 X<> 04 161 X<> 05 162 X<> 06 163 STO 02 164 DSE 13 165 GTO 02 166 RCL 16 167 STO 13 168 RTN 169 LBL 03 170 RCL 03 171 RCL 09 172 X=Y? 173 GTO 09 174 X<Y? 175 X<>Y 176 STO Z 177 X<>Y 178 / 179 STO 10 180 CF 07 |
181 X#Y?
182 FRC 183 X=0? 184 XEQ 04 185 FS? 06 186 GTO 00 187 RCL 09 188 RCL 03 189 - 190 ABS 191 STO 10 192 SF 07 193 XEQ 04 194 RCL 09 195 RCL 03 196 + 197 STO 10 198 XEQ 04 199 LBL 00 200 RCL 03 201 X<> 04 202 X<> 05 203 X<> 06 204 STO 03 205 DSE 14 206 GTO 03 207 RCL 17 208 STO 14 209 RTN 210 LBL 04 211 RCL 04 212 RCL 10 213 X=Y? 214 GTO 08 215 X>Y? 216 X<>Y 217 ENTER^ 218 SIGN 219 X=Y? 220 GTO 00 221 RDN 222 / 223 STO 11 224 FRC 225 X=0? 226 XEQ 05 227 RCL 04 228 RCL 10 229 * 230 STO 11 231 XEQ 05 232 LBL 00 233 FS? 07 234 GTO 00 235 RCL 10 236 RCL 04 237 - 238 ABS 239 STO 11 240 XEQ 05 |
241 RCL 04
242 RCL 10 243 + 244 STO 11 245 XEQ 05 246 LBL 00 247 RCL 04 248 X<> 05 249 X<> 06 250 STO 04 251 DSE 15 252 GTO 04 253 RCL 00 254 STO 15 255 RTN 256 LBL 05 257 RCL 06 258 RCL 11 259 X=Y? 260 GTO 07 261 RCL 05 262 - 263 X=0? 264 GTO 07 265 ABS 266 RCL 06 267 X=Y? 268 GTO 06 269 RCL 11 270 RCL 05 271 + 272 X=Y? 273 GTO 06 274 RCL 11 275 RCL 05 276 X>Y? 277 X<>Y 278 / 279 RCL 06 280 X=Y? 281 GTO 06 282 RCL 11 283 RCL 05 284 * 285 X#Y? 286 RTN 287 LBL 06 288 RCL 11 289 RCL 05 290 RCL 06 291 XEQ 00 292 LBL 07 293 RCL 10 294 RCL 04 295 RCL 11 296 XEQ 00 297 LBL 08 298 RCL 09 299 RCL 03 300 RCL 10 |
301 XEQ 00
302 LBL 09 303 RCL 12 304 FRC 305 X#0? 306 GTO 11 307 RCL 08 308 RCL 02 309 RCL 09 310 XEQ 00 311 LBL 10 312 RCL 07 313 RCL 01 314 RCL 08 315 GTO 00 316 LBL 11 317 RCL 08 318 RCL 01 319 RCL 02 320 XEQ 00 321 RCL 07 322 RCL 08 323 RCL 09 324 LBL 00 325 FIX 0 326 CF 29 327 X<Y? 328 X<>Y 329 STO T 330 X<>Y 331 CLA 332 ARCL Y 333 + 334 X=Y? 335 "~+" 336 X<> T 337 LASTX 338 - 339 X=Y? 340 "~-" 341 X<> T 342 LASTX 343 ST/ T 344 * 345 X=Y? 346 "~*" 347 X<> T 348 X=Y? 349 "~/" 350 ARCL L 351 "~=" 352 ARCL Y 353 FIX 4 354 SF 29 355 PROMPT 356 END |
( 513 bytes / SIZE 018 )
STACK | INPUTS | OUTPUTS |
X | / | / |
Example1: 75 - 100 - 25
- 3 - 9 - 6 // 758
Store these 7 numbers into R01 thru R07 respectively
XEQ "LCEB" >>>> "75+3=78"
( in 1 minute )
R/S "78/6=13"
R/S "100-13=87"
R/S "87*9=783"
R/S "783-25=758"
Example2: 4 - 7 - 50 - 1 - 4 - 100 // 903 4 STO 01 ......................... 903 STO 07
XEQ "LCEB" >>>> "100/4=25"
( in 4 minutes )
R/S "25-4=21"
R/S "50-7=43"
R/S 43*21=903"
Example3: 3 - 7 - 7 - 50 - 1 - 8 // 947 3 STO 01 ............................ 947 STO 07
XEQ "LCEB" >>>> the HP-41 displays "Nb NOT FOUND" about 6 minutes later
-However, there is a solution ( see below )
Remarks:
-Press XEQ 10 to display again a solution in 1 operation
-Press XEQ 09 to display again a solution in 2 operations
-Press XEQ 08 to display again a solution in 3 operations
-Press XEQ 07 to display again a solution in 4 operations
-Press XEQ 06 to display again a solution in 5 operations
-In order to decrease the execution time, flags F05 F06 F07 are used
to avoid 2 successive additions and/or subtractions
in the beginning of the search ( i-e at the end of the solutions
).
-Additions and subtractions are only computed after a division or a
multiplication and a very simple result like 100 + 7 = 107 ,
107 + 25 = 132 cannot be found!
( delete lines 157 - 144 - 143 - 28 - 19 to allow this
kind of solutions )
-Moreover, the multiplication doesn't appear in the beginning of the
tree ( so, a solution never ends by a division )
and many other solutions are skipped.
-Despite all these limitations, this program can solve about 90% of
the soluble problems! ( only 80% if you delete lines 40 to 124 )
-Execution times are usually a few minutes ( less than 20 minutes apparently
)
-Improvements are easy to make: delete all the lines involving flags
F05 F06 F07 and a solution with 5 additions is now possible.
-Unfortunately, execution time can reach several hours... unless you
are using an emulator like V41 in turbo mode,
( the several hours are reduced to less than 1 minute! )
-On the other hand, you can also add other operations:
for instance, add RCL 07 RCL 01 * STO
08 XEQ 02 after line 23 and try example 3 again
-Your HP-41 now yields in 48 seconds:
"50+8=58"
R/S
"58*7=406"
R/S
"406*7=2842"
R/S
"2842-1=2841"
R/S
"2841/3=947"
-There are 2 minor defects:
1-The solution in zero operation: 100 = 100
cannot be found, but a calculator is not absolutely necessary to find this
result!
2-The HP-41 displays "2+*2=4" instead of "2+2=4" or "2*2=4"
-Of course, this program can use other integers:
-For instance, with 32 - 41 - 55 - 48 - 49 - 67 //
2007
XEQ "LCEB" >>>> "49-41=8"
R/S "48/8=6"
R/S "67-6=61"
R/S "61*32=1952"
R/S "1952+55=2007"
2°) M-Code Routine
-This long routine does the most part of the job.
-All the improvements mentionned above are taken into account.
-Its name is the header of your ROM, located in block F.
-If you change its place, change all the jumps written in red too...
-This routine must be used with care:
-Synthetic register a is used.
-The 7 numbers must be integers that are stored in registers
X Y Z T L M N.
-Use it with the 2nd program listed in paragraph 3.
-Moreover, it can only be stopped by pressing ENTER^ ON on a "new"
HP-41,
-So, avoid using it with older HP-41... ( unless you add the 3 words
suggested hereunder before LBL 04,
but in this case, change the jumps too )
08D "M"
The name doesn't matter
00F "O"
012 "R"
00E "N"
017 "W"
00F "O"
019 "Y"
00D "M"
2A0 SETDEC
the 1st executable word is at the address F08C
130 LDI S&X
006 006
070 N=C ALL
270 RAMSLCT
038 READDATA
249 ?NCXQ
?NCXQ to shift the digits
in the right
3C8 F292
format
part of the mantissa field
2F0 WRITDATA
0B0 C=N ALL
266 C=C-1 S&X
3C3 JNC-08
04E C=0
01C PT=3
090 LD@PT- 3
070 N=C ALL
2DC PT=13
150 LD@PT- 5
110 LD@PT- 4
0D0 LD@PT- 3
130 LDI S&X
006 006
158 M=C ALL
1B8 READ 6(N)
LBL 01 address F0A3
10E A=C ALL
0B0 C=N ALL
0EE B<>C ALL
04E C=0 ALL
270 RAMSLCT
038 READDATA
304 CLRF 1
204 CLRF 2
004 CLRF 3
31A ?A<C M
017 JC+02
0BA A<>C M
33A ?A<B M
077 JC+0Eh
2ED ?NCXQ
quotient-remainder
3C8 F2BB
subroutine
35A ?A#0 M
1B3 JNC+36h
308 SETF 1
04E C=0 ALL
270 RAMSLCT
038 READDATA
10E A=C ALL
1B8 READ 6(N)
2A1 ?NCXQ
multiplication
3C8 F2A8
subroutine
16B JNC+2Dh
208 SETF 2
04E C=0 ALL
270 RAMSLCT
038 READDATA
10E A=C ALL
1B8 READ 6(N)
21A C=A+C M
12B JNC+25h
008 SETF 3
04E C=0 ALL
270 RAMSLCT
038 READDATA
10E A=C ALL
1B8 READ 6(N)
31A ?A<C M
013 JNC+02
0BA A<>C M
25A C=A-C M
0D3 JNC+1Ah
04E C=0 ALL
270 RAMSLCT
038 READDATA
10E A=C ALL
1D8 C<>M ALL
266 C=C-1 S&X
270 RAMSLCT
1D8 C<>M ALL
038 READDATA
0AE A<>C ALL
2F0 WRITDATA
0AE A<>C ALL
028 WRIT 0(T)
198 C=M ALL
2E6 ?C#0 S&X
217 JC-3Eh
3CD ?NCGO
GTO the 2nd part of the routine
3C6 F1F3
if no solution has been found yet
00C ?FSET 3
36F JC-13h
20C ?FSET 2
307 JC-20h
30C ?FSET 1
2B7 JC-2Ah
263 JNC-34h
1E8 WRIT 7(O)
LBL 02 Since we can only use 4 subroutine-levels,
CPU-flags are used to avoid ?NCXQ LBL 02
1F8 READ 7(O)
10E A=C ALL
0B0 C=N ALL
0EE B<>C ALL
078 READ 1(Z)
37A ?A#C M
325 ?NCGO
GTO
3C6 F1C9
end1
31A ?A<C M
017 JC+02
0BA A<>C M
33A ?A<B M
037 JC+06
2ED ?NCXQ
quotient-remainder
3C8 F2BB
subroutine
35A ?A#0 M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
1F8 READ 7(O)
10E A=C ALL
078 READ 1(Z)
21A C=A+C M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
1F8 READ 7(O)
10E A=C ALL
078 READ 1(Z)
31A ?A<C M
013 JNC+02
0BA A<>C M
25A C=C-A M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
078 READ 1(Z)
10E A=C ALL
0B8 READ 2(Y)
0AE A<>C ALL
0A8 WRIT 2(Y)
0F8 READ 3(X)
0AE A<>C ALL
0E8 WRIT 3(X)
138 READ 4(L)
0AE A<>C ALL
128 WRIT 4(L)
178 READ 5(M)
068 WRIT 1(Z)
0AE A<>C ALL
168 WRIT 5(M)
198 C=M ALL
27E C=C-1 MS
158 M=C ALL
2FE ?C#0 MS
267 JC-34h
2DC PT=13
150 LD@PT- 5
158 M=C ALL
203 JNC-40h
228 WRIT 8(P)
LBL 03 at the address F125
238 READ 8(P)
10E A=C ALL
0B0 C=N ALL
0EE B<>C ALL
0B8 READ 2(Y)
37A ?A#C M
335 ?NCGO
GTO
3C6 F1CD
end2
31A ?A<C M
017 JC+02
0BA A<>C M
33A ?A<B M
037 JC+06
2ED ?NCXQ
quotient-remainder
3C8 F2BB
subroutine
35A ?A#0 M
171 ?NCXQ
?NCXQ
3C4 F15C
LBL 04
238 READ 8(P)
10E A=C ALL
0B8 READ 2(Y)
21A C=A+C M
171 ?NCXQ
?NCXQ
3C4 F15C
LBL 04
238 READ 8(P)
10E A=C ALL
0B8 READ 2(Y)
31A ?A<C M
013 JNC+02
0BA A<>C M
25A C=A-C M
171 ?NCXQ
?NCXQ
3C4 F15C
LBL 04
0B8 READ 2(Y)
10E A=C ALL
0F8 READ 3(X)
0AE A<>C ALL
0E8 WRIT 3(X)
138 READ 4(L)
0AE A<>C ALL
128 WRIT 4(L)
178 READ 5(M)
0A8 WRIT 2(Y)
0AE A<>C ALL
168 WRIT 5(M)
198 C=M ALL
35C PT=12
262 C=C-1@PT
158 M=C ALL
2E2 ?C#0@PT
277 JC-32h
110 LD@PT- 4
158 M=C ALL
you could add 3CC 3A0 020 ( ?CKEY ?NCRTN
XQ->GO ) after this line to stop the routine by pressing a key
3E0 RTN
but it would change all the following subroutine addresses...
268 WRIT 9(Q)
LBL 04 at the address F15C
278 READ 9(Q)
10E A=C ALL
0B0 C=N ALL
0EE B<>C ALL
0F8 READ 3(X)
37A ?A#C M
345 ?NCGO
GTO
3C6 F1D1
end3
31A ?A<C M
017 JC+02
0BA A<>C M
33A ?A<B M
06F JC+0Dh
2ED ?NCXQ
quotient-remainder
3C8 F2BB
subroutine
35A ?A#0 M
25D ?NCXQ
?NCXQ
3C4 F197
LBL 05
278 READ 9(Q)
10E A=C ALL
0F8 READ 3(X)
2A1 ?NCXQ
multiplication
3C8 F2A8
subroutine
25D ?NCXQ
?NCXQ
3C4 F197
LBL 05
278 READ 9(Q)
10E A=C ALL
0F8 READ 3(X)
21A C=A+C M
25D ?NCXQ
?NCXQ
3C4 F197
LBL 05
278 READ 9(Q)
10E A=C ALL
0F8 READ 3(X)
31A ?A<C M
013 JNC+02
0BA A<>C M
25A C=A-C M
25D ?NCXQ
?NCXQ
3C4 F197
LBL 05
0F8 READ 3(X)
10E A=C ALL
138 READ 4(L)
0AE A<>C ALL
128 WRIT 4(L)
178 READ 5(M)
0E8 WRIT 3(X)
0AE A<>C ALL
168 WRIT 5(M)
198 C=M ALL
19C PT=11
262 C=C-1@PT
158 M=C ALL
2E2 ?C#0@PT
257 JC-36h
0D0 LD@PT- 3
158 M=C ALL
3E0 RTN
2E8 WRIT 11(a)
LBL 05 at the address F197
10E A=C ALL
178 READ 5(M)
37A ?A#C M
1CB JNC+39h
GTO end4
138 READ 4(L)
37A ?A#C M
1B3 JNC+36h
GTO end4
31A ?A<C M
013 JNC+02
0BA A<>C M
1DA A=A-C M
178 READ 5(M)
37A ?A#C M
19B JNC+33h
GTO end5
2F8 READ 11(a)
10E A=C ALL
138 READ 4(L)
15A A=A+C M
178 READ 5(M)
37A ?A#C M
163 JNC+2Ch
GTO end5
2F8 READ 11(a)
10E A=C ALL
0B0 C=N ALL
0EE B<>C ALL
138 READ 4(L)
31A ?A<C M
017 JC+02
0BA A<>C M
33A ?A<B M
04F JC+09
2ED ?NCXQ
quotient-remainder
3C8 F2BB
subroutine
35A ?A#0 M
02F JC+05
10E A=C ALL
178 READ 5(M)
37A ?A#C M
0D3 JNC+1Ah
GTO end5
2F8 READ 11(a)
10E A=C ALL
138 READ 4(L)
2A1 ?NCXQ
multiplication
3C8 F2A8
subroutine
10E A=C ALL
178 READ 5(M)
37A ?A#C M
360 ?C RTN
083 JNC+10h
04E C=0 ALL
end1 address F1C9
2DC PT=13
110 LD@PT- 4
093 JNC+12h
04E C=0 ALL
end2 address F1CD
2DC PT=13
090 LD@PT- 2
06B JNC+0Dh
04E C=0 ALL
end3 address F1D1
23E C=C+1 MS
04B JNC+09
04E C=0 ALL
end4 address F1D4
35C PT=12
210 LD@PT- 8
023 JNC+04
04E C=0 ALL
end5 address F1D8
35C PT=12
110 LD@PT- 4
020 XQ->GO
020 XQ->GO
020 XQ->GO
10E A=C ALL
3B8 READ 14(d)
20E C=A+C ALL
3A8 WRIT 14(d)
130 LDI S&X
009 009
070 N=C ALL
270 RAMSLCT
038 READDATA
26D ?NCXQ
reformat
3C8 F29B
2F0 WRITDATA
0B0 C=N ALL
266 C=C-1 S&X
3C3 JNC-08
2F8 READ 14(d)
26D ?NCXQ
?NCXQ
3C8 F29B
reformat
2E8 WRIT 14(d)
3C1 ?NCGO
Since the 4 subroutine-levels are used,
002 00F0
we must replace 3E0 RTN by these 2 words
198 C=M ALL
2nd part of the search address F1F3
01C PT=3
190 LD@PT- 6
130 LDI S&X
006 006
158 M=C ALL
04E C=0 ALL
35C PT=12
050 LD@PT- 1
10E A=C ALL
3B8 READ 14(d)
20E C=A+C ALL
3A8 WRIT 14(d)
04E C=0 ALL
LBL 12 address F200
270 RAMSLCT
038 READDATA
10E A=C ALL
078 READ 1(Z)
21A C=A+C M
1E8 WRIT 7(O)
10E A=C ALL
1B8 READ 6(N)
31A ?A<C M
017 JC+02
0BA A<>C M
2ED ?NCXQ
quotient-remainder
3C8 F2BB
subroutine
35A ?A#0 M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
04E C=0 ALL
270 RAMSLCT
038 READDATA
10E A=C ALL
078 READ 1(Z)
37A ?A#C M
0A3 JNC+14h
31A ?A<C M
013 JNC+02
0BA A<>C M
25A C=A-C M
1E8 WRIT 7(O)
10E A=C ALL
0B0 C=N ALL
0EE B<>C ALL
1B8 READ 6(N)
31A ?A<C M
017 JC+02
0BA A<>C M
33A ?A<B M
037 JC+06
2ED ?NCXQ
quotient-remainder
3C8 F2BB
subroutine
35A ?A#0 M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
04E C=0 ALL
270 RAMSLCT
038 READDATA
10E A=C ALL
0B0 C=N ALL
0EE B<>C ALL
078 READ 1(Z)
31A ?A<C M
017 JC+02
0BA A<>C M
33A ?A<B M
16F JC+2Dh
2A1 ?NCXQ
multiplication
3C8 F2A8
subroutine
1E8 WRIT 7(O)
10E A=C ALL
1B8 READ 6(N)
31A ?A<C M
013 JNC+02
0BA A<>C M
25A C=A-C M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
1F8 READ 7(O)
10E A=C ALL
1B8 READ 6(N)
21A C=A+C M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
04E C=0 ALL
270 RAMSLCT
038 READDATA
10E A=C ALL
078 READ 1(Z)
31A ?A<C M
017 JC+02
0BA A<>C M
2ED ?NCXQ
quotient-remainder
3C8 F2BB
subroutine
35A ?A#0 M
087 JC+10h
1E8 WRIT 7(O)
10E A=C ALL
1B8 READ 6(N)
21A C=A+C M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
1B8 READ 6(N)
10E A=C ALL
1F8 READ 7(O)
31A ?A<C M
013 JNC+02
0BA A<>C M
25A C=A-C M
095 ?NCXQ
?NCXQ
3C4 F125
LBL 03
078 READ 1(Z)
10E A=C ALL
198 C=M ALL
01C PT=3
262 C=C-1@PT
158 M=C ALL
03C RCR 3
270 RAMSLCT
0EE B<>C ALL
038 READDATA
0AE A<>C ALL
2F0 WRITDATA
0AE A<>C ALL
068 WRIT 1(Z)
0EE B<>C ALL
266 C=C-1 S&X
2E6 ?C#0 S&X
001 ?CGO
?C GTO
3CB F200
LBL 12
04E C=0 ALL
270 RAMSLCT
038 READDATA
10E A=C ALL
198 C=M ALL
266 C=C-1 S&X
158 M=C ALL
270 RAMSLCT
038 READDATA
0AE A<>C ALL
2F0 WRITDATA
0AE A<>C ALL
028 WRIT 0(T)
198 C=M ALL
10E A=C ALL
1BC RCR 11
01C PT=3
102 A=C@PT
0AE A<>C ALL
158 M=C ALL
266 C=C-1 S&X
2E6 ?C#0 S&X
001 ?CGO
?C GTO
3CB F200
LBL 12
04E C=0 ALL
0E8 WRIT 3(X)
3C1 ?NCGO
Since the 4 subroutine-levels are used,
002 00F0
we must replace 3E0 RTN by these 2 words
006 A=0 S&X
To shift the integers in the right part of the mantissa field address
F292
39C PT=0
1A2 A=A-1@PT
366 ?A#C S&X
01B JNC+03
3DA RSHFC M
3E3 JNC-04
046 C=0 S&X
3E0 RTN
2FA ?C#0 M
The reverse operation ( reformating ) address
F29B
3A0 ?NC RTN
130 LDI S&X
009 009
35C PT=12
11A A=C M
342 ?A#0@PT
027 JC+04
266 C=C-1 S&X
3FA LSHFA M
3E3 JNC-04
0BA A<>C M
3E0 RTN
31A ?A<C M
Multiplication routine address
F2A8
013 JNC+02
0AE A<>C ALL
08E B=A ALL
00E A=0 ALL
01C PT=3
2E2 ?C#0@PT
023 JNC+04
13A A=A+B M
262 C=C-1@PT
3E3 JNC-04
3DC PT=PT+1
07A A<>B M
3FA LSHFA M
07A A<>B M
154 ?PT=6
3B3 JNC-0Ah
0AE A<>C ALL
3E0 RTN
23A C=C+1 M
Quotient-Remainder Routine address
F2BB
0EE B<>C ALL
04E C=0 ALL
21C PT=2
3FA LSHFA M
3DC PT=PT+1
33A ?A<B M
3EF JC-03
39A RSHFA M
07A A<>B M
1BA A=A-1 M
222 C=C+1@PT
19A A=A-B M
33A ?A<B M
3EB JNC-03
3BA RSHFB M
3D4 PT=PT-1
214 ?PT=2
3DB JNC-05
3E0 RTN
Address F2CE
-I'm not an expert in M-Code, so the subroutines might certainly be
improved, especially the multiplication subroutine...
3°) Program#2
Data Registers: •
R01 = n1 • R02 = n2 ..........
• R06 = n6 • R07 = N
( these 7 registers are to be initialized before executing "LCEB"
)
R00 & R08 thru R10: temp
Flags: F01 to F07
Subroutines: /
-Lines 02-03 may be replaced by CF 01 CF 02 CF 03
CF 04 CF 05 CF 06 CF 07
-The append character is denoted ~
01 LBL "LCEB"
02 CLX 03 X<>F 04 RCL 07 05 STO N 06 RCL 06 07 STO M 08 RCL 05 09 SIGN 10 RCL 01 11 RCL 02 12 RCL 03 13 RCL 04 14 MYOWNROM 15 X=0? 16 "Nb NOT FOUND" 17 X=0? 18 PROMPT 19 STO 04 20 RDN 21 STO 03 22 RDN 23 STO 02 |
24 X<>Y
25 STO 01 26 LASTX 27 STO 05 28 RCL M 29 STO 06 30 RCL O 31 STO 08 32 RCL P 33 STO 09 34 RCL Q 35 STO 10 36 RCL a 37 STO 00 38 FS? 01 39 GTO 01 40 FS? 02 41 GTO 02 42 FS? 03 43 GTO 03 44 FS? 04 45 GTO 04 46 LBL 05 |
47 RCL 00
48 RCL 05 49 RCL 06 50 XEQ 00 51 LBL 04 52 RCL 10 53 RCL 04 54 RCL 00 55 XEQ 00 56 LBL 03 57 RCL 09 58 RCL 03 59 RCL 10 60 XEQ 00 61 LBL 02 62 FS? 07 63 GTO 07 64 RCL 08 65 RCL 02 66 RCL 09 67 XEQ 00 68 LBL 01 69 RCL 07 |
70 RCL 01
71 RCL 08 72 GTO 00 73 LBL 07 74 RCL 08 75 RCL 01 76 RCL 02 77 XEQ 00 78 RCL 07 79 RCL 08 80 RCL 09 81 LBL 00 82 FIX 0 83 CF 29 84 X<Y? 85 X<>Y 86 STO T 87 X<>Y 88 " " 89 ARCL Y 90 + 91 X=Y? 92 "~+" |
93 X<> T
94 LASTX 95 - 96 X=Y? 97 "~-" 98 X<> T 99 LASTX 100 ST/ T 101 * 102 X=Y? 103 "~*" 104 X<> T 105 X=Y? 106 "~/" 107 ARCL L 108 "~=" 109 ARCL Y 110 FIX 4 111 SF 29 112 PROMPT 113 END |
( 187 bytes / SIZE 011 )
STACK | INPUTS | OUTPUTS |
X | / | / |
Example1: 3 - 7 - 7 - 50 - 1
- 8 // 947
3 STO 01 7 STO 02 STO 03 50 STO 04 1 STO 05 8 STO 06 947 STO 07
XEQ "LCEB" >>>> "50+8=58"
---Execution time = 15s---
R/S
"58*7=406"
R/S
"406*7=2842"
R/S
"2842-1=2841"
R/S
"2841/3=947"
Example2: 4 - 7 - 50 - 1 - 4 - 100 // 903 4 STO 01 ......................... 903 STO 07
XEQ "LCEB" >>>> "100/4=25"
---Execution time = 70s---
R/S "25-7=18"
R/S "50*18=900"
R/S "900-1=899"
R/S 899+4=903"
Example3: 2 - 3 - 4 - 5 - 6 - 7 // 5041 1 STO 01 ........................ 5041 STO 07
XEQ "LCEB" >>>> "Nb NOT FOUND' ---Execution time = 15m27s---
-Here, there is no solution at all since we cannot exceed 5040.
Notes:
-Since the M-Code routine uses synthetic register a, "LCEB" cannot be used as more than a first-level subroutine.
-If the solution involves 1 operation, flag F01 is set. Press XEQ 01
if you want to display it again.
-If the solution involves 2 operations, flag F02 is set. Press XEQ
02 to display it again.
..............................................................................................................................
-If the solution involves 5 operations, flag F05 is set. Press XEQ 05
to display it again.
-Flag F07 is set if the solution has been found in the second part
of the search.
-It may be wise to add the following lines at the beginning of the program:
7
LBL 14
ABS LN
STO IND Z
E4
CLX
INT X>Y?
DSE Z
ENTER^ RCL IND Z
X=0? ACOS
GTO 14
to check that all the data in registers R01 thru R07 are valid.