I'm stuck on how to check for a palindrome using MASM.
#include <iostream>
#include <cstring>
#include<string>
#include <algorithm>
using namespace std;
extern "C"
char test(char*, int);
int main()
{
char arr[] = {NULL};
cout << "Enter a string: " << endl;
cin >> arr;
int name = strlen(arr);
test(arr, name);
if (name == 1)
{
cout << "It is a palindrome! " << endl;
}
else
cout << "Not a palindrome. " << endl;
return 0;
}
I asked the user for a string and insert it to an array. I send it to the assembly file and it would return a '1' if its true or '0' if false.
.686
.model flat
.code
_test PROC ;named _test because C automatically prepends an underscode, it is needed to interoperate
push ebp
mov ebp,esp ;stack pointer to ebp
mov eax,[ebp+8]
mov ecx,[ebp+12]
mov ebp,0
mov edi,0
mov edx,0
loopMe:
cmp ebp,ecx
je True
mov al,[eax+edi]
mov bl,[edx+esi]
cmp al,bl ;compare
jne false ;if not equal then jump to false
inc edi
dec esi
jmp loopMe
True:
mov eax,1
jmp allDone
False:
mov eax,0
jmp allDone
allDone:
pop ebp
ret
_test ENDP
END
when I enter a string it seems to always return 0. I checked the debugger and it would always jump to the False label even though the values are equal. Any help is appreciated.