Question: I try to switch the letter by this code like abcdef convert to badcfe , but it always run error, I really can't find where

I try to switch the letter by this code like "abcdef" convert to "badcfe" , but it always run error, I really can't find where is wrong of my code, HELP!!!

.data

chararray:

.asciiz "abcdef"

endl: .asciiz " "

.text

.globl main

main: # execution starts here

la $t1,chararray # $t1 points to the string

nextCh:

lb $t0,($t1) # get a byte from string

beqz $t0,chararrayEnd # zero means end of string

rem $t2,$t0,2

bnez $t2,else

add $sp,$sp,1 # adjust stack pointer

b cont

else:

sub $sp,$sp,1

cont:

sw $t0,($sp) # PUSH the t0 register

add $t1,1 # move pointer one character

j nextCh # go round the loop again

chararrayEnd:

la $t1,chararray # $t1 points to the string

store:

lb $t0,($t1) # get a byte from string

beqz $t0,done # zero means end of string

lw $t0,($sp) # POP a value from the stack

add $sp,$sp,5 # and adjust the pointer

sb $t0,($t1) # store in string

add $t1,1 # move pointer one character

j store

done:

la $a0,chararray # system call to print

li $v0,4 # out a message

syscall

la $a0,endl # system call to print

li $v0,4 # out a newline

syscall

li $v0,10

syscall

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!