Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org 100h
- NL_ equ 0dh, 0ah
- start:
- mov ah, 9 ;output - helloStr
- mov dx, helloStr_
- int 21h
- mov ah, 1 ;echo one symbol input; output - ascii code of symbol in al
- int 21h
- xor ah, ah ;clear ah
- push ax ;save symbol code to stack
- mov ah, 9 ;output - findStr
- mov dx, findStr_
- int 21h
- mov ah, 0ah ;input - string
- mov dx, buffStr_
- int 21h
- cld ;direction - forward
- pop ax ;retrieve symbol code
- xor ch, ch ;clear ch
- mov cl, [buffStr_ + 1] ;amount of letters to cl
- add cl, 1 ;include last 0dh
- mov di, buffStr_ ;address of string...
- add di, 2 ;...starts here
- next_:
- repne scasb ;repeat if not equal scasb (cmp al, di; inc di)
- jcxz result_ ;if it's here it's either: found a symbol or end of string; jcxz - jump if cx zero
- add ah, 1 ;amount of repetitioons
- jmp next_ ;next checks
- result_:
- mov bl, ah ;answer to bl
- add bl, '0' ;convert to ascii
- mov ah, 9 ;output - resultStr
- mov dx, resultStr_
- int 21h
- mov ah, 2 ;output - answer
- mov dl, bl
- int 21h
- mov ah, 9 ;output - byeStr
- mov dx, byeStr_
- int 21h
- mov ah, 7 ;wait for input
- int 21h
- ret
- helloStr_ db "This program finds how many times a symbol occurs in a string", NL_, "Input symbol you want to find:", NL_, "$"
- findStr_ db NL_, "Input string you will be looking in:", NL_, "$"
- buffStr_ db 10, 0, 10 dup (?)
- resultStr_ db NL_, "Result: $"
- byeStr_ db NL_, "The program has now terminated$"
Add Comment
Please, Sign In to add comment