Write an assembly language procedure using string instructio

Write an assembly language procedure using string instruction. Given two strings, SI and S2, determine if S2 is a sub string of S1. Sub string example: S1: \'I am happy today\', S2: \'happy\', S2 is a substring of S1. S1: \'I am happy today\', S2: \'sad\', S2 is not a substring of S1. Call above procedure in an assembly language program and show the result of the procedure. Give you two files, a.txt and b.txt. Append data in b.txt to a.txt. Input a.txt and b.txt. Output a.txt as a combination of a.txt and b.txt.

Solution

DATA SEGMENT   ;Data Segment starts here
STR1 DB ‘I am happy Today$’
SUBSTR1 DB ‘happy$’
LEN1 DB 0
LEN2 DB 0
MSG1 DB 10,13,’Our STRING IS : $’
MSG2 DB 10,13,’SUBSTRING IS : $’
MSG3 DB 10,13,’SUBSTRING FOUND...!!! : $’
POS DB -1
RTN DB ‘-1$’
DATA ENDS   ;Data Segement ends here

DISPLAY MACRO MSG   ;Message Macro starts
MOV AH,9
LEA DX,MSG
INT 21H
ENDM   ;Message macro ends

CODE SEGMENT
ASSUME CS:CODE,DS:DATA   ;tells the assembler that CS segment points to Code and DS to   
       ; Data
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1   ;Display message1
DISPLAY STR1   ;Display I am happy today
DISPLAY MSG2   ;Display mesaage2
DISPLAY SUBSTR1 ;Display substring happy

LEA SI,STR1
L1:
CMP [SI],’$’
JE D1
INC LEN1
INC SI
JMP L1
D1:
LEA DI,SUBSTR1
L2:
CMP [DI],’$’
JE D2
INC LEN2
INC DI
JMP L2

D2:
DISPLAY MSG3
LEA SI,STR1
MOV AL,LEN1
SUB AL,LEN2
MOV CL,AL
MOV CH,0
FIRSTLOOP:
INC POS
MOV AL,[SI]
CMP AL,SUBSTR1[0]
JE CMPR
INC SI
LOOP FIRSTLOOP

CMPR: INC SI
MOV AL,[SI]
CMP AL,SUBSTR1[1]
JNE NOT_EQUAL
INC SI
MOV AL,[SI]
CMP AL,SUBSTR1[2]
JE EQUAL

NOT_EQUAL:
MOV POS,-1
DISPLAY RTN
JMP EXIT

EQUAL:
MOV DL,POS
ADD DL,30H
MOV AH,2
INT 21H

EXIT: MOV AH,4CH
INT 21H

CODE ENDS

END START

 Write an assembly language procedure using string instruction. Given two strings, SI and S2, determine if S2 is a sub string of S1. Sub string example: S1: \'I
 Write an assembly language procedure using string instruction. Given two strings, SI and S2, determine if S2 is a sub string of S1. Sub string example: S1: \'I

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site