參考資訊:
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
NR | syscall name | a7 | arg0(a0) | arg1(a1) | arg2(a2) |
---|---|---|---|---|---|
64 | write | 4 | unsigned int fd | const char *buf | size_t count |
93 | exit | 1 | int error_code |
編譯、執行
$ riscv64-linux-gnu-gcc main.s -o main -static -nostdlib $ qemu-riscv64 ./main hello, world!