Im parsing strings and I have written code that works but Im not so sure that I have written it most efficiently which has brought about an issue in my mind. For a good starter, generally speaking which of the following is a better method of indexing?
mov firstbyte, [si]
inc si
mov secbyte, [si]
inc si
mov thirdbyte, [si]
inc si
...ect...
or
mov firstbyte, [si]
mov secbyte, [si+1]
mov thirdbyte, [si+2]
...ect...
I realize that the value of si will not be changed when done with the 2nd example, in case I was trying to maintain a pointer value. That decision can be made as necessary.
Or what if I didn't use inc in the first example but rather add si, 1 for each index. Are there huge penaltys to pay?
jon
Your second version will be faster. Always try to use addressing modes to avoid instructions.
Also, using an add instead of inc will be faster.
The code speedup can be noticeable if you do this in inner loops.
Hey guys!
I realize that this is not an addressing question but it is, however, an efficiency question.
Which would be faster within a loop:
or al, al
jz whatever
or..
cmp al, 0
je whatever
jon
I doubt there will be any noticable difference, and it would depend more on the instructions leading up to that.
In general I would go for the least destructive. 'OR' will write back the value, destroying the previous value of al (which was the same, but that's not the point,) whereas CMP doesn't try to modify al.
If only checking for zero, "test al,al" might be better :P (It does 'and al,al' but without writing back the result to al.)