944,179 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Marked Solved
  • Views: 3009
  • Assembly RSS
Apr 26th, 2007
0

Help on Storing Strings from Keyboard...

Expand Post »
Hey I am doing a program in palindromes.


Don't worry, I dont want any code (I read the sticky). But this is my first semester using it, and my second program. I am having trouble in storing the word from the user. Right now it only stores one character. How can I make it save the entire word? What am I doing wrong?



Should I save the word one letter at a time in a loop so I can make it go in reverse order? Using Pops and Pushes?

I am using Tasm. Here is my code for reference

[code = language][inline code]
MSG1 DB ' Enter a word $'
theword db 20 dup( ' '), 0
ItIs DB 'The word is a Palindrome $'
ItIsNot DB 'The word is not a Palindrome $'

....
....
GetPut:

lea dx,MSG1 ;addr. of 1st msg
mov ah,9 ;set for str. displ.
int 21H ;call DOS to displ.

;DISPLAY MESSAGE ABOVE;


mov ah,1 ;set func. to Get
int 21H ;call DOS (val-AL)

;USER ENTERS STRING ABOVE;

mov theword,al ;move input to theword




lea dx,theword ;move the word to dx register
mov ah,9 ;move 9 to ah signaling output
int 21h ;call the interrupt

[/inlinecode]
[\code]
The current output is that it only allows me to type in one letter. Then the letter is echo'd (with no space in between). And the string that the word is a palindrome


If someone can show me how to have the user entered a string from they keyboard, and how I store it, that will be a big help.
Last edited by gparadox; Apr 26th, 2007 at 3:09 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gparadox is offline Offline
15 posts
since Apr 2007
Apr 26th, 2007
0

Re: Help on Storing Strings from Keyboard...

OK I figured out how to store string input.
but the output disappears, I want it to stay.
Assembly Syntax (Toggle Plain Text)
  1. TITLE Proj2
  2.  
  3. PAGE 56,90
  4. ; file: Proj2.asm
  5. ; author: xxxxx
  6. ; date: 04/26/07
  7. ; Based on: xxxxx
  8. ;
  9. ; ----------------------------------------
  10.  
  11. ; ----------------------------------------
  12.  
  13.  
  14.  
  15. .MODEL SMALL
  16. .STACK 100H
  17. .DATA
  18. CR EQU 0DH ; Carriage Return Code
  19. LF EQU 0AH ; Line Feed Control Code
  20. DOSEXIT EQU 4CH ; DOS exit code for 21h int
  21.  
  22.  
  23. para_list LABEL BYTE
  24. max_len db 20
  25. act_len db ?
  26. theword db 20 DUP(' ')
  27. MSG1 DB 'Enter a word $'
  28.  
  29. ItIs DB 'The word is a Palindrome $'
  30. ItIsNot DB 'The word is not a Palindrome $'
  31.  
  32.  
  33. ; --------- End of Data Segment ----------
  34. .CODE
  35. Main PROC
  36.  
  37. ;------------------------------------------
  38. ; The routine performs basic
  39. ; "housekeeping" operations necessary in
  40. ; any Assembly Language Program running
  41. ; under DOS or Windows...
  42. ; 1 - Establish Addressability to the
  43. ; Data Segment of the program.
  44. ;------------------------------------------
  45.  
  46. HouseKeeping:
  47.  
  48. mov ax,@data ;get addr. of DSeg.
  49. mov ds,ax ;set in DS Reg.
  50.  
  51. ;------------------------------------------
  52. ; Routine "GetPut" will...
  53. ; 1 - Display prompt message.
  54. ; 2 - capture user provided ASCII
  55. ; letter (located in AL register).
  56. ; 3 - Convert the letter to it's decimal
  57. ; equivalent.
  58. ; 4 - Display the converted letter within
  59. ; an "echoing" message.
  60. ;------------------------------------------
  61. Prompt:
  62.  
  63.  
  64. lea dx,MSG1 ;addr. of 1st msg
  65. mov ah,9h ;set for str. displ.
  66. int 21H ;call DOS to displ.
  67.  
  68. ;DISPLAY MESSAGE ABOVE;
  69.  
  70.  
  71. GetWord:
  72. mov ah,0Ah ;set func. to Get String
  73. lea DX,Para_list ;load address of para list
  74. int 21H ;call DOS (val-AL)
  75.  
  76.  
  77.  
  78. mov theword,al ;move input to theword
  79. lea dx,theword
  80. mov ah,9
  81. int 21h
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. ;------------------------------------------
  96. ; The routine sets the exit code and
  97. ; calls DOS. This is the appropriate
  98. ; technique for terminating a non-
  99. ; resident program running under DOS.
  100. ;------------------------------------------
  101.  
  102. PgmExit:
  103. mov ah,DOSEXIT ;set Exit code
  104. int 21H ;and call DOS
  105. Main EndP
  106. End Main

