		.data
string:		.byte	0:80
length:		.word
start_ptr:	.word
end_ptr:	.word
getstring_ra:	.word
prompt:		.asciiz	"What phrase do you want to test for palindromehood?\n"
yes_msg:	.asciiz	"Yes, it's a palindrome.\n"
no_msg:		.asciiz	"No, it's not a palindrome.\n"


		.text
__start:	puts	prompt

		la	start_ptr,string
		la	getstring_ra,stmt1
		b	getstring
stmt1:
		add	end_ptr,start_ptr,length
		sub	end_ptr,end_ptr,1
testloop:	ble	end_ptr,start_ptr,is_palindrome
		bne	m[end_ptr],m[start_ptr],isnt_palindrome
		add	start_ptr,start_ptr,1
		sub	end_ptr,end_ptr,1
		b	testloop

is_palindrome:	puts	yes_msg
		b	end

isnt_palindrome: puts	no_msg

end:		done



		.data		# variables for the getstring procedure

next_char_ptr:	.word
this_char:	.byte

		.text
getstring:
	# Read the string into location pointed to by "start_ptr",
	# setting "length" to the length of the string
		move		next_char_ptr,start_ptr
read_loop:	get		this_char
		beq		this_char,'\n',done_reading
		move		m[next_char_ptr],this_char
		add		next_char_ptr,next_char_ptr,1
		b		read_loop

done_reading:	move		m[next_char_ptr],'\0'
	# This is not strictly necessary, but it ensures that we have
	# a standard null-terminated string.
		sub		length,next_char_ptr,start_ptr
		b		(getstring_ra)

