帮助修剪字符串输入它的返回字符MIPS

时间:2010-12-04 01:51:58

标签: string 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: "

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

2 个答案:

答案 0 :(得分: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

删除newLine字符:)

答案 1 :(得分:0)

浏览包含播放器名称的字符串,直到找到空字符。存放该位置。然后在pos-1处放置一个空字符。 (我想你也必须把它放在pos-2上,因为换行有时候是两个不同的字符。)