News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Why not rep scasb?

Started by afmcc, March 23, 2006, 07:31:07 PM

Previous topic - Next topic

afmcc

Hi, I have recently started using the GoTools and am really impressed. However, I find that if I try to use a

REP SCASB

in my code, the assembler flags this as an error. The error message is:

REP not allowed with this mnemonic:-                                                         
rep scasb

but as far as I can see from the Intel manuals, this should be fine (I'm really only beginning assembly language programming so I could be misinterpreting that).  This is with goasm 0.55.02

Cheers,
Tony       

1rDirEctoALgran0

You must write REPE SCASB
it is the only case for this instruction :
While B[EDI] Equals AL, REPeat a SCAn String instruction.

Now have fun with GoAsm ! :dance:

Patrick

1rDirEctoALgran0

;
; Little example
;

   CONST
Klax: DB "...........STOP"

   CODE
Start:
   LEA EDI,Klax
   MOV ESI,EDI
   MOV AL,"."
   REPE SCASB
   SUB EDI,ESI
   MOV EAX,EDI        ; EAX contains the number of "." +1
   RET

raymond

QuoteYou must write REPE SCASB
it is the only case for this instruction :

Although REPE can be used, the SCASB is more often used with the REPNZ (or REPNE) prefix to find a specific character in a "string", such as a terminating 0, a ",", a space, a ":", etc. etc.

(AFAIK, the REP prefix can be used with MASM and would be interpreted as REPE (or REPZ). However, GoAsm may have its own syntax limits.)

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

MichaelW

MASM also will not allow a REP prefix with CMPS_ or SCAS_. I think a REP prefix with CMPS_ or SCAS_ is assumed to indicate a programmer error because instructions of this form would serve no useful purpose, effectively doing repeated comparisons with no way to respond to the result of the comparisons. Actually, REP and REPE both have the same encoding (F3h), interpreted as REP or REPE depending on the prefixed instruction. You can encode a REP CMPS_ or REP SCAS_ manually, but the processor will see REPE CMPS_ or REPE SCAS_.

eschew obfuscation

afmcc

Thanks all for the replies. That gave me the clue I needed.