Write an assembly procedure Find to return the index of the first occurrence of a character ch in a string str. If ch is not found in str the return value should be -1.
Input parameters:
None.
Preconditions:
The base address of str is stored in ecx.
str is ‘\0’ terminated.
ch is strored in bl.
Return value:
The return value should be stored in eax.
Run and test your procedure using the following driver program:
.386
.model flat, stdcall
option casemap : none
.data
MyStr byte "Assembly Lab 8: Procedures", 0
MyCH byte ":"
.code
;write your procedure here.
start:
lea ecx, MyStr
mov bl, MyCH
call Find
ret
end start
DATA SEGMENT MSG1 DB "ENTER THE STRING : $" MSG2 DB "NO OF OCCURANCES OF N : $" NEWLINE DB 10,13,'$' STR1 DB 80 DUP('$') bl DB ch CNT DB 0 DATA ENDS CODE SEGMENT ASSUME DS:DATA,CS:CODE START : MOV AX,DATA MOV DS,AX MOV AH,09H LEA DX,MSG1 INT 21H MOV AH,0AH LEA DX,STR1 INT 21H MOV AH,09H LEA DX,NEWLINE INT 21H LEA SI,STR1+1 MOV CL,BYTE PTR[SI] MOV CH,00H #ITERATING THE STRING AND FINDING THE FIRST OCCURRENCE OF bl L1 : INC SI CMP BYTE PTR[SI],bl JNZ L2 INC CNT MOV EAX,SI L2 : LOOP L1 ADD CNT,'0' MOV AH,09H LEA DX,MSG2 INT 21H JNZ CNT MOV AH,02H MOV DH,00H MOV DL,EAX INT 21H MOV AH,4CH INT 21H CODE ENDS END START
Get Answers For Free
Most questions answered within 1 hours.