Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to find the no. of occurrences of character `c' in the input string

Posted By: Arnelle Schmidt     Category: Assembly Language     Views: 7425

Write a program to find the no. of occurrences of character `c' in the input string.

Code for Program to find the no. of occurrences of character `c' in the input string in Assembly Language

DATA SEGMENT
        STR1 DB "ENTER FIRST STRING HERE ->$"
        STR2 DB "OCCURENCE OF C IS : ->$"
        STR11 DB "GIVEN STRING IS : ->$"
        OCC DB "C"
        N DB ?
        INSTR1 DB 20 DUP("$")
        NEWLINE DB 10,13,"$"

DATA ENDS

CODE SEGMENT

        ASSUME DS:DATA,CS:CODE
START:

        MOV AX,DATA
        MOV DS,AX

        LEA SI,INSTR1

;GET STRING
        MOV AH,09H
        LEA DX,STR1
        INT 21H

        MOV AH,0AH
        MOV DX,SI
        INT 21H


        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

;PRINT THE STRING

        MOV AH,09H
        LEA DX,STR11
        INT 21H

        MOV AH,09H
        LEA DX,INSTR1+2
        INT 21H

        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H


;FIND THE OCCURENCE OF C
        MOV AX,00

        MOV AH,09H
        LEA DX,STR2
        INT 21H

        MOV BX,00

        ADD SI,1
        

     L2:INC SI
        CMP BYTE PTR[SI],"$"
        JE L1
        CMP BYTE PTR[SI],"C"
        JNE L2
        ADD BL,1
        JMP L2


    L1: MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

        ADD BL,30H

        MOV AH,02H
        MOV DL,BL
        INT 21H

        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

        MOV AH,4CH
        INT 21H


CODE ENDS
END START


;OUTPUT:-
;Z:\SEM3\SS\21-30>P30
;ENTER FIRST STRING HERE ->JINESH
;GIVEN STRING IS : ->JINESH
;OCCURENCE OF C IS : ->
;0
;
;Z:\SEM3\SS\21-30>P30
;ENTER FIRST STRING HERE ->CAPITAL
;GIVEN STRING IS : ->CAPITAL
;OCCURENCE OF C IS : ->
;1
  
Share: 



Arnelle Schmidt
Arnelle Schmidt author of Program to find the no. of occurrences of character `c' in the input string is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Assembly Language:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!