1
votes

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

1 Answers

0
votes

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.