MIPS,如何从控制台获取5个字符串然后将其打印出来

时间:2017-10-24 18:48:07

标签: string assembly mips qtspim

     # Data section
     .data 

insert1:    .word        20     # make space in memory for a word with address insert1              
insert2:    .word        20                 
insert3:    .word        20                 
insert4:    .word        20                 
insert5:    .word        20                     
Input:      .asciiz     "Enter a Series of 5 formulae\n"    
Output:     .asciiz     "The values are:\n"             
CR:     .asciiz     "\n"                    


      # Text Section
     .text 

     .globl my_main


my_main: 

     la $a0, Input
     li $v0, 4 
     syscall        

     la $a0, insert1     # sets $a0 to point to the space allocated for writing a word
     la $a1, insert1     # gets the length of the space in $a1 so we can't go over the memory limit
     li $v0, 8      
     move $t0, $a0      
     syscall        

     la $a0, insert2 
     la $a1, insert2     
     li $v0, 8              
     li $v0, 8      
     move $t1, $a0      
     syscall        

     la $a0, insert3
     la $a1, insert3     
     li $v0, 8      
     li $v0, 8 
     move $t2, $a0
     syscall        

     la $a0, insert4
     la $a1, insert4    
     li $v0, 8              
     li $v0, 8 
     move $t3, $a0
     syscall 

     la $a0, insert5
     la $a1, insert5     
     li $v0, 8      
     li $v0, 8 
     move $t4, $a0
     syscall 

    la $a0, Output 
    li $v0, 4 
    syscall 

    la $a0, insert1 
    li $v0, 4 
    syscall 


    la $a0, insert2 
    li $v0, 4   
    syscall 


    la $a0, insert3 
    li $v0, 4   
    syscall 


    la $a0, insert4 
    li $v0, 4 
    syscall 


    la $a0, insert5 
    li $v0, 4 
    syscall 


    # Exits Program
    li $v0, 10 
    syscall 

结果我得到了:

Enter a Series of 5 formulae:
hey
man
how
are
you
The values are:
hey
man
how
are
you
man
how
are
you
how 
are 
you
are 
you
you

我想要的结果:

Enter a Series of 5 formulae:
hey
man
how
are
you
The values are:
hey 
man
how
are
you

所以基本上我需要从控制台取5个字符串然后打印出来,如上所示。奇怪的是,当我使用只有1个字母长的单词时,它会正确打印出来,但除了单个字母之外的任何其他内容都会返回一系列类似于我上面所示的单词。我是MIPS的新手,不知道我在这里做错了什么。任何帮助将不胜感激。

编辑:我似乎只需要使用.space而不是.word。感谢那些评论/回答帮助问题的人。

0 个答案:

没有答案