; check whether R0 contains a palindrome

; in class, return value was in R0.  Here, we print yes or no.

	.ORIG x3000

	; set up the stack
	LEA R6,STK_BASE

	; put something into R0
	LD R0,CHK_ME

	; now check for a palindrome

	LD R2,MASK	; set R2 to x8000
	AND R1,R1,#0
	ADD R1,R1,#8

	; push the first 8 bits
PUSHING	AND R3,R0,R2	; copy MSB into R3
	ADD R6,R6,#-1	; push R3
	STR R3,R6,#0
	ADD R0,R0,R0	; shift R0 left
	ADD R1,R1,#-1	; count down 8 bits
	BRp PUSHING

	ADD R1,R1,#8	; prepare for next 8 bits

POPPING	AND R3,R0,R2	; copy MSB into R3
	LDR R4,R6,#0	; pop R4
	ADD R6,R6,#1
	ADD R3,R3,R4	; compare bits
	BRnp NOT_PAL
	ADD R0,R0,R0	; shift R0 left
	ADD R1,R1,#-1	; count down 8 bits
	BRp POPPING

	LEA R0,PALIN	; print "yes"
	BRnzp OUTPUT
NOT_PAL	LEA R0,NPAL	; print "no"
OUTPUT	PUTS
	HALT

MASK	.FILL x8000
PALIN	.STRINGZ "yes\n"
NPAL	.STRINGZ "no\n"

CHK_ME	.FILL xABCD	; Try xBC3D for a "yes" answer.
	.BLKW #32
STK_BASE

	.END
