Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions