I am writing a program to check if a given string is a palindrome and it is not running as expected. The code is from a textbook so it's not mine, but I can't understand why it's not running as it should. I actually had the same problem with a different program (which you can see on my stack overflow post here if you want) but I ignored it and moved on. I had the same issue again and I think the 'DCB' and 'DCD' instructions are not doing what they should. The reason I think that is the problem because when I look at the program in the debugger, the memory address that should be holding the string is clear. I don't know how to see what memory address holds a given variable but the address is loaded into r6 so I checked in memory area and its empty? What am I doing wrong?
My target device is an AMRCM7 by the way, and I'm on keil uvision v5.38a and the compiler is ARM compiler v6.19
Here is my full code:
AREA myData,DATA ALIGN string DCB "rats live on no evil star", 0 ; NULL terminator explicitly added AREA palindrome,CODE EXPORT __main ALIGN ENTRY __main PROC LDR r6, = string ; load address of string in r6 ;Find string length MOV r1,#0 ; len MOV r5,r6 ; r5=string strLen LDRB r2,[r5],#1 ;post-index CMP r2,#0 ;Check for NULL character ADDNE r1,r1,#1 BNE strLen ;Check palindrome SUB r1,r1,#1 ;len - 1 ADD r1,r6,r1 ;&str[len-1]. MOV r2,r6 ;&str. First character of string cmpStr LDRB r3,[r2],#1 ;Len - 1 LDRB r4,[r1],#-1 ;str[len - 1 - i] CMP r3,r4 MOVNE r0,#0 ;set flag BNE stop CMP r1,r2 BLT cmpStr MOV r0,#1 stop B stop ENDP END