liable
liable

Reputation: 93

Unintended loop termination

I'm writing a program for class that lowercases a text string. This works for the first character, but when it loops back for the second the beq $10,$0,done line always turns $10 to 0 and terminates the loop. I have no idea why.

.text
.globl main
main:
lui $9, 0x1000

loop:
lbu $10,0($9)
sll $0,$0,0

beq $10,$0,done
sll $0,$0,0

addiu $10,$10,0x20
sw  $10,0($9)
addiu $9,$9,1
ori $10,$0,1
j loop

sll $0,$0,0
done: sll $0,$0,0

.data
string: .asciiz "ABCDEFG"

Upvotes: 0

Views: 49

Answers (1)

Michael
Michael

Reputation: 58427

sw $10,0($9) <-- this is wrong

That sw should be an sb. Otherwise you'll store the 32-bit word 0x000000nn (where 0xnn is your character) at ($9). Which means that the bytes at 1($9)..3($9) will all be filled with the value 0. So on the next iteration of the loop you'll load the first of those 0-bytes and exit the loop.

Upvotes: 1

Related Questions