To the MCODE gurus

There seems to be an interesting discrepancy between the behavior of MCODE in the 41 (currently using a HEPAX) and in SDK41. Given that the SDK41 uses the original roms, this surprised me.

Even more surprised am I that the instruction *C=-C-1 MS * can create a carry with a very benign positive number in C (MS=0). The code below runs as shown in SDK41 and produces for 100 in x-reg the correct value of 71. However when run within an MLDL it produces -29 as the *?NCXQ in line x11F and x124 *are not run. If I insert a NOP infront of them the code runs in the MLDL as well, producing the correct result.

Please see the code snippet below (the code does not do anything useful, it’s a preamble to a Prime-Twin generator, my usual way of learning a new language). Any thoughts with regards to

- How C=-C-1 for a benign positive number can set the carry

- Difference between SDK41 and MLDL

Thanks so much !

Cheers

Peter

;calculate startvalue for search for prim-twins

;given a number in X, startvalue = 30*Int((X+19)/30) – 19

;implemented as (X+19) – (X+19)Mod30 -19

Add HexCode Command Comment

x107 2A0 SetDec

x108 1A0 A=B=C=0

x109 35C R=12 ;load 19 into C

x10A 050 LD@R 1

x10B 250 LD@R 9

x10C 226 C=C+1 S&X

x10D 070 N=C All ;save for later use

x10E 10E A=C All ;prepare regs for AD2_10

x10F 0F8 Read 3(x)

x110 01D060 ?NCXQ [AD2_10] ;this one works fine

x112 10E A=C All ;A=X+19

x113 158 M=C All ;save in M for later

x114 04E C=0 All ;Load 30 into C to prep for [MOD10]

x115 35C R=12

x116 0D0 LD@R 3

x117 226 C=C+1 S&X

x118 171064 ?NCXQ [MOD10] ;A Mod C

x11A 0EE B<>C ;prep for subtraction via AD2_10

x11B 198 C=M All ;recall X+19

x11C 10E A=C All

x11D 0CE C=B All ;(X+19) Mod 30

x11E 2BE C=-C-1 MS ;This should simply make it negative. But it sets Carry!!

x11F 01D060 ?NCXQ [AD2_10] ;this only works if I have a NOP in front to clear carry when run in MLDL

;it calcs (X+19) – (X+19)Mod30

x121 10E A=C All ;prep to subtract 19

x122 0B0 C=N All ;recall 19 from N

x123 2BE C=-C-1 ;same problem it sets carry when run in MLDL

x124 01D060 ?NCXQ [AD2_10]

x126 0E8 WRIT 3(x) ;save result to x

x127 3E0 RTN