Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please solve this question using Assembly Language 1. Write an assembly language

ID: 3682139 • Letter: P

Question

Please solve this question using Assembly Language

1. Write an assembly language program that allows a user to enter two strings, List1 and List2, of a size that does not exceed Maxsize. Then, the program asks the user to enter one character that indicates the type of operation requested according to the following table: Character 'c' or 'C', s or S Operation . Concatenates Listl and List2 and displays the resulting string » Displays a substring obtained from the first 4 characters of Listl . Displays a substring obtained from the first 4 characters of List2. Otherwise . Displays an error message and terminates. 2. Use the assembler directives SIZEOF, LENGTHOF, and OFFSET operators to make your program flexible as possible in handling any defined strings by the user. 3. Use the following procedures for input/output. For more details about these procedures see Chapter 5 of Irvine textbook.

Explanation / Answer

.model small .data m1 db 10d,13d,"Enter first string: $" m2 db 10d,13d,"Enter second string: $" m3 db 10d,13d,"Concatenated string: $" s1 db 20 dup('$') s2 db 20 dup('$') s3 db 40 dup('$') nwline db 10d,"$" m4 db 10d,13d,"Secong String is Substring.$" m5 db 10d,13d,"Secong String is not a Substring.$" m6 db 10d,13d,"No. Of Occurence: $" count db 1 dup(0) .code public concat,substring ;procedures scope has been made public ;accessible to other segments also ;*********Generalised 2 parameters 16 bit macro************ scall macro xx,yy lea dx,xx mov ah,yy int 21h endm ;end of macro ;*******************CONCATENATION PROCEDURE***************** concat proc mov ax,@data mov ds,ax scall m1,09h ;display m1 string scall s1,0Ah ;buffered s1 string input scall m2,09h ;display m2 string scall s2,0Ah ;buffered s2 string input lea si,s1 lea di,s3 inc si mov cl,[si] ;length of s1 string ;copying entire s1 string to s3 loop1: inc si mov al,[si] mov [di],al inc di dec cl jnz loop1 lea si,s2 inc si mov cl,[si] ;length of s2 string ;copying entire s2 string to s3 loop2: inc si mov al,[si] mov [di],al inc di dec cl jnz loop2 mov al,24h ;'$'=24h, putting $ at end of string s3 mov [di],al scall nwline,09h scall m3,09h ;display m3 string scall s3,09h ;display concatenated string ret ;return from prodecure endp ;end of prodecure ;****************SUBSTRING PROCEDURE********************** substring proc mov ax,@data mov ds,ax scall m1,09h ;display m1 string scall s1,0Ah ;accept s1 string scall m2,09h ;display m2 string scall s2,0Ah ;accept s2 string lea si,s1 inc si mov cl,[si] ;take length of s1 string in cl inc si lea di,s2 inc di mov ch,[di] ;take length of s2 string in cl inc di mov dh,ch ;backup of ch register mov [count],0 ;initialise count with zero loop3: mov al,[si] mov bp,si ;backup of si pointer cmp al,[di] je loop4 inc si dec cl ;counter for main string jnz loop3 mov dl,[count] cmp dl,0 ;dl=0 implies no string found je fail jmp result loop4: dec ch ;counter for sub-string cmp ch,0 je success inc si inc di mov al,[si] cmp al,[di] je loop4 ;continue this loop till string are same jmp loop3 ;inc case of mismatch, start again success: add [count],01 lea di,s2 add di,2 ;move di to string place inc bp mov si,bp ;restore si from bp dec cl mov ch,dh ;restore ch from dh jmp loop3 ;start again till main string ends fail: scall m5,09h ;display m5 ret ;return from procedure result: scall m4,09h ;display m4 string scall m6,09h ;display m6 string mov dl,[count] add dl,30h mov ah,02h ;display dl contents int 21h ret ;return from procedure endp ;end of procedure end ;end of Program