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



參考資訊:
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 main
    .extern printf
 
    .data
msg: .asciz "hello, world!\n"
 
    .text
main:
    add sp, sp, -4
    sw ra, 0(sp)
 
    la a0, msg
    jal printf
 
    lw ra, 0(sp)
    add sp, sp, 4
    jr ra

編譯、執行

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