Reputation: 659
I have a problem with this code. It should do this:
gabriele -> grl
but instead of 3 characters it redouble the last one. Hence: gabriele -> grll
Why?
.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:
Upvotes: 1
Views: 2187
Reputation: 58447
In your cerca_nom
loop you're removing the vowels from the name and storing the remaining characters ('g'
, 'b'
, 'r'
, 'l'
) at st_nome
.
So now you've got 'gbrl'
at st_nome
.
Then you do:
st_nome[0] = st_nome[0] ; still 'gbrl'
st_nome[1] = st_nome[2] ; 'grrl'
st_nome[2] = st_nome[3] ; 'grll'
You're never overwriting st_nome[3]
, so there will still be an 'l'
there.
Upvotes: 1