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
String MIPS程序集-从输入字符串中删除元音_String_Assembly_Mips - Fatal编程技术网

String MIPS程序集-从输入字符串中删除元音

String MIPS程序集-从输入字符串中删除元音,string,assembly,mips,String,Assembly,Mips,以下是我的MIPS汇编程序代码,该程序旨在从输入字符串中删除元音,然后打印新字符串。目前,该程序只是不删除元音,而是重新打印输入的相同字符串 .text .globl main main: # display prompt li $v0, 4 la $a0, prompt syscall # accept input string li $v0, 8 la $a0, str

以下是我的MIPS汇编程序代码,该程序旨在从输入字符串中删除元音,然后打印新字符串。目前,该程序只是不删除元音,而是重新打印输入的相同字符串

    .text
    .globl  main

main:
    # display prompt
    li      $v0, 4
    la      $a0, prompt
    syscall
    # accept input string
    li      $v0, 8
    la      $a0, str
    li      $a1, 82
    syscall

    li      $t0, 0          # add a null to the bottom of the stack
    subu    $sp, $sp, 4
    sw      $t0, ($sp)
    li      $t1, 0          # initiate index

pushloop:
    lbu     $t0, str($t1)   # (I think the program is placing a zero in $t0 here, thus causing it to branch immediately to poploop, which then branches to the end since only the null has been pushed onto the stack)
    beqz    $t0, poploop    # once we reach null char, finish
    subu    $sp, $sp, 4
    sw      $t0, ($sp)
    addiu   $t1, $t1, 1
    j       pushloop
    nop
    # $t1 is not reset

poploop:
    lw      $t0, ($sp)
    addu    $sp, $sp, 4
    beqz    $t0, done       # once we reach null char, finish
    nop
    # check if vowel
    li      $t2, 0x61       # a
    beq     $t0, $t2, vowel
    nop
    li      $t2, 0x65       # e
    beq     $t0, $t2, vowel
    nop
    li      $t2, 0x69       # i
    beq     $t0, $t2, vowel
    nop
    li      $t2, 0x6F       # o
    beq     $t0, $t2, vowel
    nop
    li      $t2, 0x75       # u
    beq     $t0, $t2, vowel
    nop
    # if not a vowel, store it at current index in string
    sb      $t0, str($t1)
    j       decrement
    nop
vowel:  # if vowel, remove character
    li      $t0, 0
    sb      $t0, str($t1)
decrement:
    addiu   $t1, $t1, -1        # decrement index
    j       poploop
    nop
done:   
    li      $v0, 4
    la      $a0, str
    syscall
    li      $v0, 10         # exit program
    syscall
    nop

    .data
str:    .space 82
prompt: .asciiz "Input a string:\n"

所以。我看了你写的东西,我把它修好了

我的第一个想法是我不知道你在用堆栈和堆栈指针(
$sp
)做什么。看起来没必要,所以我把它拿了出来

其次,这种方法是错误的。您的方法是搜索字符串并用
0
替换每个小写元音(或至少“a”、“e”、“i”、“o”和“u”)。这是行不通的

如果你考虑一个典型的C字符串,它们会被一个
0
删除,因此如果你把字符串
取下来,我的名字是Jeoff
,然后应用你的算法,你会得到
My n\0m\0\0s J\0\0ff
,当然会打印成
My n

因此,我选择了一个单独的algthm,它选择不存储任何元音,而是将下面的所有字符移位1。这样,我们可以轻松地从字符串中删除所有元音,而不需要二级缓冲区

请看下面:

    .text
    .globl  main

main:
    # display prompt
    li      $v0, 4
    la      $a0, prompt
    syscall
    # accept input string
    li      $v0, 8
    la      $a0, str
    li      $a1, 82
    syscall

    li      $t1, 0          # initiate index
    li      $t3, 0          # vowel count

poploop:
    lb $t0 str($t1)

    # check if vowel
    li      $t2, 'a'       # a
    beq     $t0, $t2, vowel
    nop
    li      $t2, 'e'       # e
    beq     $t0, $t2, vowel
    nop
    li      $t2, 'i'       # i
    beq     $t0, $t2, vowel
    nop
    li      $t2, 'o'       # o
    beq     $t0, $t2, vowel
    nop
    li      $t2, 'u'       # u
    beq     $t0, $t2, vowel
    nop

    # if not a vowel, store it at current index in string less vowel count
    sub     $t2, $t1, $t3
    sb      $t0, str($t2)
    j       next
    nop
vowel:  # if vowel, inc count
    addi $t3, $t3, 1
next:
    addi $t1, $t1, 1

    beqz    $t0, done       # once we reach null char, finish
    nop
    j       poploop
    nop

done:   
    li      $v0, 4
    la      $a0, str
    syscall
    li      $v0, 10         # exit program
    syscall
    nop

    .data
str:    .space 82
prompt: .asciiz "Input a string:\n"

绝对不是我经常跑步时它的功能!分配需要使用内存堆栈,但您的示例向我展示了如何修复它。