-- 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
Posted on 2001-05-23 18:12:00 by Tergiver
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.

    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
You test if ECX is zero to see if the strings are equal or not. Regards, hutch@pbq.com.au
Posted on 2001-05-23 20:27:00 by hutch--
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?
Posted on 2001-05-24 11:28:00 by Tergiver
Ok, so I am stupid. The other assemblers were assembling rep into repe opcode. Sorry
Posted on 2001-05-24 11:33:00 by Tergiver

 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.

Posted on 2001-05-25 23:35:00 by disease_2000


    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.

Posted on 2001-05-25 23:38:00 by disease_2000
Tergiver, You will forgive me for misunderstanding your question but the code you posted would not work,

              -- entire ASM file --
              _TEXT SEGMENT
              rep cmpsw
              _TEXT ENDS
              END
              -- end --
The code below should be faster that CMPSW.

            .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

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, hutch@pbq.com.au This message was edited by hutch--, on 5/26/2001 2:49:31 AM
Posted on 2001-05-26 02:46:00 by hutch--
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
Posted on 2001-05-31 23:25:00 by Larry Hammick