madopew

5_2

Apr 2nd, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     org 100h
  2.  
  3.     NL_ equ 0dh, 0ah
  4.  
  5. start:
  6.     mov ah, 9 ;output - helloStr
  7.     mov dx, helloStr_
  8.     int 21h
  9.  
  10.     mov ah, 1 ;echo one symbol input; output - ascii code of symbol in al
  11.     int 21h
  12.     xor ah, ah ;clear ah
  13.     push ax ;save symbol code to stack
  14.  
  15.     mov ah, 9 ;output - findStr
  16.     mov dx, findStr_
  17.     int 21h
  18.  
  19.     mov ah, 0ah ;input - string
  20.     mov dx, buffStr_
  21.     int 21h
  22.  
  23.     cld ;direction - forward
  24.     pop ax ;retrieve symbol code
  25.     xor ch, ch ;clear ch
  26.     mov cl, [buffStr_ + 1] ;amount of letters to cl
  27.     add cl, 1 ;include last 0dh
  28.     mov di, buffStr_ ;address of string...
  29.     add di, 2 ;...starts here
  30.     next_:
  31.         repne scasb ;repeat if not equal scasb (cmp al, di; inc di)
  32.     jcxz result_ ;if it's here it's either: found a symbol or end of string; jcxz - jump if cx zero
  33.     add ah, 1 ;amount of repetitioons
  34.     jmp next_ ;next checks
  35.  
  36. result_:
  37.     mov bl, ah ;answer to bl
  38.     add bl, '0' ;convert to ascii
  39.  
  40.     mov ah, 9 ;output - resultStr
  41.     mov dx, resultStr_
  42.     int 21h
  43.  
  44.     mov ah, 2 ;output - answer
  45.     mov dl, bl
  46.     int 21h
  47.  
  48.     mov ah, 9 ;output - byeStr
  49.     mov dx, byeStr_
  50.     int 21h
  51.  
  52.     mov ah, 7 ;wait for input
  53.     int 21h
  54.     ret
  55.  
  56. helloStr_ db "This program finds how many times a symbol occurs in a string", NL_, "Input symbol you want to find:", NL_, "$"
  57. findStr_ db NL_, "Input string you will be looking in:", NL_, "$"
  58. buffStr_ db 10, 0, 10 dup (?)
  59. resultStr_ db NL_, "Result: $"
  60. byeStr_ db NL_, "The program has now terminated$"
Add Comment
Please, Sign In to add comment