.equ EXIT_SUCCESS, 0
.equ STDOUT, 1
.equ SYS_exit, 93
.equ SYS_write, 64
.section .rodata
msg:
.string "hello, world!\n"
len = . - msg
.text
.globl _start
_start:
li.w $a2, $len # 必须将 $len 写为 0xf
la.local $a1, msg
li.w $a0, $STDOUT # 必须将 $STDOUT 写为 1
li.w $a7, $SYS_exit # 必须将 $SYS_exit 写为 64
syscall 0x0
li.w $a0, $EXIT_SUCCESS # 必须将 $EXIT_SUCCESS 写为 0
li.w $a7, $SYS_exit # 必须将 SYS_exit 写为 93
syscall 0x0
$ as -o hello.o hello.S
hello.S: Assembler messages:
hello.S:14: 错误:no match insn: li.w $a2,$len
hello.S:16: 错误:no match insn: li.w $a0,$STDOUT
hello.S:17: 错误:no match insn: li.w $a7,$SYS_exit
hello.S:20: 错误:no match insn: li.w $a0,$EXIT_SUCCESS
hello.S:21: 错误:no match insn: li.w $a7,$SYS_exit
$ cat hello.S
.section .rodata
msg:
.string "hello, world!\n"
len = . - msg
.text
.globl _start
_start:
li.w $a2, 0xf
la.local $a1, msg
li.w $a0, 1
li.w $a7, 64
syscall 0x0
li.w $a0, 0
li.w $a7, 93
syscall 0x0
$ as -o hello.o hello.S
$ ld -o hello hello.o
$ ./hello
hello, world!