Hi,
Inspired by another member here to write the 8-Queens problem for the HP41 in MCODE and add this to the Benchmark I used a sprained ankle to do just that. Below you find the MCODE which models as closely as possible the Basic code. Runn-time 11.05 seconds on my normal speed CX. For a reference, the RPN version runs 17+ minutes...
I used a very simple program and the 41cx internal clock to time this so the 11.05s have a tiny bit of RPN overhead for the timing program. If there is a better way to time the actual code, please let me know.
Would be great if that can be added to the great Benchmark article on calculator speed.
Cheers
Peter
;-----------------------------------------------------------------------------------------------------------------------
; 8 queens problem - calc benchmark
; modelled after the BASIC version printed
; X = M
; Y = N
; A() is RAM-Regs 1-9 (Stack + Alpha)
;S = Q
;-----------------------------------------------------------------------------------------------------------------------
.NAME "CQ2"
*0078 0B2 #0B2 ; "2"
*0079 011 #011 ; "Q"
*007A 003 #003 ; "C"
007B 1A0 [CQ2] A=B=C=0 ;
007C 158 M=C ;initialize
007D 070 N=C ;initialize
007E 268 WRIT 9(Q) ;initialize
007F 228 WRIT 8(P) ;initialize
0080 1E8 WRIT 7(O) ;initialize
0081 1A8 WRIT 6(N) ;initialize
0082 168 WRIT 5(M) ;initialize
0083 128 WRIT 4(L) ;initialize
0084 0E8 WRIT 3(X) ;initialize
0085 0A8 WRIT 2(Y) ;initialize
0086 068 WRIT 1(Z) ;initialize
0087 2A0 SETDEC
0088 198 [L40_2] C=M
0089 0A6 A<>C S&X
008A 130008 LDIS&X 008 ;
008C 366 ?A#C S&X
008D 093 JNC [SL180_2] +18 009F ;If X=8 Then 180
;--------
008E 198 [L50_2] C=M ;
008F 226 C=C+1 S&X
0090 158 M=C ;X=X+1
;--------
0091 198 [L60_2] C=M
0092 270 RAMSLCT
0093 130008 LDIS&X 008
0095 2F0 WRITDATA ;A(x) = 8
;--------
0096 278 [L70_2] READ 9(Q)
0097 22E C=C+1 ALL
0098 268 WRIT 9(Q) ;S=S+1
;--------
0099 198 [L80_2] C=M ;
009A 070 N=C ; Y=X
;--------
009B 0B0 [L90_2] C=N
009C 266 C=C-1 S&X
009D 070 N=C ;Y=Y-1
;----------------------------- Stepping Stone
009E 013 JNC [L100_2] +2 00A0
009F 12B [SL180_2] JNC [L180_2] +37 00C4
;----------------------------- Stepping Stone
00A0 0B0 [L100_2] C=N
00A1 2E6 ?C#0 S&X
00A2 333 JNC [L40_2] -26 0088 ;if Y=0 then GOTO 40
;--------
00A3 198 [L110_2] C=M ;get A(x)
00A4 270 RAMSLCT
00A5 038 READDATA ;
00A6 0A6 A<>C S&X ;A(x)
00A7 0B0 C=N
00A8 270 RAMSLCT
00A9 038 READDATA ;A(y)
00AA 246 C=A-C S&X ;T = A(x) - A(y)
00AB 013 JNC (c6_2) +2 00AD
00AC 286 C=0-C S&X ;complement if underflow
00AD 2E6 (c6_2) ?C#0 S&X ;if T=0
00AE 04B JNC [L140_2] +9 00B7 ;then goto 140
;--------
00AF 0E6 C<>B S&X ;save abs(T)
00B0 198 [L130_2] C=M
00B1 0A6 A<>C S&X
00B2 0B0 C=N
00B3 1C6 A=A-C S&X ;X-Y
00B4 0E6 C<>B S&X ;get abs(T)
00B5 366 ?A#C S&X ;if X-Y <> abs(T)
00B6 32F JC [L90_2] -27 009B ;then goto 90
;--------
00B7 198 [L140_2] C=M
00B8 270 RAMSLCT
00B9 038 READDATA
00BA 266 C=C-1 S&X
00BB 2F0 WRITDATA ;A(x) = A(X) -1
;--------
00BC 2E6 [L150_2] ?C#0 S&X ;if A(x) <>0
00BD 2CF JC [L70_2] -39 0096 ;then goto 70
;--------
00BE 198 [L160_2] C=M
00BF 266 C=C-1 S&X
00C0 158 M=C ;X=X-1
;--------
00C1 198 [L170_2] C=M
00C2 2E6 ?C#0 S&X ;if x <>0
00C3 3A7 JC [L140_2] -12 00B7 ;then goto 140
;--------
00C4 35C [L180_2] R= 12
00C5 278 READ 9(Q)
00C6 2FC (c8_2) RCR 13 ;=LSHFT 1
00C7 2E2 ?C#0 @R
00C8 3F3 JNC (c8_2) -2 00C6
00C9 0E8 WRIT 3(x)
00CA 3E0 RTN
;--------
;------------------------------------------------------------------------------------------------------------------