Assembly 在MIPS中打印后跟字符串的变量

Assembly 在MIPS中打印后跟字符串的变量,assembly,mips,Assembly,Mips,我正在写一个MIPS程序,询问你的名字,然后打印出一行“你好吗?”?但是我的代码 #Program that fulfills the requirements of COS250 lab 1 #Nick Gilbert .data #Section that declares variables for program firstPromptString: .asciiz "What is your name: " secondPromptString: .asciiz "

我正在写一个MIPS程序,询问你的名字,然后打印出一行“你好吗?”?但是我的代码

#Program that fulfills the requirements of COS250 lab 1
#Nick Gilbert

.data #Section that declares variables for program
firstPromptString:  .asciiz     "What is your name: "
secondPromptString: .asciiz     "Enter width: "
thirdPromptString:  .asciiz     "Enter length: "

name:           .space      20

firstOutStringOne:     .asciiz     "Hi "
firstOutStringTwo:  .asciiz     ", how are you?"
secondOutString:        .asciiz     "The perimeter is ____"
thirdOutString:     .asciiz     "The area is _____"

.text #Section that declares methods for program
main:
    #Printing string asking for a name
        la $a0, firstPromptString #address of the string to print
        li $v0, 4 #Loads system call code for printing a string into $v0 so syscall can execute it
        syscall #call to print the prompt. register $v0 will have what syscall is, $a0-$a3 contain args for syscall if needed

        #Prompting user for response and storing response
        la $a0, name
        li $v0, 8 #System call code for reading a string
        li $a1, 20
        syscall

        #Printing response to name
        la $a0, firstOutStringOne
        li $v0, 4 #System call code for printing a string
        syscall

        la $a0, name
        li $v0, 4 #System call code for printing a string
        syscall

        la $a0, firstOutStringTwo
        li $v0, 4 #System call code for printing a string
        syscall

在单独的行上打印“你好”和“你好”。我需要将消息放在一行

据我所知,
'\n'
(新行)来自用户输入。
程序打印出
“您的名字是什么:”
,用户键入自己的名字,然后按回车键输入。这将在缓冲区中的名称后放置一个
'\n'
。当随后打印缓冲区时,将使用它打印换行符。为防止出现这种情况,需要将
'\n'
替换为
'\0'
,即字符串终止符。因此,您需要像
memchr()
strchr()
这样的函数来查找
'\n'
并替换它。

是的。由于您可能无法访问这些现成的函数,因此可以编写一个简单的例程来实现您想要的功能:对于字符串中的每个字符,如果它是=='0',则转到结束;如果为=='\n',则将其替换为“0”并转到结束;否则,递增指针并转到下一次迭代。