Advanced

Palindrome Checker

Check if a null-terminated string is a palindrome, ignoring spaces.

Write a program to check if a null-terminated string stored in memory starting at location x5000 is a palindrome. Store 1 in memory location x6000 if it is a palindrome, -1 otherwise.

A palindrome is an expression that reads the same from left to right or from right to left. Spaces should be ignored and you can assume all letters are in uppercase.

Requirements:
• The string at x5000 is null-terminated and all uppercase

• Spaces (ASCII x20) should be skipped when comparing

• Store 1 at x6000 if the string is a palindrome

• Store -1 (xFFFF) at x6000 if it is not

Suggested Algorithm:
1. Set R1 to point to the first character of the string, R2 to point to the last character
2. Skip any spaces at R1 (advance forward) and R2 (advance backward)
3. Compare characters pointed to by R1 and R2
4. If they are the same, go to the next step. Otherwise, store -1 in memory location x6000 and stop
5. Update R1 (forward) and R2 (backward). If they have not crossed each other, go to step 2, else the string is a palindrome — store 1 at x6000 and stop

Key Insight: To find the last character, first walk the string to find the null terminator, then back up one position.

ASCII Reference:

CharacterHexDecimal
Spacex2032
Ax4165
Zx5A90
1
2
3
4
50:00