A program in assembly language to print out the length of string – IGNOU MCA Assignment 2014 – 15

By | July 19, 2014

 MASTER OF COMPUTER APPLICATIONS
Course Code : MCSL-017
Course Title : C and Assembly Language Programming
Assignment Number : MCA(1)/L017/Assign/2014-15
Maximum Marks : 100
Weightage : 25%

 

Write a program in assembly language to print out the length of string. 

 

DATA SEGMENT
STR DB ‘GANGADHAR$’
MSG1 DB 10,13,’THE STRING IN THE MEMORY IS : $’
MSG2 DB 10,13,’LENGTH OF THE STRING IS :- $’
LEN DB 0H
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 STR

LEA SI,STR
NEXT:
CMP [SI],’$’
JE DONE
INC LEN
INC SI
JMP NEXT
DONE:
DISPLAY MSG2

MOV AL,LEN
ADD AL,30H

MOV DL,AL
MOV AH,2
INT 21H

MOV AH,4CH
INT 21H
CODE ENDS

END START

Program Code :

  1. DATA SEGMENT
  2. STR DB 'GANGADHAR$'
  3. MSG1 DB 10,13,'THE STRING IN THE MEMORY IS : $'
  4. MSG2 DB 10,13,'LENGTH OF THE STRING IS :- $'
  5. LEN DB 0H
  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. DISPLAY MSG1
  18. DISPLAY STR
  19. LEA SI,STR
  20. NEXT:
  21. CMP [SI],'$'
  22. JE DONE
  23. INC LEN
  24. INC SI
  25. JMP NEXT
  26. DONE:
  27. DISPLAY MSG2
  28. MOV AL,LEN
  29. ADD AL,30H
  30. MOV DL,AL
  31. MOV AH,2
  32. INT 21H
  33. MOV AH,4CH
  34. INT 21H
  35. CODE ENDS
  36. END START

Screen shots :-

Asm_program_String_Length

After Execution :-

Asm_program_String_Length_Output

Leave a Reply