Skip to content

Latest commit

 

History

History

linux

RISC-V (RV64G) assembly examples on linux

Examples

How to try

  • Assemble (generate binary)

    $ make -f ../Makefile  <sample>
    
  • Execute

    $ ./<sample>
    or
    $ qemu-riscv64 ./<sample>
    
  • Disassemble (for full object)

    $ make -f ../Makefile  <sample>.disasm  | less
    (search "main>" in `less` command)
    
  • Disassemble (for .S only)

    $ make -f ../Makefile  <sample>.o.disasm
    
  • Step execution with gdb

    $ make -f ../Makefile  <sample>
    $ gdb ./<sample>
    (gdb) layout asm
    (gdb) layout regs
    (gdb) break main
    (gdb) run
    (gdb) stepi
      :
    (gdb) quit
    
    
  • Step execution with qemu and gdb

    • on first terminal for qemu:
    $ qemu-riscv64 -g 1234 ./<sample>
    
    • on second terminal for gdb:
    $ riscv64-unknown-linux-gnu-gdb ./<sample>
    (gdb) layout asm
    (gdb) layout regs
    (gdb) target remote localhost:1234
    (gdb) break main
    (gdb) continue
    (gdb) stepi
      :
    (gdb) quit
    

References

Further information

Calling convention

  • System call

    • a7, a0, a1, a2, a3, a4, a5 -> a0, a1
  • Funcation call

    • a0, a1, a2, a3, a4, a5, a6, a7 -> a0, a1
  • see:

Tool installation on ubuntu (x86)