程式語言 - GNU - Assembly (MIPSEL) - Hello, world!(syscall)



參考資訊:
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

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

    .text
main:
    li $v0, 4004
    li $a0, 1
    la $a1, msg
    li $a2, len
    syscall

    li $v0, 4001
    li $a0, 0
    syscall

NRsyscall namev0arg0(a0)arg1(a1)arg2(a2)
4001exit1int error_code
4004write4unsigned int fdconst char *bufsize_t count

編譯、執行

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