Tool to generate BYTE sequences for Go assembly as generated by YASM.
Make sure YASM is installed on your platform. Get the code and compile with go install
.
usage: -h help -w write back to the file
$ more example.s
// @ VPADDQ XMM0,XMM1,XMM8
$ asm2plan9s -w example.s
$ echo example.s
LONG $0xd471c1c4; BYTE $0xc0 // @ VPADDQ XMM0,XMM1,XMM8
The instruction to be assembled needs to start with a // @
The preceding characters will be overwitten by the correct sequence (irrespective of its contents) so when changing the instruction, rerunning asm2plan9s
will update the BYTE sequence generated.
Macro definitions will be preserved, so #define macro // @ VZEROUPPER
won't overwrite the #define macro
portion.
If you are using #define for 'macros' with the back-slash delimiter to continue on the next line, this will be preserved.
For instance:
\ // @ VPADDQ XMM0,XMM1,XMM8
will be assembled into
LONG $0xd471c1c4; BYTE $0xc0 \ // @ VPADDQ XMM0,XMM1,XMM8
Instructions can be in Intel or GoAsm format. So, both of these lines will assemble to the same byte code:
// @ VFMADD123PD xmm1, xmm0, [rax]
// @ VFMADD123PD X0, (AX), X1
Becomes:
LONG $0x98f9e2c4; BYTE $0x08 // @ VFMADD123PD xmm1, xmm0, [rax]
LONG $0x98f9e2c4; BYTE $0x08 // @ VFMADD123PD X0, (AX), X1
Assembled code will be formatted with asmfmt.
To run assembler and formatter on save, add a hook in your init file:
(defun asm-mode-setup ()
(set (make-local-variable 'gofmt-command) "asm2plan9s")
(add-hook 'before-save-hook 'gofmt nil t)
)
(add-hook 'asm-mode-hook 'asm-mode-setup)
For a more extensive example see compressAvx_amd64.s