Rubi of tony0620emma

DynASM (dynamic assembler)

Tool-chain Features
  • Pre-processing assembler, converts mixed C/ASM code into plain C
  • Generated C code is extremely small and fast
  • Tiny embeddable C library to help assembling, relocating, and linking
  • No outside dependencies with other tools
  • CPU-specific modules
  • Pre-processing is machine independent
Assembler Features
  • Can freely mix C code and assembly code
  • Local and global labels
  • Macros can mix assembler statements and C codes
  • Currently only support for "x86, x64, ARM, powerPC, MIPS"
  • Simple case conversion
before : 
if (ptr != NULL) {
    |  mov eax, foo+17
    |  mov edx, [eax+esi*2+0x20]
    |  add ebx, [ecx+bar(ptr, 9)]
after : 
if (ptr != NULL) {
    dasm_put(Dst, 123, foo+17, bar(ptr, 9));
Lua is taking care of pre-processing, so there will be no dependencies when the code is in action
and the lines start with pipe | is for dynasm
123 holds the offset in the action list buffer, but, what is the action list ?
  • Action List : 
  • The embedded C library implements the byte code engine, then takes the action list as input, and outputs the machine code

Unofficial Documentation of DynASM

Ground Work
  • include
  • first, we need to include the dynasm header dasm_proto.h and dasm_x86.h 
  • where dasm_proto.h contains the API and dasm_x86.h implements it
  • variables
  • we need a variable of type dasm_State * to hold the state of dynasm
  • two extra variables of type unsigned int