Sei sulla pagina 1di 2

;EXITmov ax,4c00h ;ah = code to return to DOSint 21h ;al = 0, i.e.

, no error ;=====================================getc: ; read character into alpush bxpush cxpush dx ;Save register valuesmov ah, 01h ; 07h DOES NOT ECHO KEYBOARDint 21hpop dxpop cxpop bx ; Restore register valuesretend main Your Tasks :1. Modify the program to get two strings from the user with two different promptmessages2 . M a k e t h e p r o g r a m l o o p 5 t i m e s 9 Practical #5 :String instructionsGiven below is an assembly source code. Compile the program. .model small.dataCR equ 13LF equ 10NewLine db CR,LF,"$"String1 db "This is a string!$"String2 db 18 dup(0)Diff1 db "This string is nearly the same as Diff2$"Diff2 db "This string is nearly the same as Diff1$"Equal1 db "The strings are equal$"Equal2 db "The strings are not equal$"Message db "This is a message"SearchString db "1293ijdkfjiu938uHello983fjkfjsi98934$"Message1 db "Using String instructions example program.$"Message2 db CR,LF,"String1 is now: $"Message3 db CR,LF,"String2 is now: $"Message4 db CR,LF,"Strings are equal!$"Message5 db CR,LF,"Strings are not equal!$"Message6 db CR,LF,"Character was found.$"Message7 db CR,LF,"Character was not found.$".stack 100h.codestart:mov ax,@data ; ax points to of data segmentmov ds,ax ; put it into dsmov es,ax ; put it in es toomov ah,9 ; function 9 - display stringmov dx,OFFSET Message1 ; ds:dx points to messageint 21h ; call dos functioncld ; clear direction flagmov si,OFFSET String1 ; make ds:si point to String1mov di,OFFSET String2 ; make es:di point to String2mov cx,18 ; length of strings 10 rep movsb ; copy string1 into string2mov ah,9 ; function 9 - display stringmov dx,OFFSET Message2 ; ds:dx points to messageint 21h ; call dos functionmov dx,OFFSET String1 ; display String1int 21h ; call DOS servicemov dx,OFFSET Message3 ; ds:dx points to messageint 21h ; call dos functionmov dx,OFFSET String2 ; display String2int 21h ; call DOS servicemov si,OFFSET Diff1 ; make ds:si point to Diff1mov di,OFFSET Diff2 ; make es:di point to Diff2mov cx,39 ; length of stringsrepz cmpsb ; compare stringsjnz Not_Equal ; jump if they are not the samemov ah,9 ; function 9 - display stringmov dx,OFFSET Message4 ; ds:dx points to messageint 21h ; call dos functionjmp Next_OperationNot_Equal:mov ah,9 ; function 9 - display stringmov dx,OFFSET Message5 ; ds:dx points to messageint 21h ; call dos functionNext_Operation:mov di,OFFSET SearchString ; make es:di point to stringmov cx,36 ; length of stringmov al,'H' ; character to search for repne scasb ; find first matchjnz Not_Foundmov ah,9 ; function 9 - display stringmov dx,OFFSET Message6 ; ds:dx points to message 11 int 21h ; call dos functionjmp Lodsb_ExampleNot_Found:mov ah,9 ; function 9 display stringmov dx,OFFSET Message7 ; ds:dx points to messageint 21h ; call dos functionLodsb_Example:mov ah,9 ; function 9 - display stringmov dx,OFFSET NewLine ; ds:dx points to messageint 21h ; call dos functionmov cx,17 ; length of stringmov si,OFFSET Message ; DS:SI - address of stringxor bh,bh ; video page 0mov ah,0Eh ; function 0Eh - write character NextChar:lodsb ; AL = next character in

stringint 10h ; call BIOS serviceloop NextChar mov ax,4C00h ; return to DOSint 21hend start Your Tasks: 1. Compile and Link this program.2. Change the strings and c h e c k r e s u l t s 3 T r y a l l s t r i n g i n s t r u c t i o n s l e a r n t i n t h e c l a s s . 4. Enter a character string from keyboard and search for a two character string to beentered from keyboard.12

Potrebbero piacerti anche