why there is ascii code infront?

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 14
Reputation: rayda is an unknown quantity at this point 
Solved Threads: 0
rayda rayda is offline Offline
Newbie Poster

why there is ascii code infront?

 
0
  #1
Oct 17th, 2009
i am writing a assembly code to count the number of words in a sentence.
below is my coding:
  1. .model small
  2. .stack 200h
  3. .386
  4. .data
  5.  
  6. message1 db 10,13, 'Word counter : Enter the sentence to be calculated$'
  7. result db 10,13, 'Number of words : $'
  8. counter db 5,6 dup(0)
  9. sentence db 10,13, 'hello world and me. $'
  10.  
  11. .code
  12.  
  13. Start:
  14. mov ax,seg message1
  15. mov ds,ax
  16. mov dx,offset message1
  17. mov ah,09h
  18. int 21h
  19.  
  20. mov ax,seg sentence
  21. mov ds,ax
  22. mov bx,offset sentence
  23. mov ax,0
  24.  
  25. mov cx,0
  26. mov di,2
  27.  
  28. check1:
  29. mov al,[bx+di]
  30.  
  31. cmp al,'.'
  32. je check2
  33. cmp al,','
  34. je check2
  35. cmp al,' '
  36. je count
  37. cmp al,'$'
  38. je done
  39. jmp skip
  40.  
  41. check2:
  42. inc cx
  43. inc di
  44. mov al,[bx+di]
  45. cmp al,' '
  46. je skip
  47. jmp check1
  48.  
  49. skip:
  50. inc di
  51. jmp check1
  52.  
  53. count:
  54. inc cx
  55. inc di
  56. jmp check1
  57.  
  58. done:
  59. mov ax,cx
  60. aaa
  61. add ax,3030h
  62.  
  63. cmp ah,30h
  64. je singleNumber
  65. jmp doubleNumber
  66.  
  67. singleNumber:
  68.  
  69. mov bx,offset counter
  70. mov [bx+2],al
  71. mov al,'$'
  72. mov [bx+3],al
  73. jmp print
  74.  
  75. doubleNumber:
  76.  
  77. mov bx,offset counter
  78. mov [bx+2],ah
  79. mov [bx+3],al
  80. mov al,'$'
  81. mov [bx+4],al
  82.  
  83. print:
  84.  
  85. mov dx,offset result
  86. mov ah,09h
  87. int 21h
  88.  
  89. mov dx,offset counter
  90. mov ah,09h
  91. int 21h
  92.  
  93. .exit
  94. end start
when i run it, there is a ascii symbol infront of the number of word.
isit something wrong with my coding?
please help.
thank you
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 140
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 14
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #2
Oct 18th, 2009
You loaded your counter variable starting at counter+2 which
causes the ASCII character 5 to be printed on the screen,
that is the initializer you used for the first byte of the
array at counter:

Make these changes:
  1. singleNumber:
  2. mov bx,offset counter
  3. mov [bx+0],al ; changed +2 to +0
  4. mov al,'$'
  5. mov [bx+1],al ; changed +3 to +1
  6. jmp print
  7. doubleNumber:
  8. mov bx,offset counter
  9. mov [bx+0],ah ; changed +2 to +0
  10. mov [bx+1],al ; changed +3 to +1
  11. mov al,'$'
  12. mov [bx+2],al ; changed +4 to +2

That will eliminate the club symbol (ASCI '\5') from being
printed on the console.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 14
Reputation: rayda is an unknown quantity at this point 
Solved Threads: 0
rayda rayda is offline Offline
Newbie Poster
 
0
  #3
Oct 18th, 2009
yup2, that solved the problem..
thank you =)
but then, isnt the [offset counter+2] is the memory location that store the total number of count?
i am a bit confuse this,
sorry, i am still a beginner to assembly..
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC