User guide
200 CHAPTER 11. THE MC PACKAGE
11.4 MC Debugging Aids
The primary debugging aid is to inspect the generated code and the is controlled by
the DEBUG directive which sets the t r aci ng level held in the global variable mcDebug.
Assuming bimc are the least significant four bit of mcDebug, if c = 1, print comments
compiled by mcComment. If m = 1, print MC instructions and directives. If i = 1, print
the corresponding target instruction(s) and if b = 1, print the resulting binary code in
hexadecimal. To fully understand this ou tpu t it is, of course, necessary to have a good
understanding of the target architecture being used.
A second important debugging aid is provided by the mcPRF function whi ch compiler
code to output the value of a specified register using a given printf format string. On
return all registers including the condition co de are preserved. A typical call of mcPRF
is as f ol l ows.
mcPRF("The value of register A is %8x*n", mc_a)
As an aid to d ebu ggi ng MC packages themselves, there is a test program called
bcplprogs/mc/mcsystest.b which systematically tests all MC instructions, directives
and addressing mode s generating error messages for each error found. Each such error
message includes a test number which helps to locate the source of the of the problem.
If mcsystest is given a test number as argument, it provides a detailed compilati on
trace of the specified test. This should provide sufficient information to locate the error
in the package.
11.5 The n-queens Demonstration
This section shows how the algorithm to solve the n-queens problem as described in
Section 13.3 on page 214 can be reimplemented using the MC package. The MC version
of the program is as follows.
GET "libhdr"
GET "mc.h"
MANIFEST {
// Register mnemonics
ld = mc_a
col = mc_b
rd = mc_c
poss = mc_d
p = mc_e
count = mc_f
}
LET start() = VALOF
{ // Load the dynamic code generation package
LET argv = VEC 50
LET lo, hi, dlevel = 1, 16, #x0000
LET mcname = "mci386" // Default setting
LET mcseg = 0
LET mcb = 0