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

Write a inline assembly language program subroutine that searches for a characte

ID: 3860902 • 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 ESl, 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. Extra credit: Write a version of the program that pushes the parameters onto the stack and then reads them off the stack inside the subroutine.

Explanation / Answer

Here is the code segment as per the given criteria, please go through it:

DATA SEGMENT

MSG1 DB 10,13, ' ENTER 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
=======================================================

These command is used to save string given by user.
Here 0FFH DUP (‘$’) stands for N i.e. Size of Array
=======================================================

P1 LABEL BYTE /* P1 is the Start of the Label Byte Data Type.*/

M1 DB 00FH /* M1is used for assigning Maximum Length of the Array */

L1 DB ? /* L1 is used to Get the LENGTH of the entered String by User.*/

P11 DB 0FFH DUP ('$') /* P11 is the names refered to the Arrays */
========================================
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

Please run the codes into your window and check out the output.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote