-- entire ASM file -- _TEXT SEGMENT rep cmpsw _TEXT ENDS END -- end -- error A2068: instruction prefix not allowed What's up with that? I can rep the other string instructions and I can do this with all my other assemblers. MASM v6.14.8444
Tergiver, The code you posted looks like DOS segmented code that will not work in 32 bit mode. You need to do more to get CMPSW to work, below is the basic code to set up 2 strings to compare them. It uses 32 bit registers in the normal manner.
You test if ECX is zero to see if the strings are equal or not. Regards, firstname.lastname@example.org
mov esi, source ; 1st string to compare mov edi, dest ; 2nd string to compare mov ecx, length ; max number of bytes to compare rep cmpsw ; repeat comparison until either ; ecx = 0 OR bytes in ESI/EDI do not match
Come on man, I'm not stupid. I know what has to be done to setup and compare 2 strings. The point is that this version of the MASM compiler is telling me I can't prefix compsw with the rep instruction. I can do this with other assemblers (i.e. Microsoft Visual C++ inline, and an old 16-bit x86 assembler I have). It works perfectly AND it assembles. The question is why is MASM complaining?
Ok, so I am stupid. The other assemblers were assembling rep into repe opcode. Sorry
Hutch, mov esi, source ; 1st string to compare mov edi, dest ; 2nd string to compare mov ecx, length ; max number of bytes to compare rep cmpsw ; repeat comparison until either ; ecx = 0 OR bytes in ESI/EDI do not match i tried that, and masm still complain. ;) it's strange if you can actually compile that, because REP nev- er work with CMPSW.
mov esi, source mov edi, dest mov ecx, length rep movsb would make sense, because you're not comparing, but moving. Tergiver, if you understand this, then you understand why REP CMPS* won't compile.
Tergiver, You will forgive me for misunderstanding your question but the code you posted would not work,
The code below should be faster that CMPSW.
-- entire ASM file -- _TEXT SEGMENT rep cmpsw _TEXT ENDS END -- end --
disease, I confess to being a bit rusty with CMPS and SCAS as I have not used them for a long time as they are basically too slow. REPE is the correct prefix for both. Regards, email@example.com This message was edited by hutch--, on 5/26/2001 2:49:31 AM
.data source db "this is a test" dest db "this is a pest" .code mov eax, offset source ; 1st string to compare mov edx, offset dest ; 2nd string to compare xor ecx, ecx @@: mov bx, cmp bx, jne @F ; exit if not matching add ecx, 2 cmp ecx, 14 jne @B ; exit if full length @@: shr ecx, 1 ShowReturn hWnd, ecx
ecx can end up zero after rep cmpswhatever even if the strings don't match, i.e. if they match except in the last rep. Use the zero flag to see if the strings match. Of course, one can always make up one's own opcodes: repcmpsw macro dw 0A7F3h ;F3 is repe, A7 is cmpsw endm This message was edited by Larry Hammick, on 5/31/2001 11:33:05 PM