Help on Storing Strings from Keyboard...

Reply

Join Date: Apr 2007
Posts: 15
Reputation: gparadox is an unknown quantity at this point 
Solved Threads: 0
gparadox gparadox is offline Offline
Newbie Poster

Help on Storing Strings from Keyboard...

 
0
  #1
Apr 26th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 15
Reputation: gparadox is an unknown quantity at this point 
Solved Threads: 0
gparadox gparadox is offline Offline
Newbie Poster

Re: Help on Storing Strings from Keyboard...

 
0
  #2
Apr 26th, 2007
OK I figured out how to store string input.
but the output disappears, I want it to stay.
  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 15
Reputation: gparadox is an unknown quantity at this point 
Solved Threads: 0
gparadox gparadox is offline Offline
Newbie Poster

Re: Help on Storing Strings from Keyboard...

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

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC