User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 423,386 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,727 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 698 | Replies: 0
Reply
Join Date: Aug 2007
Posts: 1
Reputation: lilo12 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
lilo12 lilo12 is offline Offline
Newbie Poster

Question problem with output values

  #1  
Aug 10th, 2007
  1. TITLE charwordcount
  2. DOSSEG
  3. .MODEL SMALL
  4. .STACK 100h
  5. .DATA
  6.  
  7. msg1 db "Enter a sentence please: $"
  8. msg2 db " Do you want to try again (Y/N)? $"
  9. msg3 db "Character count = $"
  10. msg4 db "Word count = $"
  11. sentence db 84 dup("$")
  12. try db 5 dup("$")
  13. crlf db 13, 10, "$"
  14. error1 db "*** Error: Null Input ***$"
  15. error2 db "*** Error: No period or invalid terminating character at the end of the sentence ***$"
  16. error3 db "*** Error: Two or more spaces between words ***$"
  17. count db 00
  18.  
  19. .CODE
  20.  
  21. BEGIN: mov ax, @data
  22. mov ds, ax
  23. mov es, ax
  24.  
  25. ; clear screen
  26. mov al, 03h
  27. mov ah, 00h
  28. int 10h
  29.  
  30. ; print msg1
  31. ulit: lea dx, msg1
  32. mov ah, 09h
  33. int 21h
  34.  
  35. ; get sentence
  36. mov byte ptr sentence, 81
  37. lea dx, sentence
  38. mov ah, 0Ah
  39. int 21h
  40.  
  41. ; next line
  42. lea dx, crlf
  43. mov ah, 09h
  44. int 21h
  45.  
  46. ; check for null value and output error msg
  47. mov si, 0002
  48. mov al, sentence[si]
  49. cmp al, 0dh
  50. je err1
  51. cmp al, ' '
  52. je err1
  53.  
  54. ; compare for two or more spaces
  55. ;mov si, 0002
  56. mov si, 0000
  57. c10: inc si
  58. mov al, sentence[si]
  59. cmp al, '$'
  60. je next
  61. cmp al, ' '
  62. je L11
  63. jmp c10
  64.  
  65. L11: inc si
  66. mov al, sentence[si]
  67. cmp al, ' '
  68. je err3
  69. dec si
  70. jmp c10
  71.  
  72. ; compare for terminaton
  73. ;mov si, 0001
  74. next: mov si, 0000
  75. L1: inc si
  76. mov al, sentence[si]
  77. cmp al, '.'
  78. je cchar
  79. cmp al, '$'
  80. je err2
  81. jmp L1
  82.  
  83. ; error message for null input
  84. err1: lea dx, error1
  85. mov ah, 09h
  86. int 21h
  87. jmp tanong
  88.  
  89. err3: lea dx, error3
  90. mov ah, 09h
  91. int 21h
  92. jmp tanong
  93.  
  94. ; print character message
  95. cchar: lea dx, msg3
  96. mov ah, 09h
  97. int 21h
  98.  
  99. ; count for characters
  100. mov si, 0001
  101. mov al, sentence[si]
  102. sub al, 01
  103. aam
  104. add ax, 3030h
  105. push ax
  106.  
  107. ; print number of char
  108. mov dl, ah
  109. mov ah, 02h
  110. int 21h
  111. pop ax
  112. mov dl, al
  113. mov ah, 02h
  114. int 21h
  115.  
  116. ; next line
  117. lea dx, crlf
  118. mov ah, 09h
  119. int 21h
  120.  
  121. ; print msg4
  122. lea dx, msg4
  123. mov ah, 09h
  124. int 21h
  125.  
  126. ; count number of words
  127. words: mov byte ptr count, 00
  128. ;mov si, 0002
  129. mov si, 0000
  130. c1: inc si
  131. mov al, sentence[si]
  132. cmp al, '$'
  133. je pcount
  134. cmp al, ' '
  135. je L10
  136. jmp c1
  137.  
  138. ; start counting words
  139. L10: inc byte ptr count
  140. jmp c1
  141.  
  142. ; print number of words
  143. pcount: mov al, count
  144. add al, 01
  145. aam
  146. add ax, 3030h
  147. push ax
  148.  
  149. ; print number of words
  150. mov dl, ah
  151. mov ah, 02h
  152. int 21h
  153. pop ax
  154. mov dl, al
  155. mov ah, 02h
  156. int 21h
  157. jmp tanong
  158.  
  159. ; error message for invalid terminator
  160. err2: lea dx, error2
  161. mov ah, 09h
  162. int 21h
  163. jmp tanong
  164.  
  165.  
  166. ; next line
  167. tanong: lea dx, crlf
  168. mov ah, 09h
  169. int 21h
  170.  
  171. ; try again
  172. lea dx, msg2
  173. mov ah, 09h
  174. int 21h
  175.  
  176. ; get try answer
  177. mov byte ptr try, 2
  178. lea dx, try
  179. mov ah, 0Ah
  180. int 21h
  181.  
  182. ; next line
  183. lea dx, crlf
  184. mov ah, 09h
  185. int 21h
  186.  
  187. ; check for answer
  188. mov si, 0002
  189. mov al, try[si]
  190. cmp al, 'Y'
  191. Jne tapos
  192. jmp ulit
  193.  
  194. ; next line
  195. lea dx, crlf
  196. mov ah, 09h
  197. int 21h
  198.  
  199. tapos:
  200.  
  201. mov ah, 4ch
  202. int 21h
  203. end BEGIN


;;; Hi guys, I'm really new in Assembly programming.. This code is running pretty good.. but i have a problem when it loops.. i think the counter is not resetting.. it gave me wrong values for the word count.. please help.. thanks
Last edited by stymiee : Aug 10th, 2007 at 1:38 pm. Reason: added code tags
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Assembly Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Assembly Forum

All times are GMT -4. The time now is 12:54 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC