我目前正在我的大学学习 MARS 模拟器的 MIPS 编程。但是,我想尝试学习为 MIPS Linux 虚拟机编写 MIPS 汇编程序。我设法创建了一个 MIPS32 Debian 11 虚拟机。但是,我在 Linux 内核系统调用及其参数方面遇到了麻烦。经过一些困惑,并在互联网上搜索了很长时间,我设法创建了一个基本的 hello world 程序。然后,我尝试创建一个程序,要求用户输入一些文本,然后将其打印出来,但它不起作用。
我期待这样的事情:
Please enter a string: This is text
The input is: This is text
然而,我得到:
Please enter a string: This is text
The input is:
我的密码是:
.data
prompt: .asciiz "Please enter a string: "
promptLength: .quad . - prompt
input: .space 81 #Create a 80-character empty string
inputLength: .word 80
answer: .asciiz "The input is: "
answerLength: .quad . - answer
newline: .asciiz "\n"
.text
.globl __start
__start:
#Display the prompt
li $a0, 1
la $a1, prompt
lw $a2, promptLength
li $v0, 4004
syscall
#Read the input
li $a0, 1
la $a1, input
lw $a2, inputLength
li $v0, 4003
syscall
move $s0, $v0
#Write the user input
li $a0, 1
la $a1, answer
lw $a2, answerLength
li $v0, 4004
syscall
la $a1, input
move $a2, $s0
syscall
#Exit
b exit
printNewline:
li $a0, 1
li $a1, newline
li $a2, 1
li $v0, 4004
syscall
jr $ra
exit:
li $v0, 4001
syscall
附言。有没有教 Linux 的 MIPS 编程的书/YouTube 教程/网站?