Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Even though I saved this text file with . s and uploaded it to PcSpim, I continue to get the syntax error on line 1

Even though I saved this text file with .s and uploaded it to PcSpim, I continue to get the syntax error on line 10 of file C:\Users\asus\Desktop\PalindromeTeneme1.s with $t0, string error. When I try the sample codes it works, but my own code does not work.
this is my PcSpim code:
.data
string: .asciiz "level"
result: .word 0
.text
.globl main
main:
#load address of string into $t0
la $t0, string
#initlialize length counter $t1 to 0
move $t1, zero
find_length:
#load byte at address in $t0 into $t2
lb $t2,0($t0) #load byte at address in $t0 into $t2
#If t2 is 0, end of string go to palindrome check
beq $t2, $zero, check_palindrome
#increment address pointer
addi $t0, $t0,1
#increment length counter
addi $t1, $t1,1
#jump back to continue finding length
j find_length
check_palindrome:
#move length into $t3 for calculations
move $t3, $t1
#load address of the string into $t4
la $t4, string
#set $t5 to point the last character of string
add $t5, $t4, $t3
#Adjust for zero based index
subi $t5, $t5,1
#assume palindrome initially, store 1 in $t6
li $t6,1
compare_loop:
#If start pointer is less than end pointer, continuous
blt $t4, $t5, continue_compare
#finish the check
jfinish
continue_compare:
#load character at start pointer
lb $t7,0($t4)
#load character at end pointer
lb $t8,0($t5)
#if characters don't match, its not palindrome
bne $t7, $t8, not_palindrome
#move start pointer right
addi $t4, $t4,1
#move end pointer left
subi $t5, $t5,1 #move end pointer left
#jump back to start of the loop
j compare_loop
not_palindrome:
#set result to 0
li $t6,0
finish:
#store result in memory
sw $t6, result
#load exit syscall
li $v0,10 #load exit syscall
#exit program
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

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions