User guide

Chapter 11
The MC Package
This chapt er describes the MC package which provides a machine independent way to
generate and execut e native machine code at runtime. The work on this package started
in January 2008 and is still under development, however, it currently works well enough
to run the n-queens problem on i386 machines about 24 times faster than the normal
Cintcode interpretive version. MC package development is performed in the directory
BCPL/bcplprogs/mc/ and fairly stable versions are copied to BCPL/cintcode/g/mc.h,
BCPL/cintcode/com/mci386.b and BCPL/cintcode/cin/mci386 which can be used
from any working directory. Currently the MC package does not have any floating
point operations. This will be rect i fie d in due course.
The package is based on a simple machine independent abstract machine co d e
called MC which is easily translated into machine instructions for most architectures.
Although native code is generated by MC calls such as mcRDX(mc
add, mc b, 20,
mc
d), MC has a corresponding assembly language to assist debugging. The assembly
form of the instr uc ti on generated by the previous call is ADD B,20(D) meaning set
register B to the sum of B and the contents of the memory location whose address is 20
plus the value of regis te r D. MC instructions are fairly low level and typically translate
into single native code instructions for most architectures. This exampl e translates into
the i386 GNU statement: addl 20(%edx),%ebx.
The first operand is the destination for any instr u ct i on that updates a regi s-
ter or memory l ocation. Thus assignments are always from right to left as in
most programming lan guages but unlike many assembly codes where, for instance,
movl 20(%edx),%ebx updates the second operand.
The MC machine has six registers A, B, C, D, E and F that are directly available
to the programmer, and also a pr ogr am counter, stack pointer, stack frame pointer and
a condition code register, although these cannot be accessed explicitly.
11.1 MC E xa m pl e
The following program is a simple demonstration of the i386 version of the MC package.
GET "libhdr"
GET "mc.h"
187