Advertisement
Nahid8195

Spacce count

Dec 9th, 2021
2,800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print macro m
  2. mov ah,09h
  3. mov dx,offset m
  4. int 21h
  5. endm
  6.  
  7. .model small
  8.  
  9.  
  10. ;******  Data Segment ******
  11. .data
  12.  
  13. empty db 10,13, "   $"
  14. str1 db 25,?,25 dup('$')
  15. mstring db 10,13, "Enter the string: $"
  16. mscount db 10,13, "Number of spaces: $"
  17. mlength db 10,13, "Length is: $"
  18. scount db ?
  19.  
  20.  
  21.  
  22. ;********** Code Segment ************
  23.  
  24. .code
  25.  
  26. start:
  27. mov ax,@data
  28. mov ds,ax
  29.  
  30.         print mstring
  31.         call accept_string
  32.         mov si,offset str1+2  ;position si to start of the string
  33.        
  34.         mov cl,str1+1         ;copy length in cl
  35.         mov dh,00             ;counter to store number of spaces  
  36. cmpagain1:  mov al,[si]      ;copy content at memory location "si" in "al"
  37.            cmp al,' '        ;compare "al" with space
  38.            jne below         ;if not equal jump to label "below"
  39.            inc dh
  40.        
  41. below:  inc si               ;move to next character
  42.         dec cl               ;decrement string length counter
  43.         jnz cmpagain1        ;if not zero check again
  44.        
  45.         mov scount,dh       ;save the count in memory location "scount"
  46.         mov bl,scount       ;copy count to "bl" for printing
  47.         print mscount
  48.         call display1
  49.  
  50. exit:
  51. mov ah,4ch       ;exit the program
  52. int 21h
  53.  
  54.  
  55. ;accept procedure
  56.  
  57. accept proc near
  58.  
  59. mov ah,01
  60. int 21h
  61. ret
  62. accept endp
  63.  
  64. display1 proc near
  65.  
  66.    mov al,bl
  67.    mov bl,al
  68.    and al,0f0h
  69.    mov cl,04
  70.    rol al,cl
  71.  
  72.    cmp al,09
  73.    jbe number
  74.    add al,07
  75. number:  add al,30h
  76.          mov dl,al
  77.          mov ah,02
  78.          int 21h
  79.  
  80.          mov al,bl
  81.          and al,00fh
  82.          cmp al,09
  83.          jbe number2
  84.          add al,07
  85. number2:  add al,30h
  86.           mov dl,al
  87.           mov ah,02
  88.           int 21h
  89. ret
  90. display1 endp
  91.  
  92.  
  93.  
  94. accept_string proc near
  95.  
  96. mov ah,0ah          ;accept string from user function
  97. mov dx,offset str1  ; store the string in memory pointed by "DX"
  98. int 21h
  99. ret
  100. accept_string endp
  101.  
  102. end start
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement