Logo 
Search:

Assembly Language Articles

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

Program to find the reverse of a string

Posted By: Emma Brown     Category: Assembly Language     Views: 5711

Write a program to find the reverse of a string.

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

DATA SEGMENT
        STR1 DB "ENTER YOUR STRING HERE ->$"
        STR2 DB "YOUR STRING IS ->$"
        STR3 DB "REVERSE STRING IS ->$"
        INSTR1 DB 20 DUP("$")
        RSTR DB 20 DUP("$")
        NEWLINE DB 10,13,"$"
        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 THE REVERSE OF THE STRING

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

        MOV CL,INSTR1+1
        ADD CL,1
        ADD SI,2

     L1:
        INC SI

        CMP BYTE PTR[SI],"$"
        JNE L1

        DEC SI

        LEA DI,RSTR

     L2:MOV AL,BYTE PTR[SI]

        MOV BYTE PTR[DI],AL

        DEC SI
        INC DI
        LOOP L2

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

        MOV AH,09H
        LEA DX,RSTR
        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>P25
;ENTER YOUR STRING HERE ->JINESH
;YOUR STRING IS ->JINESH
;REVERSE STRING IS ->
;HSENIJ
  
Share: 


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

Emma Brown
Emma Brown author of Program to find the reverse of a string is from London, United Kingdom.
 
View All Articles

 
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!