Есть несколько ошибок.
Вот аннотированная версия вашего кода, показывающая ошибки:
.data
message: .asciiz "This text should probably contain something useful!"
# NOTE/BUG: this isn't needed since you scan for the 0 byte at the end of
# message
message_size: .word 51
.text
# NOTE/BUG: a0 is never initialized -- it should point to message_size
main:
# NOTE/BUG: setting t1 isn't needed
li $t1,0
la $t0,message
loop:
# NOTE/BUG: using a0 to fetch the byte destroys the pointer -- use a different
# register (it should be something else)
lb $a0,0($t0) # load the first ascii-char of the string
beqz $a0,done
# NOTE/BUG: these addi insts don't do much
addi $t0,$t0,1
addi $t1,$t1,1
# NOTE/BUG: jump is not needed -- just fall through
j rot47
rot47:
# NOTE/BUG: this store should be done _after_ rotation (i.e. at next:)
sb $t3,0($a0) # store the first ascii-char into $t3
ble $t3,79,do # $t3 <= 79 do $t3 + 47
sub $t3,$t3,47 # else $t3 - 47
j next
do:
addi $t3,$t3,47
j next
next:
addi $a0,$a0,1 # increment $a0 for the next byte
j loop
# print the completed string
done:
# NOTE/BUG: t3 now points to end of string [or worse]
li $v0,4
add $a0,$0,$t3
syscall
li $v0,10
syscall
Вот исправленная и исправленная версия:
.data
message: .asciiz "This text should probably contain something useful!"
output: .space 1000
.text
main:
la $t0,message # point to input buffer
la $a0,output # point to output buffer
loop:
lb $t3,0($t0) # load the next ascii-char of the string
beqz $t3,done # at end? if yes, fly
ble $t3,79,do # $t3 <= 79 do $t3 + 47
sub $t3,$t3,47 # else $t3 - 47
j next
do:
addi $t3,$t3,47
j next
next:
sb $t3,0($a0) # store the current char into output
addi $t0,$t0,1 # increment input pointer for the next byte
addi $a0,$a0,1 # increment output pointer for the next byte
j loop
# print the completed string
done:
sb $zero,0($a0)
li $v0,4
la $a0,output
syscall
li $v0,10
syscall