Write a inline assembly language program subroutine that searches for a characte
ID: 3865275 • Letter: W
Question
Write a inline assembly language program subroutine that searches for a character in a string and returns the first occurrence of the character in the string.
The subroutine must be called search and the string is passed in the ESI register. The character to search for should be placed in the AL register and the length of the string is in the ECX register.
The subroutine should return the location of the character in the EBX register, where the first character is 1 and if not found, returns 0.
For example, given a 10 character string in mystring = 'EXCELLENTE', locate the first 'X' character.
lea ESI,mystring
mov al,'X'
mov ecx,10
call search
------returns with EBX =2
lea ESI,mystring
mov al,'Y'
mov ecx,10
call search
------returns EBX = 0
The program must work for any sized string or character combination.
Having trouble writing this program on visual studio 2015 keep getting compile errors when i go by the example above. Need help on one that will compile and work correctly.
Explanation / Answer
CODE:
DATA SEGMENT
MSG1 DB 10,13, ' NETER THE STRING :- $'
MSG2 DB 10,13,'ENTER ANY CHARACTER :-$'
MSG3 DB 10,13, '$'
MSG4 DB 10,13,' NO, CHARACTER FOUND IN THE GIVEN STRING $'
MSG5 DB ' CHARACTER(S) FOUND IN THE GIVEN STRING $'
CHAR DB ?
COUNT DB 0
P1 LABEL BYTE
M1 DB 00FH
L1 DB ?
P11 DB 0FFH DUP ('$')
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
END M
CODE SEGMENT
ASSUME CS:CODE , DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
LEA DX,P1
MOV AH,0AH
INT 21H
DISPLAY MSG2
MOV AH,1
INT 21H
MOV CHAR,AL
DISPLAY MSG3
LEA SI,P11
MOV CL,L1
MOV CH,0
CHECK:
MOV AL,[ SI ]
CMP CHAR,AL
JNE SKIP
INC COUNT
SKIP:
INC SI
LOOP CHECK
CMP COUNT,0
JE NOT FOUND
DISPLAY MSG3
MOV DL,COUNT
ADD DL,30H
MOV AH,2
INT 21H
DISPLAY MSG5
JMP EXIT
NOTFOUND:
DISPLAY MSG4
EXIT:
MOV AH,4CH
INT 21H
CODE ENDS
END START
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.