Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 在MIPS中查找字符串的字符_Assembly_Mips_Spim - Fatal编程技术网

Assembly 在MIPS中查找字符串的字符

Assembly 在MIPS中查找字符串的字符,assembly,mips,spim,Assembly,Mips,Spim,如何在MIPS中具有已知长度的用户输入字符串中找到特定字符?我看过很多其他网站,但似乎没有一个能从根本上解释如何操纵用户输入的数据 以下是我目前掌握的情况: 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 您必须在读取缓

如何在MIPS中具有已知长度的用户输入字符串中找到特定字符?我看过很多其他网站,但似乎没有一个能从根本上解释如何操纵用户输入的数据

以下是我目前掌握的情况:

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

您必须在读取缓冲区中迭代以查找所需的特定字符

例如,假设您希望在输入数据中查找字符“x”,并假设此代码段放在代码后面,因此$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:

您必须在读取缓冲区中迭代以查找所需的特定字符

例如,假设您希望在输入数据中查找字符“x”,并假设此代码段放在代码后面,因此$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: