The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: The_Grey_Beast on March 22, 2005, 03:51:36 PM

Title: Just wondering...
Post by: The_Grey_Beast on March 22, 2005, 03:51:36 PM
Can rep be used for other instructions than string operations? For example:

; add ax to itself 6 times
mov ecx, 6
rep add ax, ax


Does the above code work? Thanks.
Title: Re: Just wondering...
Post by: roticv on March 22, 2005, 04:00:00 PM
No.
Title: Re: Just wondering...
Post by: Tedd on March 22, 2005, 04:32:05 PM
REP is only for MOVS/LODS/CMPS/SCAS/INS/OUTS
For all other instructions it's 'illegal' (technically, it's 'undefined' - ie. you shouldn't use it.)

The LOOP instruction does what you want though (just don't mention this to any of the optimizer freaks :lol)


   mov ecx,6
@loopy:
   add ax,ax
   loop @loopy


(obviously, a number of instructions can go in the 'loop' - as long as the jump is still short)
Title: Re: Just wondering...
Post by: hutch-- on March 25, 2005, 12:47:41 AM

    mov ecx, -6
  @@:
    add ax, ax
    add ecx, 1
    jnz @B