TITLE Proj2

PAGE 56,90

;    I used your Lab05 as a template for this
; ----------------------------------------
;
;  
;    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 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 '
wordbw DB     CR,LF, 12 DUP(20H),'$'          


; --------- 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.

CLD
MOV CX, 20
LEA SI,theWORD



 

L20:    
LODSB
mov [di],AL
dec di
XOR BX, BX
mov bl, act_len

LEA DI, WORDBW[bx]
loop l20


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

My problem is that it is not outputting the reworsed word. I want to create a second string (that is the word backwards), and then compare the two strings if they are the same.

Any ideas? I've been trying for weeks and have been so stuck. I even posted here for no responces.

Recommended Answers

All 5 Replies

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
JE print
loop reverse

I think the problem is that I cant use line 4 like that. It is an error. How can I make it write to the location of wordbw but in the beginning.

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       

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?

Im not asking for code or anything, just an idea. I tried manually moving the first letter into the last letter of the new string with:

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

Im not asking for code or anything, just an idea. I tried manually moving the first letter into the last letter of the new string with:

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

end quote.

Try something like this:

mov al, 0
push al

move2stack:
mov al, theword[bx]
push al
inc bx
cmp al, 0
jne move2stack

pop al
xor bx, bx

move2mem:
pop al
mov wordbw[bx], al
inc bx
cmp al, 0
jne move2mem

Nathan.

I figured out the problem. I was moving the ah into theword; and i was only moving the last string entered. Which was the enter key. So it never recorded the first letter, and thus never repeated it.

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.