I needed to create a validator for a palindromic string of /[a-z]*/ and thought to explore doing the function in NASM. I'm looking for some source review to give me some ideas on how this might be better syntax. Please, let me know:
global _start
section .data
err_zero: db "the search string empty", 10, 0
err_zero_len: equ $-err_zero
pure_pal: db "the search string is 1 character. it is be definition a pal", 10, 0
pure_pal_len: equ $-pure_pal
is_pal: db "the string is a pal", 10, 0
is_pal_len: equ $-is_pal
is_not_pal: db "the string is not a pal", 10, 0
is_not_pal_len: equ $-is_not_pal
pal: db "thomas"
pal_len: equ $-pal
section .text
_start:
mov ecx, pal_len ;get the length of the potential pal
cmp ecx, 1 ;compare to 1
ja long_test ;if char count > 1 goto the loop test
je of_course ;if only 1 char then goto "of_course"
empty_pal: ;fall through: empty pal string
mov edx, err_zero_len
mov ecx, err_zero
mov ebx, 1
mov eax, 4
int 0x80
jmp endend
of_course: ;of course it's a pal. just 1 char
mov edx, pure_pal_len
mov ecx, pure_pal
mov ebx, 1
mov eax, 4
int 0x80
jmp endend
long_test: ;start of the long loop test
mov ecx, pal_len ;get the count of chars in the pal
xor edx, edx ;clear out the bit flags
xor eax, eax ;clear out the total count
loop: ;begin of loop
dec ecx ;decrease the index array because we are base zero
movzx esi, byte [pal + ecx] ;get the ansi number of the character
sub esi, 97 ;reduce the string value to be inside the alphabet flags
btc edx, esi ;bit swap just that bit
jnc missmatch ;if the return of the swap was 0 then we have a missmatch
dec eax ;else -- we matched and should decrease the missmatch count
jmp next ;attempt the next char if possible
missmatch: ;we have a missmatch detected
inc eax ;increase the missmatch count
next:
jecxz out ;compare the index loop to 0 to see if we are at the start
jmp loop ;go to the next character
out:
cmp eax, 1 ;see how the total count compares to 1
ja notpal ;only if there are more than 1 should we know it's not a pal
mov edx, is_pal_len
mov ecx, is_pal
mov ebx, 1
mov eax, 4
int 0x80
jmp endend
notpal: ;oops, it's not a pal
mov edx, is_not_pal_len
mov ecx, is_not_pal
mov ebx, 1
mov eax, 4
int 0x80
endend: ;exit the application
xor ebx, ebx
mov eax, 1
int 0x80