1

I'm using MASM and I'm trying to exchange a string with another I want to change test with rull

I'm using an array of string: This is a test I'm trying to search for test and replace it with rull.

I did everything, however, I have 2 problems

  1. I have to write rull in reverse, llur.
  2. It prints t with rull, so the output after replacing it will be trull. I am not sure where did the t comes.

Can someone help?

This is what I've done so far:

       cld
       lea edi, str2
       mov ecx, lengthof str2
       mov eax, 'test'
       repne scasb
       je found
       jne notfound 
       dec edi

       call crlf

found: mov eax, 'llur'
       stosd
       lea edi, str2

L1:    mov eax, [edi]
       call writechar
       add edi, type str2
       loop l1

1 Answer 1

0

1- I have to write rull in reverse, llur

That's just how MASM interprets string literals when you use them as an immediate operand.

2- it prints t with rull so the output after replacing it will be trull I am not sure where did the t come

SCASB increases EDI after comparing AL against [EDI], so when REPNE SCASB finishes you'll be one byte past the character you were looking for. You've got a dec edi to counter this, but you're jumping past that instruction with the je found.

Also did you intend to look for 'test' or just 't'? You're moving 'test' into eax (which really will end up as 'tset'), but you're only scanning for a single byte.

Sign up to request clarification or add additional context in comments.

5 Comments

I've tried to use the code without je found before and it worked, however, it keeps deleting everything each time I try to use the loop again. it will also change rull to something like rurull at the second time then rururull at the third time, then it will delete it, then it will delete is and this, and finally it will claim that test isn't found !
Your error description doesn't really make much sense without knowing what the input string looks like. You should include that in the question, along with the output you're getting.
I did. "This is a test"
I had no trouble doing the replacement multiple times. I tried it with the string "This is a test and another test" and got the output "This is a rull and anorull rull" (the 't' in 'another' is matched since you only scan for single characters).
I want to let the user choose whether or not he wants to continue searching for test, this is why I'm doing it again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.