Mips 可变偏移量

Mips 可变偏移量,mips,offset,Mips,Offset,我正在编写一个代码,从另一个字符串中搜索和查找这些字符(aeiou),并保存所有其他字符(最多3个)。如果(aeiou)中没有3个不同的字符,则必须使用这些字符。 例如,我有一个字符串:“rossi”。我想将这个字符串的每个字符与其他字符串进行比较,找出不同的字符。 我是这样想的: 如果“r”与“a”&&“e”&“i”&“o”&“u”不同,则将“r”保存在寄存器中,并使用第二个字符进行比较 我写了这个,但我不能退出循环 .data 0x10010000 cognome: .asciiz "

我正在编写一个代码,从另一个字符串中搜索和查找这些字符(aeiou),并保存所有其他字符(最多3个)。如果(aeiou)中没有3个不同的字符,则必须使用这些字符。 例如,我有一个字符串:“rossi”。我想将这个字符串的每个字符与其他字符串进行比较,找出不同的字符。 我是这样想的:
如果“r”与“a”&&“e”&“i”&“o”&“u”不同,则将“r”保存在寄存器中,并使用第二个字符进行比较

我写了这个,但我不能退出循环

.data 0x10010000 cognome: .asciiz "rossi" voc: .asciiz "aeiou" .text 0x400000 main: la $s0, cognome la $s1, voc cerca: lbu $t0, 0($s0) sc_voc: lbu $t1, 0($s1) bne $t0, $t1, sc_voc move $s3, $t2 j cerca .数据0x10010000 cognome:“罗西” voc:。asciiz“aeiou” .文本0x400000 主:洛杉矶$s0,科诺美 洛杉矶1美元,voc cerca:lbu$t0,0($s0) sc_voc:lbu$t1,0($s1) bne$t0、$t1、sc_voc 移动$s3,$t2 日本cerca 我知道这是错误的,但我不知道如何增加lbu的偏移量,因为这取第一个


你能帮帮我吗?

你陷入了这个循环,因为你只需要比较字母“r”和字母“a”,看看它们是否相等。您必须通过已创建的角色数组进行操作。您可以做的一件事是利用这样一个事实:当您使用
.asciiz
定义字符串时,汇编程序会自动附加空终止符。这允许您使用以下伪代码解决问题:

place starting address of cognome in $s0
place starting address of voc in $s1
place starting address of storage in $s3
initialize an index for cognome ($t3 = 0)
initialize an index for voc ($t4 = 0)
initialize an index for storage ($t5 = 0)

LOOP1
if (current value stored at cognome index does not equal 0)
    LOOP2
    if (current value stored at voc index does not equal 0)
        if (value stored at cognome index is equal to value stored at voc index)
            increment cognome index
            set voc index equal to 0
            goto LOOP1
        else
            increment voc index 
            goto LOOP2
    else
        store value at address based on storage index
        increment storage index
        increment cognome index
        set voc index equal to 0
        goto LOOP1
利用以上关于如何解决问题的知识,您可以按如下方式实现程序集:

    .data 0x10010000
cognome:    .asciiz "rossi"
voc:        .asciiz "aeiou"
storage:

    .text 0x400000

    la $s0, cognome         #load starting address of "rossi"
    la $s1, voc             #load starting address of "aeiou"
    la $s2, storage         #load starting address to save desired letters
    li $t3, 0               #initialize index for cognome
    li $t4, 0               #initialize index for voc
    li $t5, 0               #initialize index for storage

loop1:   
    lbu $t1, cognome($t3)   #load value at cognome[$t3] into $t1
    beqz $t1, end           #if the value of $t1 is NULL, goto end

loop2:
    lbu $t2, voc($t4)       #load value at voc[$t4] into $t2
    beq $t1, $t2, is_vowel  #if $t1 == $t2 do not store, goto is_vowel
    addiu $t4, $t4, 1       #increment voc index
    beqz $t2, save          #if $t2 is NULL, all vowels have been checked,
                            #  and the value in $t1 is not a vowel, goto save.
    b loop2                 #Otherwise, check $t1 against the next letter in voc
                            #  by going to loop2

save:
    sb $t1, storage($t5)    #store the letter at storage[$t5]
    addiu $t5, $t5, 1       #increment the storage index
is_vowel:
    li $t4, 0                #reset the voc index
    addiu $t3, $t3, 1       #increment the cognome index
    b loop1                 #check the next letter in cognome, goto loop1

end:

我希望这有帮助

谢谢你,伙计!你救了我!!我可以使用寄存器存储内存中的所有字符吗?还有一件事:我可以反过来保存角色吗?如果没有,如何选择存储字符的地址?远非同源voc@Shika93,据我所知,在单独的寄存器中存储值并非易事。这是因为您不能以与内存相同的方式对寄存器进行索引。您可以使用一系列基于索引的分支,并在代码的分支中将您的char分配给特定的寄存器(但我认为这会变得很糟糕)。如果使用单个寄存器,则可以使用位操作。至于在内存中选择地址,您应该能够指定数据段中的任何可用地址。我只是觉得用标签会更容易。明白了。另一件事:我怎么能说:“如果t1>4那么”?在寄存器中没有加载“4”的类似“bgt”的指令。听起来你需要一个很好的MIPS介绍。查看此网站。它有你想要的所有答案。