I am coming back with a load address error with the first line in main (la $a0, test_str). I have been trying to figure out why. I am probably thinking to hard. Any help would be appreciated.
.data
pali0:
.asciiz "Go deliver a dare, vile dog"
pali1:
.asciiz "Some men interpret nine memos"
pali2:
.asciiz "Gateman sees name, garageman sees name tag"
pali3:
.asciiz "Ein Neger mit Gazelle zagtim Regen nie"
pali4:
.asciiz "stressed desserts"
pali5:
.asciiz "palindromes"
pali6:
.asciiz "Drab as a fool, aloof as a bard"
pali7:
.asciiz "Tattarrattat"
pali8:
.asciiz "Socorram me subi no on ibus em Marrocos"
pali9:
.asciiz "May a moody baby doom a yam"
test_str:
.word pali0, pali1, pali2, pali3, pali4, pali5, pali6, pali7, pali8, pali9
is_pali_msg:
.asciiz " The string is a palindrome."
not_pali_msg:
.asciiz " The string is not a palindrome."
newline:
.asciiz "\n"
res_msg:
.asciiz "The longest palindrome is "
.text
.globl main
main:
la $a0, test_str # Load the starting address of the array
li $a1, 10 # the number of elements
jal get_longest
ori $t0, $v0, 0
la $a0, res_msg
li $v0, 4
syscall
ori $a0, $t0, 0
li $v0, 4
syscall
la $a0, newline
li $v0, 4
syscall
done:
li $v0, 10 # exit
syscall
get_longest:
addi $sp, $sp, -4 # create space on stack
sw $ra, 0($sp) # store return address
addi $t7, $t7, 0 # initialize t7 to 0
la $t5, 0($a0) # store address of current string
jal is_palindrome # go to function
beq $v0, $0, L6 # if not palindrome jump to L6
bgt $v1, $t7, L7
L6:
la $ra, 0($sp) #get return address from stack
addi $sp, $sp, 4 #restore space on stack
jr $ra #return to main
L7:
la $v0, 0($t5) #load address of larger palindrome
la $ra, 0($sp) #get return address from stack
addi $sp, $sp, 4 #restore space on stack
jr $ra #return to main
is_palindrome:
addi $sp, $sp, -4 # create space on stack
sw $ra, 0($sp) # store return address on stack
jal get_to_end # go to function
srl $t0, $v1, 1 # divide v1 by 2 into t0
li $t3, 0 # initialize counter to 0
L3:
lw $t1, 0($a0) # load 1st element into t1
lw $t2, 0 ($v0) # load last element into t2
bne $t2, $t1, L4 # compare elements
addi $a0, $a0, 4 # increment a0 to next element
addi $v0, $v0, -4 # decrement $v0 to next element
addi $t3, $t3, 1 # increment counter
beq $t3, $t0, L5 # check exit condition (i < v1/2)
j L3
L4:
li $v0, 0 #if string ins not palindrome
la $ra, 0($sp) # get address off stack
addi $sp, $sp, 4
jr $ra #return to get_longest
L5:
li $v0, 1 # if string is palindrome
la $ra, 0($sp) # get address off stack
addi $sp, $sp, 4 # pop
jr $ra # return to get_longest
get_to_end:
la $v0, 0($a0) # load address into $a0
li $v1, 0
L1:
bne $v0, 0, L2 # if the element if 0
addi $v0, $v0, -1 # decrement to capture address of last element
jr $ra #
L2:
addi $v0, $v0, 1 # go to next element
addi $v1, $v1, 1 # count number of elements
j L1 # return to loop