MIPS存储字节

时间:2014-07-30 19:01:38

标签: mips

我的代码有问题。它应该这样做:
gabriele - > GRL
但不是3个字符,它加倍了最后一个。因此:gabriele - > grll
为什么呢?

    .data 0x10010000
nome:       .asciiz "gabriele"
voc:        .asciiz "aeiou"
st_nome:    

    .text 0x400000
main:       la $s1, voc         #address of voc in s1
            la $s2, nome        #address di nome in s2
            li $t3, 0           #index name
            li $t4, 0           #index  vowel
            li $t5, 0           #memory index
            li $a1, 4           #max number of character

cerca_nom:  lbu $t0, nome($t3)
            beqz, $t0, fine

sc_voc2:    lbu $t1, voc($t4)
            beq $t0, $t1, ignora2
            addi $t4, $t4, 1
            beqz $t1, salva_n
            j sc_voc2

salva_n:    sb $t0, st_nome($t5) 
            addiu $t5, $t5, 1
            bge $t5, $a1, prime

ignora2:    addi $t3, $t3, 1
            li $t4, 0
            j cerca_nom

prime:      li $t5, 0                   
            la $t1, st_nome

            lbu $t0, 0($t1)             
            sb $t0, st_nome($t5)        #take the first character
            addi $t5, $t5, 1

            lbu $t0, 2($t1)
            sb $t0, st_nome($t5)        #take the third character
            addi $t5, $t5, 1

            lbu $t0, 3($t1)
            sb $t0, st_nome($t5)        #take the fourth character

fine:

1 个答案:

答案 0 :(得分:1)

cerca_nom循环中,您要从名称中删除元音并存储剩余的字符('g''b''r''l')在st_nome

所以现在你'gbrl'已经st_nome了。

然后你做:

st_nome[0] = st_nome[0]   ; still 'gbrl'
st_nome[1] = st_nome[2]   ; 'grrl'
st_nome[2] = st_nome[3]   ; 'grll'

你永远不会覆盖st_nome[3],因此那里仍会有'l'