.file "hello.c"
.option nopic
.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
.attribute unaligned_access, 0
.attribute stack_align, 16
.text
.section .rodata
.align 3
.LC0:
.string "Hello, world!"
.text
.align 1
.globl main
.type main, @function
main:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
lui a5,%hi(.LC0)
addi a0,a5,%lo(.LC0)
call puts
li a5,0
mv a0,a5
ld ra,8(sp)
ld s0,0(sp)
addi sp,sp,16
jr ra
.size main, .-main
.ident "GCC: (GNU) 10.2.0"
$RISCV/newlib/bin/riscv64-unknown-elf-g++ hello.s -o hello
$RISCV/llvm/bin/clang --target=riscv64-unknown-elf -march=rv64gc --sysroot=$RISCV/newlib/riscv64-unknown-elf --gcc-toolchain=$RISCV/newlib hello.s -o hello
可以看到生成了hello
可执行程序。
$RISCV/qemu/bin/qemu-riscv64 hello
$RISCV/newlib/bin/spike $RISCV/newlib/riscv64-unknown-elf/bin/pk hello
恭喜,至此,已经成功运行了你的第一个RISC-V程序!