Good day ^^

I want to create a program using tasm that will tell if the inputted string is a palindrome or not....but i don't know how will i get the first and last char to compare..unlike in C..i can use the strlen....XD

Please make the codes very simple ^^..tnx in advance XD

Whole codes? Well hint's are okay, but I won't cause fuss and try to figure out a completely running programme.

Think about how you determine the length of a string? Null-terminated? Fine.
I'd start like that:
Run through the string, till \0 comes. Decrease the register (let's call it the backcounter). Now run a second loop till the \0-character. Now compare the character of your backcounter with the one of your forward-counter. After each step you're decreasing the backcounter and increase the forward-counter.

That should be all.
Hope it helps.

You could start out with getting the user input of the word and then figure out the word length based on the left-over terminators.

Start with something like this:
http://www.daniweb.com/software-development/assembly/code/270832

...then count the characters based on the start position until you run into a terminator.
After that, you can copy and reverse the word and compare it.

Actually I know what should i do to tell if it is palindrome or not.. I already done it in turbo c but my problem is what is the equivalent code of strlen (to get the number of char) of tc in TASM..... i dont know how to get each character in tasm that is my only problem...XD

[Just getting string length]
Assuming a 10-char max string and a specific location,
this code compares the target string against a string of terminating dollar-signs.

;This determines a string length by
; producing a reverse count and subtracting
mov cx, 10	; Max string length
mov dx, 9	; one less than max (offset for $)
mov si, string1
mov di, string2
repne cmpsb
sub dx, cx	; Actual string length in DX

int 20h
string1:	db 'One$$$$$$$'
string2:	db '$$$$$$$$$$'

Thanks for all the help...me and my two other classmates successfully finished the program ^^..XD

Great!
Here's what I hacked out (FYI):

;-------------------------------80x86----------------------------------------
; 8-Aug-2011 - THINES01
; Palindro.asm: to be compiled with A86 (http://eji.com/a86/)
; This program shows how to get user input with echo
; and test to see if it is a palindrome
; ---------------------------------------------------------------------------
        mov dx, askString;
        call doPrint
        mov cx, 0ah
        mov si, strOrig;                ; Place to store the orig string
getString:
        mov ah, 01h
        int 21h                         ; Get input with echo
        
        cmp al, 0dh                     ; 
        je printQuit                    ; Quit if Carriage-return
        
        mov [si], al                    ; Put entered char in orig string
        
        cmp byte ptr [finalStop], 24h   ; is 10th dollar-sign gone?
        jne printQuit                   ; if so, buffer is full?, quit
        
        inc si                          ; move the position
        loop getString;                 ; Keep going (looping)
printQuit:
        mov dx, youEntered              ;
        call doPrint                    ; Print the finished message
; ---------------------------------------------------------------------------
strLen:
        mov cx, 0bh                     ; max string length (plus terminator)
        mov dx, 0ah                     ; minus 1
        mov si, strOrig                 ;
        mov di, strComp                 ; All terminators
        repne cmpsb                     ;
        sub dx, cx                      ; dx now holds num chars to reverse
; ---------------------------------------------------------------------------
doReverseCopy:
        mov cx, dx                      ; copy the length for the next op
        mov si, strOrig                 ;
        mov di, strDest                 ;
        add di, cx                      ;
        dec di                          ; minus 1
reverseCopy:
        mov bl, byte ptr [si]           ; copy the chars from source
        mov byte ptr[di], bl            ; paste chars at destination
        inc si                          ; next char forward
        dec di                          ; next char backward
        loop reverseCopy
; ---------------------------------------------------------------------------
compareStrings:
        mov cx, 0ah                     ; max string length
        mov si, strOrig                 ; Original string
        mov di, strDest                 ; Compare string
        repe cmpsb                      ;
        cmp cx, 0h                      ;
        jnz noMatch
; ---------------------------------------------------------------------------
isMatch:
        mov dx, strIsMatch
        call doPrint
        jmp quit
strIsMatch:       db 0ah, 0dh,'IS a palindrome!', 0ah, 0dh, 024h
; ---------------------------------------------------------------------------
noMatch:
        mov dx, strNoMatch              ; Display mismatch message
        call doPrint
        jmp quit
strNoMatch:       db 0ah, 0dh,'NOT a palindrome!', 0ah, 0dh, 024h
; ---------------------------------------------------------------------------
doPrint:
	mov ah, 09h
	int 21h
	ret
; ---------------------------------------------------------------------------
quit:   int 20h                         ; *** DROP TO DOS ***
; ---------------------------------------------------------------------------
askString:        db 'Enter a string of up to 10 characters: $'
youEntered:       db 0ah, 0dh, 'You entered: '
strOrig:          db '$$$$$$$$$$'
finalStop:        db '$$'
strDest:          db '$$$$$$$$$$$'
strComp:          db '$$$$$$$$$$$'

Great!
Here's what I hacked out (FYI):

;-------------------------------80x86----------------------------------------
; 8-Aug-2011 - THINES01
; Palindro.asm: to be compiled with A86 (http://eji.com/a86/)
; This program shows how to get user input with echo
; and test to see if it is a palindrome
; ---------------------------------------------------------------------------
        mov dx, askString;
        call doPrint
        mov cx, 0ah
        mov si, strOrig;                ; Place to store the orig string
getString:
        mov ah, 01h
        int 21h                         ; Get input with echo
        
        cmp al, 0dh                     ; 
        je printQuit                    ; Quit if Carriage-return
        
        mov [si], al                    ; Put entered char in orig string
        
        cmp byte ptr [finalStop], 24h   ; is 10th dollar-sign gone?
        jne printQuit                   ; if so, buffer is full?, quit
        
        inc si                          ; move the position
        loop getString;                 ; Keep going (looping)
printQuit:
        mov dx, youEntered              ;
        call doPrint                    ; Print the finished message
; ---------------------------------------------------------------------------
strLen:
        mov cx, 0bh                     ; max string length (plus terminator)
        mov dx, 0ah                     ; minus 1
        mov si, strOrig                 ;
        mov di, strComp                 ; All terminators
        repne cmpsb                     ;
        sub dx, cx                      ; dx now holds num chars to reverse
; ---------------------------------------------------------------------------
doReverseCopy:
        mov cx, dx                      ; copy the length for the next op
        mov si, strOrig                 ;
        mov di, strDest                 ;
        add di, cx                      ;
        dec di                          ; minus 1
reverseCopy:
        mov bl, byte ptr [si]           ; copy the chars from source
        mov byte ptr[di], bl            ; paste chars at destination
        inc si                          ; next char forward
        dec di                          ; next char backward
        loop reverseCopy
; ---------------------------------------------------------------------------
compareStrings:
        mov cx, 0ah                     ; max string length
        mov si, strOrig                 ; Original string
        mov di, strDest                 ; Compare string
        repe cmpsb                      ;
        cmp cx, 0h                      ;
        jnz noMatch
; ---------------------------------------------------------------------------
isMatch:
        mov dx, strIsMatch
        call doPrint
        jmp quit
strIsMatch:       db 0ah, 0dh,'IS a palindrome!', 0ah, 0dh, 024h
; ---------------------------------------------------------------------------
noMatch:
        mov dx, strNoMatch              ; Display mismatch message
        call doPrint
        jmp quit
strNoMatch:       db 0ah, 0dh,'NOT a palindrome!', 0ah, 0dh, 024h
; ---------------------------------------------------------------------------
doPrint:
	mov ah, 09h
	int 21h
	ret
; ---------------------------------------------------------------------------
quit:   int 20h                         ; *** DROP TO DOS ***
; ---------------------------------------------------------------------------
askString:        db 'Enter a string of up to 10 characters: $'
youEntered:       db 0ah, 0dh, 'You entered: '
strOrig:          db '$$$$$$$$$$'
finalStop:        db '$$'
strDest:          db '$$$$$$$$$$$'
strComp:          db '$$$$$$$$$$$'

thanks a lot thines01 hehehe your code is shorter than ours ^^

hi thines why is it unexpected end of file encountered?

i included .model small
.stack
.code
org 100h
start:
at the beginning of ur code

hi thines why is it unexpected end of file encountered?

i included .model small
.stack
.code
org 100h
start:
at the beginning of ur code

Maybe your compiler also needs the .model.

yah i included .model small

i got the same error: unexpected end of file encountered

commented: At 9 years and counting, best to make a new post with full code, which ASSEMBLER and full details to replicate. +16
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.