Hello fellow coders!
Recently I have been playing with ALOT of different instructions.
And I have been reading about them in different places. The
texts I have read confuses me. Some say: do not use this,
do not use that, but use this.

LODS, STOS, SCAS, REP, REPZ, REPNZ. What are the pros/cons
of these instructions? I have made the equilant with mov,jmp,etc.
But what is faster? or better?

Lets look at some code: what you see below does exactly the same
thing. It gets you to the end position in a string.
[color=sienna]mov esi,offset string

test al,al
jne $-3

mov al,[esi]
inc si
test al,al
jne $-6

inc si
cmp [esi],al
jnz $-4

mov edi,offset string
xor al,al
jne $-1[/color]

When you look at the code above there is some of them wich will give
you more control in the code. In all of the above examples I used jmp
instructions instead of a 'rep' instuction.

1.Is it better to use jmps instead of rep?
2.Is it better to use stos,lods,scas,etc. instead of mov/inc/etc.?
3.Will lods,scas,etc. be better to use with small rather then large operations?
or is it the other way around?

The reason why I ask these questions, is because its 05:00AM and i tired.
And because I have alot of my own optinions and want to confirm them
with others. Wich have a long experience in the assembly world.

This is what I think: jump instructions are better then rep instructions.
Using the equaliants to lods,sca,etc. can provide performance when
thinking about pairing etc. And give better control when programming.
+Some other thought wich I am just too tired to write about right now.
Hope someone understands me and gives me a good answer wich I can
look at when I have done some serious sleeping.

Until then, Good night! ( ;) )
Posted on 2002-12-26 22:44:08 by natas
    xor ecx, ecx

_1: or [esi + ecx], 0
lea ecx, [ecx + 1]
jne _1
another :)

Your on the right track. Fine grain control is good when your trying to optimize for speed, but not so much when your trying to optimize for size. Testing each code block is good, too.
Posted on 2002-12-26 23:31:25 by bitRAKE

The general recommendation with processors later than 486 is to use incremented pointers instead of the older string instructions. Two exceptions are REP MOVSD and REP STOSD which have been treated as special cases in later Intel processors.

You should avoid ANY of the string instructions if you are not using REP as they are generally measurably slower than using registers and manually incrementing the addresses.

Best way is to "suck it and see", write them, benchmark them and look at the difference. Make sure you DON'T use the old LOOP family of opcodes, they are really slow on later Intel hardware.


Posted on 2002-12-27 06:41:32 by hutch--
Thanks guys! finally I can settle my confused mind. When im coding
and get curious I tend to stop everything to explore a new interesting
instruction. So now that I have confirmed some of my thoughts. I'll
start testing some instructions under different environments.
Like Hutch sayd: "Suck it and see" :alright:
Posted on 2002-12-27 10:47:21 by natas