This is a rather inefficient way to do things, with all the repeated calls to writeByte. A smaller way is to use a fixed size array, assigning the values to the array, then passing the array in one call to buf->write():
```
unsigned char code[11];
unsigned char* p = &code[0];
code[0] = 0x50 + BP;
if (I64)
{   code[1] = REX | REX_W;
    ++p;
}
p[1] = 0x8B;
p[2] = modregrm(3,BP,SP);
if (align)
{
    if (I64)
    {
       p[3] = REX | REX_W;
        ++p;
    }
    p[3] = 0x81;
    ... etc ...
}
buf->write(code, p - code + 3);