0
#asciis for l and U
li t4, 108
li t5, 'U'
la t1, str1 # t1 is ptr

repeat:
lb s1, (t1) # the char
beq s1, t2, tapos   # check for \r
beq s1, t3, tapos   # check for \n
beq s1, t5, tapos   # check for null
beq s1, t4, test_replace
j repeat

test_replace:
#Replace current letter, with a new letter
li t5, 'U'
sb t5, 0(s1)
j repeat

What I'm trying to do is when a character 'l' is encountered, it gets rewritten with the character 'U'. However, when I run it, I experience an Address out-of-range exception on the last line

Rocklon1427
  • 251
  • 1
  • 2
  • 5
  • You have a typo in the `sb` — `s1` is not a pointer, it is a byte — you want `t1` there. – Erik Eidt Feb 20 '23 at 15:58
  • BTW, as `t1` isn't incremented, it will examine the first byte forever, if it is not one of the characters you're tetsting for. – Erik Eidt Feb 20 '23 at 16:02

0 Answers0