Advertisement
Vanya_Shestakov

Untitled

Apr 25th, 2021
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.         org 100h
  3.         NL equ 0dh, 0ah
  4.  
  5. start:
  6.  
  7.         mov ah, 9 ;output task
  8.         mov dx, taskStr
  9.         int 21h
  10.  
  11.         mov ah, 0ah ;input - string
  12.         mov dx, buffStr
  13.         int 21h
  14.  
  15.         mov ah, 2 ;output - new line
  16.         mov dx, 0d0ah
  17.         int 21h
  18.  
  19.         cld ;direction - forward (df = 0)
  20.         mov si, buffStr ;SOURCE address...
  21.         add si, 12 ;first two bytes MAX_LEN and LEN + tenth symbol = +12
  22.         mov di, destStr ;DESTINATION address
  23.         mov cx, 6 ;10 11 12 13 14 15 - 6 symbols
  24.         rep movsb ;repeat movsb (movs byte), until cx = 0
  25.  
  26.         mov ah, 9 ;output - resultStr
  27.         mov dx, resultStr
  28.         int 21h
  29.  
  30.         mov dx, destStr ;output - copied string
  31.         int 21h
  32.  
  33.         mov dx, byeStr ;output - byeStr
  34.         int 21h
  35.  
  36.         mov ah, 7 ;wait for input
  37.         int 21h
  38.  
  39.         ret
  40.  
  41. taskStr db "This program transfers bytes 10 to 15", NL, "Input string with length of 16:", NL , "$"
  42. buffStr db 17, 0, 17 dup (?)
  43. destStr db "******$"
  44. resultStr db "Result string:", NL, "$"
  45. byeStr db NL, "The program has now terminated.$"
  46.  
  47.                              
  48. org 100h
  49.  
  50. NL equ 0dh, 0ah
  51.  
  52. start:
  53.         mov ah, 9 ;output task
  54.         mov dx, taskStr
  55.         int 21h
  56.  
  57.         mov ah, 1 ;echo one symbol input; output - ascii code of symbol in al
  58.         int 21h
  59.         xor ah, ah ;clear ah
  60.         push ax ;save symbol code to stack
  61.  
  62.         mov ah, 9 ;output - findStr
  63.         mov dx, findStr
  64.         int 21h
  65.  
  66.         mov ah, 0ah ;input - string
  67.         mov dx, buffStr
  68.         int 21h
  69.  
  70.         cld ;direction - forward
  71.         pop ax ;retrieve symbol code
  72.         xor ch, ch ;clear ch
  73.         mov cl, [buffStr + 1] ;amount of letters to cl
  74.         add cl, 1 ;include last 0dh
  75.         mov di, buffStr ;address of string...
  76.         add di, 2 ;...starts here
  77.  
  78. next_:
  79.         repne scasb ;repeat if not equal scasb (cmp al, di; inc di)
  80.         jcxz result_ ;if it's here it's either: found a symbol or end of string; jcxz - jump if cx zero
  81.         add ah, 1 ;amount of repetitioons
  82.         jmp next_ ;next checks
  83.  
  84. result_:
  85.         mov bl, ah ;answer to bl
  86.         add bl, '0' ;convert to ascii
  87.  
  88.         mov ah, 9 ;output - resultStr
  89.         mov dx, resultStr
  90.         int 21h
  91.  
  92.         mov ah, 2 ;output - answer
  93.         mov dl, bl
  94.         int 21h
  95.  
  96.         mov ah, 9 ;output - byeStr
  97.         mov dx, byeStr
  98.         int 21h
  99.  
  100.         mov ah, 7 ;wait for input
  101.         int 21h
  102.         ret
  103.  
  104. taskStr db "This program finds how many times a symbol occurs in a string", NL, "Input symbol you want to find:", NL, "$"
  105. findStr db NL, "Input string you will be looking in:", NL, "$"
  106. buffStr db 10, 0, 10 dup (?)
  107. resultStr db NL, "Result: $"
  108. byeStr db NL, "The program has now terminated$"
  109.  
  110.                        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement