An Assembly Language program to reverse a string in memory and displayed – IGNOU MCA Assignment 2013

By | April 15, 2014

BACHELOR  OF COMPUTER APPLICATIONS
Course Code : BCSL-022
Course Title : Assembly Language Programming Lab
Assignment Number : BCA(II)/BCSL022/Assign/13

 

Write and run an Assembly language program that reverses a string. You may assume that the string is available in the memory and is 6 byte long. The reversed string should be stored in separate memory locations and should be displayed

 

DATA SEGMENT
    STR1 DB “MAHESH$”
    STR2 DB 7 DUP (‘$’)
    MSG1 DB 10,13,’STORED STRING IN MEMORY IS : $’
    MSG2 DB 10,13,’REVERSE STRING IS : $’
DATA ENDS

DISPLAY MACRO MSG
    MOV AH,9
    LEA DX,MSG
    INT 21H
ENDM   
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START:
        MOV AX,DATA
        MOV DS,AX                
               
        DISPLAY MSG1
                    
        DISPLAY STR1
                       
        LEA SI,STR2
        LEA DI,STR1
        ADD DI,5
               
        MOV CX,6
REVERSE:
        MOV AL,[DI]
        MOV [SI],AL
        INC SI
        DEC DI
        LOOP REVERSE
       
        DISPLAY MSG2
                   
        DISPLAY STR2
                     
        MOV AH,4CH
        INT 21H
CODE ENDS
END START

 

program code :

  1. DATA SEGMENT
  2.     STR1 DB "MAHESH$"
  3.     STR2 DB 7 DUP ('$')
  4.     MSG1 DB 10,13,'STORED STRING IN MEMORY IS : $'
  5.     MSG2 DB 10,13,'REVERSE STRING IS : $'
  6. DATA ENDS
  7. DISPLAY MACRO MSG
  8.     MOV AH,9
  9.     LEA DX,MSG
  10.     INT 21H
  11. ENDM   
  12. CODE SEGMENT
  13.     ASSUME CS:CODE,DS:DATA
  14. START:
  15.         MOV AX,DATA
  16.         MOV DS,AX                
  17.                
  18.         DISPLAY MSG1
  19.                     
  20.         DISPLAY STR1
  21.                        
  22.         LEA SI,STR2
  23.         LEA DI,STR1
  24.         ADD DI,5
  25.                
  26.         MOV CX,6
  27. REVERSE:
  28.         MOV AL,[DI]
  29.         MOV [SI],AL
  30.         INC SI
  31.         DEC DI
  32.         LOOP REVERSE
  33.        
  34.         DISPLAY MSG2
  35.                    
  36.         DISPLAY STR2
  37.                      
  38.         MOV AH,4CH
  39.         INT 21H
  40. CODE ENDS
  41. END START

Screen shots :-

Asm_program_Rev_Str_Memory

Output :-

 Asm_program_Rev_Str_Memory_Output

Leave a Reply