程式語言 - GNU - Assembly (RISC-V 64) - Hello, world!(ecall)



參考資訊:
https://smist08.wordpress.com/2019/09/07/risc-v-assembly-language-hello-world/
https://chromium.googlesource.com/chromiumos/docs/+/HEAD/constants/syscalls.md
https://teaching.basilico.di.unimi.it/lib/exe/fetch.php/pub/debian-mips-tutorial.pdf

main.s

    .global _start

    .data
msg: .asciz "hello, world!\n"
len = . - msg

    .text
_start:
    li a7, 64
    li a0, 1
    la a1, msg
    li a2, len
    ecall

    li a7, 93
    li a0, 0
    ecall

NRsyscall namea7arg0(a0)arg1(a1)arg2(a2)
64write4unsigned int fdconst char *bufsize_t count
93exit1int error_code

編譯、執行

$ riscv64-linux-gnu-gcc main.s -o main -static -nostdlib
$ qemu-riscv64 ./main
    hello, world!