As it happens, Paul Khuong has just written about a very similar topic. He uses sb-assem
to emit code for a simple stack machine.
The machinery is SBCL specific, and you might have trouble figuring out how to use sb-assem
, but it could be worth a look.