2010-12-04 36 views
1

我正在用MIPS编写一个游戏,并采用了玩家的名字。当我尝试打印这样的:帮助修剪它的返回字符的字符串输入MIPS

li $v0, 4 
la $a0, playerName 
syscall 

li $v0, 4 
la $a0, strEnd  #strEnd = ("'s Hand: ") 
syscall 

所以我希望它显示:

"playerName's Hand: " 

一切都不会出现在同一行。我反而得到:

"playerName 
's Hand: " 

我的问题是如何从我接受的名称中删除新行字符?谢谢

+1

哇,在MIPS一场比赛,最好的受虐狂 – user472875 2010-12-04 02:03:58

回答

0

检查包含播放器名称的字符串,直到您到达空字符。存储该位置。然后在pos-1处放置一个空字符。 (我想你必须把它放在POS-2为好,因为换行有时是2个独立的字符。)

1
# Your code to take a player's name 

    li $s0,0    # Set index to 0 
remove: 
    lb $a3,word($s0)  # Load character at index 
    addi $s0,$s0,1  # Increment index 
    bnez $a3,remove # Loop until the end of string is reached 
    beq $a1,$s0,skip  # Do not remove \n when it isn't present 
    subiu $s0,$s0,2  # Backtrack index to '\n' 
    sb $0, word($s0)  # Add the terminating character in its place 

删除换行符:)