【问题标题】:Finding a character of a string in MIPS在 MIPS 中查找字符串的字符
【发布时间】:2013-01-24 09:27:29
【问题描述】:

如何在用户输入的字符串中找到 MIPS 中已知长度的特定字符?我查看了 SO 以及许多其他网站,但似乎没有一个可以从根本上解释如何操作用户输入的数据。

这是我目前所拥有的:

A_string: 
.space 11
buffer:
asciiz"Is this inputed string 10 chars long?"
main: 

la $a0, buffer
li $v0, 4
syscall

li $v0, 8
la $a0, A_string
li $a1, 11
syscall

【问题讨论】:

    标签: assembly mips spim


    【解决方案1】:

    您必须遍历读取缓冲区以查找所需的特定字符。

    例如,假设您想在输入数据中查找字符 'x',并假设此 sn-p 放在您的代码之后,因此 $a1 已经读取了最大字符数。您必须从缓冲区的开头开始并迭代,直到找到您期望的字符或遍历整个缓冲区:

      xor $a0, $a0, $a0
    search:  
      lbu $a2, A_string($a0)
      beq $a2, 'x', found    # We are looking for character 'x'
      addiu $a0, $a0, 1
      bne $a0, $a1, search
    not_found:
        # Code here is executed if the character is not found
        b done
    found:
        # Code here is executed if the character is found
    done:
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 2014-03-26
      • 2016-01-26
      相关资源
      最近更新 更多