The x86 architecture allows string instructions to be used with or without a repeat prefix. But they don't seem to do anything interesting without the repeat prefix. MOVS without REP, for example, can be replaced with a simple MOV.
Is there a good reason to use MOVS (and STOS, SCAS, CMPS) without REP? Or is this just a useless idiosyncrasy of the x86 instruction set?
Yes. Not necessarily on purpose, yet you can use them for some sort of optimization.
It is, for example, faster (provided that rsi, rsi point to the right location) to use movs
than
mov rax,[whatever1]
mov [whatever2],rax
For the rest, I'm not sure at the moment, but the execution times could be looked up I guess.
Incrementing/decrementing rsi, rdi
would be a side effect here actually.
Also, printing a C style string in low level mode (no formatting or special chars; direct video memory access) is like:
; ...
_load_char:
lodsb
or al,al
jz _end_of_string
stosw
jmp _load_char
_end_of_string:
; ...
Here you need to examine each single character you load and determine if the end of the string was reached or not so you cannot use rep
. Though one might think of repz movsb
that won't work here, since one of two consecutive bytes in the video mem is the attribute byte for the particular character. In this case it is an intended feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With