Now I need an idea of how to check if it is an palindrome or not.
Last edited by gparadox; Apr 26th, 2007 at 7:12 pm. Reason: to put it in code format
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gparadox is offline Offline
15 posts
since Apr 2007
Apr 26th, 2007
0

Re: Help on Storing Strings from Keyboard...

For some reason it is writing it backwards, but it skips the first letter. If I enter georgios, it will display 'soigroe'.
Any idea why it is skipping the first letter?
Assembly Syntax (Toggle Plain Text)
  1. TITLE Proj2
  2.  
  3. PAGE 56,90
  4. ; file: Proj2.asm
  5. ; date: 04/26/07
  6. ; ----------------------------------------
  7. ;
  8. ;
  9. ; This program will take a name entered by the user
  10. ; and display it backwards. It will also tell the
  11. ; user whether the word is a palindrome or not.
  12. ; ----------------------------------------
  13.  
  14.  
  15.  
  16. .MODEL SMALL
  17. .STACK 100H
  18. .DATA
  19. CR EQU 0DH ; Carriage Return Code
  20. LF EQU 0AH ; Line Feed Control Code
  21. DOSEXIT EQU 4CH ; DOS exit code for 21h int
  22.  
  23.  
  24. para_list LABEL BYTE
  25. max_len db 20
  26. act_len db ?
  27. theword db 20 DUP(' ')
  28. MSG1 DB 'Enter a word $'
  29.  
  30. ItIs DB 'The word is a Palindrome $'
  31. ItIsNot DB 'The word is not a Palindrome $'
  32. MSG2 DB 'The word backwards is $'
  33. wordbw DB 12 DUP(20H),'$'
  34.  
  35.  
  36. ; --------- End of Data Segment ----------
  37. .CODE
  38. Main PROC
  39.  
  40. ;------------------------------------------
  41. ; The routine performs basic
  42. ; "housekeeping" operations necessary in
  43. ; any Assembly Language Program running
  44. ; under DOS or Windows...
  45. ; 1 - Establish Addressability to the
  46. ; Data Segment of the program.
  47. ;------------------------------------------
  48.  
  49. HouseKeeping:
  50.  
  51. mov ax,@data ;get addr. of DSeg.
  52. mov ds,ax ;set in DS Reg.
  53.  
  54. ;------------------------------------------
  55. ; Routine "GetPut" will...
  56. ; 1 - Display prompt message.
  57. ; 2 - capture user provided ASCII
  58. ; letter (located in AL register).
  59. ; 3 - Convert the letter to it's decimal
  60. ; equivalent.
  61. ; 4 - Display the converted letter within
  62. ; an "echoing" message.
  63. ;------------------------------------------
  64. Prompt:
  65.  
  66.  
  67. lea dx,MSG1 ;addr. of 1st msg
  68. mov ah,9h ;set for str. displ.
  69. int 21H ;call DOS to displ.
  70.  
  71. mov ah, 06h
  72. mov al,00h
  73. int 10h
  74. ;DISPLAY MESSAGE ABOVE;
  75.  
  76.  
  77. GetWord:
  78. mov ah,0Ah ;set func. to Get String
  79. lea DX,Para_list ;load address of para list
  80. int 21H ;call DOS (val-AL)
  81.  
  82. mov theword,al ;move input to theword
  83.  
  84. ;Clear Screen
  85. mov ax,0600h
  86. mov bh,07
  87. mov cx,0000
  88. mov dx,184fh
  89. int 10h
  90. ;Clear Screen
  91.  
  92.  
  93. ChangeWord:
  94.  
  95. CLD
  96.  
  97.  
  98. MOV CX,20
  99. LEA SI,theword
  100. LEA DI,wordbw+11
  101.  
  102. L20:
  103. LODSB
  104. MOV [DI],AL
  105. DEC DI
  106. LOOP L20
  107.  
  108.  
  109.  
  110. ;Clear Screen
  111. mov ax,0600h
  112. mov bh,07
  113. mov cx,0000
  114. mov dx,184fh
  115. int 10h
  116. ;Clear Screen
  117.  
  118. lea dx, wordbw
  119. mov ah,9
  120. int 21h
  121.  
  122.  
  123.  
  124. ;------------------------------------------
  125. ; The routine sets the exit code and
  126. ; calls DOS. This is the appropriate
  127. ; technique for terminating a non-
  128. ; resident program running under DOS.
  129. ;------------------------------------------
  130.  
  131. PgmExit:
  132. mov ah,DOSEXIT ;set Exit code
  133. int 21H ;and call DOS
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. Main EndP
  141. End Main
Last edited by ~s.o.s~; Jan 8th, 2011 at 3:06 am. Reason: snipped out personal information as per user request
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gparadox is offline Offline
15 posts
since Apr 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Assembly Help in Programming
Next Thread in Assembly Forum Timeline: need help - checking value





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC