0

so I have to check palindrome of the string, but it has to convert the string to lowercase first so I'm struggling at that part. Here I have the code to find the length of the string already and now I'm confused how to convert each letter in this string to lowercase. I'm thinking of traversing through the string and convert each letter one by one but don't know actually how the conversion happen, thanks

my code:

.686
.model flat

.code

_IsPalindrome PROC  ;
    push ebp
    mov ebp,esp     ;stack pointer to ebp
    
    mov ebx,[ebp+8] ; address of first array element
    
    mov eax, 0
    xor dl, dl ;set dl = 0


lengthloop: ;find the length
    cmp [ebx+eax], dl
    je FirstLast
    inc eax
    jmp lengthloop

Lowercase: ;change to lower case
;STUCK AT THIS PART CURRENTLY

FirstLast: ;I'm thinking using this for traversing through the string
    mov ecx, 0  ;ecx = firt character of the string
    dec eax ;subtract one from eax 
    mov edx, eax ;edx = length of the string
    
CheckPalindrome: ;Will work on this after the lowercase 
    


AllDone:
    pop ebp 
    ret
_IsPalindrome ENDP

END

this in my main to call this asm file

#include <iostream>
using namespace std;

extern"C" {
    
    bool IsPalindrome(char[]);
}

int main()
{
    char myString[] = "kayak";
    IsPalindrome(myString);

    return 0;
}

thanks a lot, it'll be nice if you can give feedback in this form also, it's MASM x86 Intel

jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • yeah I'm thinking of masking but not sure how to apply it – Angelic Demonic Nov 04 '20 at 04:26
  • ohter example online wrote in NASM or other Assembler so can barely understand it – Angelic Demonic Nov 04 '20 at 04:26
  • 1
    [What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?](https://stackoverflow.com/a/54585515) describes the algorithm; should be straightforward to implement or even to compile into MASM syntax using MSVC or whatever (https://godbolt.org/) – Peter Cordes Nov 04 '20 at 04:33

0 Answers0