Question: . 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 0
.text
.globl main
main:
#Step 1= Calculate length of the string
la $t0, string #load address of string into $t0
move $t1, zero #initlialize lenngth counter $t1 to 0
find_length:
lb $t2,0($t0) #load byte at address in $t0 into $t2
beq $t2, $zero, check_palindrome #If t2 is 0, end of string go to palindrome check
addi $t0, $t0,1 #increment address pointer
addi $t1, $t1,1 #increment length counter
j find_length #jump back to continue finding length
check_palindrome:
move $t3, $t1 #move length into $t3 for calculations
la $t4, string #load address of the string into $t4
add $t5, $t4, $t3 #set $t5 to point the last character of string
subi $t5, $t5,1 #Adjust for zero based index
li $t6,1 #assume palindrome initially, store 1 in $t6
compare_loop:
blt $t4, $t5, continue_compare #If start pointer is less than end poiner, continune
j finish #finish the check
continue_compare:
lb $t7,0($t4) #load character at start pointer
lb $t8,0($t5) #load character at end pointer
bne $t7, $t8, not_palindrome #if characters dont match, its not palindrome
addi $t4, $t4,1 #move start pointer right
subi $t5, $t5,1 #move end pointer left
j compare_loop #jump back to start of the loop
not_palindrome:
li $t6,0 #set result to 0
finish:
sw $t6, result #store result in memory
li $v0,10 #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

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!