Skip to content

Instantly share code, notes, and snippets.

@halferty
Created February 10, 2020 23:38
Show Gist options
  • Save halferty/267b30874a5253a20b9cc5ee2fd99175 to your computer and use it in GitHub Desktop.
Save halferty/267b30874a5253a20b9cc5ee2fd99175 to your computer and use it in GitHub Desktop.
Disassembles a single RISCV opcode in hex string format
#!/usr/bin/env ruby
# opcode = "00162023"
opcode = ARGV[0]
`echo ".text;.word 0x#{opcode}" > ~/tmp/test.S`
`$RISCV/bin/*gcc -c ~/tmp/test.S -o ~/tmp/test.o 2> /dev/null`
res = `$RISCV/bin/*objdump -d ~/tmp/test.o 2> /dev/null`
puts res.split(/\n/).last.split(/\t/)[2..-1].join(" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment