2010-12-04 77 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 

刪除換行符:)