Logo 
Search:

Assembly Language Articles

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

Program to find the length of a string

Posted By: Lurline Fischer     Category: Assembly Language     Views: 20113

Write a program to find the length of a string.

Code for Program to find the length of a string in Assembly Language


DATA SEGMENT
        STR1 DB "ENTER YOUR STRING HERE ->$"
        STR2 DB "YOUR STRING IS ->$"
        STR3 DB "LENGTH OF STRING IS(DIRECT) ->$"
        STR4 DB "LENGTH OF STRING IS(COUNT) ->$"
        INSTR1 DB 20 DUP("$")
        NEWLINE DB 10,13,"$"
        LN DB 5 DUP("$")
        N DB "$"
        S DB ?

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,STR2
        INT 21H

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

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

;PRINT LENGTH OF STRING (DIRECT)
        MOV AH,09H
        LEA DX,STR3
        INT 21H

        MOV BL,INSTR1+1

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

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


;PRINT LENGTH OF STRING ANOTHER WAY

        MOV AH,09H
        LEA DX,STR4
        INT 21H
        
        ADD SI,2
        MOV AX,00


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

     L1:SUB AL,1
        ADD AL,30H
                       
        MOV AH,02H
        MOV DL,AL
        INT 21H


        MOV AH,4CH
        INT 21H


CODE ENDS
END START


;OUTPUT:-
;Z:\SEM3\SS\21-30>P24
;ENTER YOUR STRING HERE ->JINESH
;YOUR STRING IS ->JINESH
;LENGTH OF STRING IS(DIRECT) ->:6
;LENGTH OF STRING IS(COUNT) ->:6
  
Share: 


Didn't find what you were looking for? Find more on Program to find the length of a string Or get search suggestion and latest updates.

Lurline Fischer
Lurline Fischer author of Program to find the length of a 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].

 
Chariz Hong from Philippines Comment on: Jul 08
the count string code will not works if the string input is greater than 10.. why??

View All Comments