[code] TITLE Proj2
PAGE 56,90
; ----------------------------------------
;
;
; This program will take a name entered by the user
; and display it backwards. It will also tell the
; user whether the word is a palindrome or not.
; ----------------------------------------
.MODEL SMALL
.STACK 100H
.DATA
CR EQU 0DH ; Carriage Return Code
LF EQU 0AH ; Line Feed Control Code
DOSEXIT EQU 4CH ; DOS exit code for 21h int
para_list LABEL BYTE
max_len db 20
act_len db ?
theword db CR,LF, 20 DUP(' ')
MSG1 DB CR,LF,'Enter a word $'
ItIs DB CR,LF,'The word is a Palindrome $'
ItIsNot DB CR,LF,'The word is not a Palindrome $'
SPACE DB CR,LF,'----------------------------$'
MSG2 DB CR,LF,'The word backwards is $'
MSG3 DB CR,LF,'The word is '
wordbw DB CR,LF, 12 DUP(' ')
GOODBYE DB CR,LF,'See You Later $'
; --------- End of Data Segment ----------
.CODE
Main PROC
;------------------------------------------
; The routine performs basic
; "housekeeping" operations necessary in
; any Assembly Language Program running
; under DOS or Windows...
; 1 - Establish Addressability to the
; Data Segment of the program.
;------------------------------------------
HouseKeeping:
mov ax,@data ;get addr. of DSeg.
mov ds,ax ;set in DS Reg.
;------------------------------------------
; Routine "GetPut" will...
; 1 - Display prompt message.
; 2 - capture user provided ASCII
; letter (located in AL register).
; 3 - Convert the letter to it's decimal
; equivalent.
; 4 - Display the converted letter within
; an "echoing" message.
;------------------------------------------
Prompt:
lea dx,MSG1 ;addr. of 1st msg
mov ah,9h ;set for str. displ.
int 21H ;call DOS to displ.
; DISPLAY MESSAGE ABOVE;
GetWord:
mov ah,0Ah ;set func. to Get String
lea DX,Para_list ;load address of para list
int 21H ;call DOS (val-AL)
mov theword,al ;move input to theword
;lea dx,space ;addr. of 1st msg
;mov ah,9h ;set for str. displ.
; int 21H ;call DOS to displ.
;set pointer to the right (act length)
;write that to the new string (left to right)
;dec the pointer
;increment the other pointer
MOV CX, 20 ;set the counter
lea si,theword ;put the word in si register
xor bx,bx ;clear the register
xor dx,dx ;clear the register
add act_len,1 ;increase the length by 1, because it is an array and needs to be increased by 1 so the first
mov bl,act_len ;set the pointer to read from the right
mov di,0 ;set the pointer to write starting from the left
;di starts at the number of letters and decreases
;bx starts at 0 and increases
inc bx
reverse:
mov ah,theword[bx] ;read the letter
dec bx ;decrease the read pointer
mov wordbw[di], ah ;write the letter
inc di ;increase the write pointer
cmp bx,0 ;check if the original word point is now at 0
JE print ;if it is then the loop can exit
loop reverse ;if not, then back to the beginning of the loop
print:
;Print out the Backwards Word
lea dx, wordbw
mov ah,9h
int 21h
jmp pgmexit
;------------------------------------------
; The routine sets the exit code and
; calls DOS. This is the appropriate
; technique for terminating a non-
; resident program running under DOS.
;------------------------------------------
PgmExit:
mov ah,DOSEXIT ;set Exit code
int 21H ;and call DOS
Main EndP
End Main
[\code]
I made a lot of progress but I am stuck on one thing. I am reversing the word except for the first letter. Any idea why?
I tried incrementing my reading pointer. And no luck. Any ideas?