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.
No.
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)
mov ecx, -6
@@:
add ax, ax
add ecx, 1
jnz @B