I need the same job and find the way. I am sharing that maybe others can benefit.
First, you should have riscv-gnu-toolchain to make the compilation and decompilation process. It can be found here.
The instructions that you mentioned are assembly. So, you can compile by riscv64-unknown-elf-as
and disassemble by riscv64-unknown-elf-objdump
. The instructions used to get hex are below.
omerguzel@omerguzel-HP:~/temp$ ls
code
omerguzel@omerguzel-HP:~/temp$ cat code
addi x1,x2,123
nop
xor x3,x2,x1
omerguzel@omerguzel-HP:~/temp$ /opt/riscv/bin/riscv64-unknown-elf-as code
omerguzel@omerguzel-HP:~/temp$ /opt/riscv/bin/riscv64-unknown-elf-objdump -D --section .text a.out
a.out: file format elf64-littleriscv
Disassembly of section .text:
0000000000000000 <.text>:
0: 07b10093 add ra,sp,123
4: 00000013 nop
8: 001141b3 xor gp,sp,ra
omerguzel@omerguzel-HP:~/temp$
you can extract the hex part yourself by using scripts.
**
Second Method:
**
The other way is implemented by using other compiler tools. The commands are below.
omerguzel@omerguzel-HP:~/temp$ ls
code
omerguzel@omerguzel-HP:~/temp$ cat code
addi x1,x2,123
nop
xor x3,x2,x1
nop
omerguzel@omerguzel-HP:~/temp$ /opt/riscv/bin/riscv64-unknown-elf-as code
omerguzel@omerguzel-HP:~/temp$ /opt/riscv/bin/riscv64-unknown-elf-objcopy -O binary a.out a.bin --strip-debug
omerguzel@omerguzel-HP:~/temp$ od -t x4 -An -w4 -v a.bin
07b10093
00000013
001141b3
00000013
omerguzel@omerguzel-HP:~/temp$