Saving Copy and Paste With ob-rasm2
At the beginning of 2022 I thought it would be a good idea to learn assembly, specfically ARM assembly. Like any good Emacs user I'm taking my notes in org-mode
and I wanted to reduce the amount of copy and paste from the terminal to Emacs. I already use vterm
and asm-mode
to assemble my code, but I wanted to have that inline with my notes. So i started to look around.
Rasm2
Rasm2 is part of the radare2 framework, and assembles and disassembles files or hexpair strings without having to open r2
. After installing radare2 we can execute rasm2
to quickly assemble and disassemble strings.
rasm2 -a arm -b 64 "mov x2, xzr"
e2031faa
And the reverse.
rasm2 -a arm -b 64 -d e2031faa
mov x2, xzr
This is great and excatly what I want for learning, but it would be nicer if it was more inline. The command never really changes, and I wonder if I can do better.
Org Babel
The code blocks above are ran by using org babel with shell-mode. Under the hood, it executes whats in the src
bock and then displays the results in the buffer. Now, if I could have the rasm2
command above as a snippet then it would save me a lot of repitition, but I can do one better.
My research into linking rasm2
to org babel led me to this post. The author actually provides the code to make this work, however there is a problem. When I edit code blocks in org-mode
I like to enter a temprary buffer with C '
, with the code from the post I get an error that no such language: rasm2-mode. This means that there is no C '
for me.
ob-rasm2
Tidying up the code and googling around a bit, I ended up with ob-rasm2, and adding (add-to-list 'org-src-lang-modes '("rasm2" . asm))
allows editiing with C '
by tricking org-mode
in thinking that your editing in asm
. All thats left to do is show the same example above :).
mov x2, xzr
\xe2\x03\x1f\xaa
And the reverse.
e2031faa
mov x2, xzr