Question: 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 of file C:UsersasusDesktopPalindromeTenemes with $t 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
text
globl main
main:
#load address of string into $t
la $t string
#initlialize length counter $t to
move $t zero
findlength:
#load byte at address in $t into $t
lb $t$t #load byte at address in $t into $t
#If t is end of string go to palindrome check
beq $t $zero, checkpalindrome
#increment address pointer
addi $t $t
#increment length counter
addi $t $t
#jump back to continue finding length
j findlength
checkpalindrome:
#move length into $t for calculations
move $t $t
#load address of the string into $t
la $t string
#set $t to point the last character of string
add $t $t $t
#Adjust for zero based index
subi $t $t
#assume palindrome initially, store in $t
li $t
compareloop:
#If start pointer is less than end pointer, continuous
blt $t $t continuecompare
#finish the check
jfinish
continuecompare:
#load character at start pointer
lb $t$t
#load character at end pointer
lb $t$t
#if characters don't match, its not palindrome
bne $t $t notpalindrome
#move start pointer right
addi $t $t
#move end pointer left
subi $t $t #move end pointer left
#jump back to start of the loop
j compareloop
notpalindrome:
#set result to
li $t
finish:
#store result in memory
sw $t result
#load exit syscall
li $v #load exit syscall
#exit program
syscall
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
