GET "libhdr.h" GET "mc.h" MANIFEST { lo=1; hi=16 dlevel=#b0000 // Register mnemonics ld = mc_a row = mc_b rd = mc_c poss = mc_d p = mc_e count = mc_f } LET start() = VALOF { // Load the dynamic code generation package LET mcseg = globin(loadseg("mci386")) LET mcb = 0 UNLESS mcseg DO { writef("Trouble with MC package: mci386*n") GOTO fin } // Create an MC instance for hi functions with a data space // of 10 words and code space of 40000 mcb := mcInit(hi, 10, 40000) UNLESS mcb DO { writef("Unable to create an mci386 instance*n") GOTO fin } mc := 0 // Currently no selected MC instance mcSelect(mcb) mcK(mc_debug, dlevel) // Set the debugging level FOR n = lo TO hi DO { mcComment("*n*n// Code for a %nx%n board*n", n, n) gencode(n) // Compile the code for an nxn board } mcF(mc_end) // End of code generation writef("Code generation complete*n") FOR n = lo TO hi DO { LET k = mcCall(n) writef("Number of solutions to %i2-queens is %i9*n", n, k) } fin: IF mc DO mcClose() IF mcseg DO unloadseg(mcseg) writef("*n*nEnd of run*n") } AND gencode(n) BE { LET all = (1<>1) mcRR(mc_add, ld, p) mcRK(mc_lsh, ld, 1) // ld := (ld+p)<<1 mcRR(mc_add, row, p) // row := row+p mcRR(mc_add, rd, p) mcRK(mc_rsh, rd, 1) // rd := (rd+p)>>1 cmpltry(i+1, n, all) // Compile code for row i+1 mcR (mc_pop, poss) // Restore the state mcR (mc_pop, rd) mcR (mc_pop, row) mcR (mc_pop, ld) mcRK(mc_cmp, poss, 0) mcJL(mc_jne, M) // } REPEATWHILE poss } mcL(mc_lab, L) mcComment("// End of code from try(%n, %n, %n)*n*n", i, n, all) }