Answered step by step
Verified Expert Solution
Link Copied!

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 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

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions