如何使用ascii在MIPS32中正确提示输入

时间:2013-07-23 00:31:54

标签: assembly mips32

这是我的代码。我希望它输出“嗨,输入这里:”。但相反,它会打印“Hi,input here:”和“Hello,input here:”。我该如何解决这个问题?

            .data
str_one:        .ascii      "Hi, input here: \n" 
str_two:        .ascii      "Hello, input here: \n" 

            .text

main:       

    li $v0, 9           #memory allocation syscall
    li $a0, 12
    syscall

    move $s0, $v0          

    li $v0, 4
    la $a0, str_one        #Prompt string
    syscall

    li $v0, 8          #Read string
    la $a0, ($s0)
    li $a1, 8
    syscall

1 个答案:

答案 0 :(得分:1)

您没有空终止字符串。请改用.asciiz

str_one:        .asciiz      "Hi, input here: \n" 
str_two:        .asciiz      "Hello, input here: \n" 

或者,使用明确的零:

str_one:        .ascii      "Hi, input here: \n" 
                .byte       0
str_two:        .ascii      "Hello, input here: \n" 
                .byte       0