Answered step by step
Verified Expert Solution
Question
1 Approved Answer
. data string: . asciiz level result: . word 0 . text . globl main main: #Step 1 = Calculate length of the string la
data
string: asciiz "level"
result: word
text
globl main
main:
#Step Calculate length of the string
la $t string #load address of string into $t
move $t zero #initlialize lenngth counter $t to
findlength:
lb $t$t #load byte at address in $t into $t
beq $t $zero, checkpalindrome #If t is end of string go to palindrome check
addi $t $t #increment address pointer
addi $t $t #increment length counter
j findlength #jump back to continue finding length
checkpalindrome:
move $t $t #move length into $t for calculations
la $t string #load address of the string into $t
add $t $t $t #set $t to point the last character of string
subi $t $t #Adjust for zero based index
li $t #assume palindrome initially, store in $t
compareloop:
blt $t $t continuecompare #If start pointer is less than end poiner, continune
j finish #finish the check
continuecompare:
lb $t$t #load character at start pointer
lb $t$t #load character at end pointer
bne $t $t notpalindrome #if characters dont match, its not palindrome
addi $t $t #move start pointer right
subi $t $t #move end pointer left
j compareloop #jump back to start of the loop
notpalindrome:
li $t #set result to
finish:
sw $t result #store result in memory
li $v #load exit syscall
syscall #exit program
What is false in that code got syntax error always
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started