subject

Description: Write a procedure named Str_find that searches for the
first matching occurrence of a source string inside a target string
and returns the matching position. The input parameters should be a
pointer to the source string and a pointer to the target string. If
a match is found, the procedure sets the Zero flag and EAX points to
the matching position in the target string. Otherwise, the Zero
flag is clear.
TODO: Complte Str_find PROC
!
INCLUDE Irvine32.inc
Str_find PROTO, pTarget:PTR BYTE, pSource:PTR BYTE
.data
promptTargetStr BYTE "Enter target string: ",0
promptSourceStr BYTE "Enter source string: ",0
str1 BYTE "Source string found at position ",0
str2 BYTE " in Target string (counting from zero).",0Ah,0Ah,0Dh,0
str3 BYTE "Unable to find Source string in Target string.",0Ah,0Ah,0Dh,0
MAX = 80 ;max chars to read
target BYTE MAX+1 DUP (?)
source BYTE MAX+1 DUP (?)
stop DWORD ?
lenTarget DWORD ?
lenSource DWORD ?
position DWORD ?
.code
main PROC
; prompt input target string
mov edx, OFFSET promptTargetStr
call WriteString
mov edx, OFFSET target
mov ecx, MAX ;buffer size - 1
call ReadString
call Crlf
; prompt input source string
mov edx, OFFSET promptSourceStr
call WriteString
mov edx, OFFSET source
mov ecx, MAX ;buffer size - 1
call ReadString
call Crlf
INVOKE Str_find, ADDR target, ADDR source
mov position, eax
jz wasfound ; ZF=1 indicates string found
mov edx, OFFSET str3 ; string not found
call WriteString
jmp quit
wasfound: ; display message
mov edx, OFFSET str1
call WriteString
mov eax, position ; write position value
call WriteDec
mov edx, OFFSET str2
call WriteString
quit:
exit
main ENDP
;
Str_find PROC, pTarget:PTR BYTE, ;PTR to Target string
pSource:PTR BYTE ;PTR to Source string
;
; Searches for the first matching occurrence of a source
; string inside a target string.
; Receives: pointer to the source string and a pointer
; to the target string.
; Returns: If a match is found, ZF=1 and EAX points to
; the offset of the match in the target string.
; IF ZF=0, no match was found.
;
INVOKE Str_length, pTarget ; get length of target
mov lenTarget, eax
INVOKE Str_length, pSource ; get length of source
mov lenSource, eax
mov edi, OFFSET target ; point to target
mov esi, OFFSET source ; point to source
; Compute place in target to stop search
mov eax, edi ; stop = (offset target)
add eax, lenTarget ; + (length of target)
sub eax, lenSource ; - (length of source)
inc eax ; + 1
mov stop, eax ; save the stopping position
; TODO: Compare source string to current target
ret
Str_find ENDP
END main

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:10, o10922025
Assume that to_the_power_of is a function that expects two int parameters and returns the value of the first parameter raised to the power of the second parameter. write a statement that calls to_the_power_of to compute the value of cube_side raised to the power of 3 and that associates this value with cube_volume.
Answers: 1
image
Computers and Technology, 23.06.2019 04:31, mjweed3381
Cloud computing service providers manage different computing resources based on the services they offer. which resources do iaas and paas providers not manage? iaas providers do not manage the for the client, whereas paas providers usually do not manage the for their clients. iaas- storage server operating system network paas- applications interafce storage vertualiation
Answers: 2
image
Computers and Technology, 23.06.2019 18:30, erjalinalii
Janice recently received her college degree and is looking for a job. she is worried that since she just finished school, she will be required to repay her perkins and direct subsidized loans immediately. janice pulls out the paperwork she signed and reviews it again for repayment information. after reading all of the information, janice discovers that
Answers: 2
image
Computers and Technology, 25.06.2019 05:30, TheViperMlg23676
The piston ring isn't a completely solid ring; instead, it's usually split at one point. this split or gap in the ring is called the a. ring spacing. b. ring clearance. c. ring end gap. d. ring side clearance.
Answers: 2
You know the right answer?
Description: Write a procedure named Str_find that searches for the
first matching occurrence...

Questions in other subjects:

Konu
Chemistry, 22.02.2022 20:20
Konu
Mathematics, 22.02.2022 20:20