add1

Monday, October 10, 2016

MCSL 017 C and Assembly Language Programming 16-17


MCSL 017 
MCA 1st semester 
Section 2: Assembly Language Programming Lab

(a) Write a program in assembly language to find if two given strings are of equal length.

DATA SEGMENT
STR1 DB 'International$'
STR2 DB 'universal$'
MSG1 DB 10,13,'LENGTH OF THE STRING 1 IS :- $'
MSG2 DB 10,13,'LENGTH OF THE STRING 2 IS :- $'
MSG3 DB 10,13,'STRING ARE OF EQUAL LENGTH$'
MSG4 DB 10,13,'STRING ARE OF NOT EQUAL LENGTH$'
LEN1 DB 0H
LEN2 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

LEA SI,STR1
NEXT1:
CMP [SI],'$'
JE DONE1
INC LEN1
INC SI
JMP NEXT1
DONE1:
DISPLAY MSG1

MOV AL,LEN1
ADD AL,30H

MOV DL,AL
MOV AH,2
INT 21H

LEA DI,STR2
NEXT2:
CMP [DI],'$'
JE DONE2
INC LEN2
INC DI
JMP NEXT2
DONE2:
DISPLAY MSG2

MOV AL,LEN2
ADD AL,30H

MOV DL,AL
MOV AH,2
INT 21H

MOV AL,LEN1
CMP AL,LEN2
JE EQUAL

DISPLAY MSG4
JMP EXIT
EQUAL:
DISPLAY MSG3

EXIT:
MOV AH,4CH
INT 21H
CODE ENDS

END START

2 comments: