Significant refactoring of the inline asm stuff, to support future changes.