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.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
[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 '$$$$$$$$$$'
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
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 '$$$$$$$$$$$'
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
Maybe your compiler also needs the .model.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402