flat assembler
Message board for the users of flat assembler.

Index > Main > [SOLVED] repnz movsb - problem

Author
Thread Post new topic Reply to topic
killasmurf86



Joined: 29 Sep 2010
Posts: 36
killasmurf86 01 Oct 2010, 16:56
So I was writing string manipulation function, and encountered a bug.

I tried to figure why this bug happens for a day....
today I searched for Intel instruction set reference.

Please correct me if i'm wrong, but
Code:
repnz movsb    
is invalid instruction (it works, but no the way, noob like me would expect)

repnz movsb works just like rep movsb


am I right?


Last edited by killasmurf86 on 01 Oct 2010, 17:51; edited 1 time in total
Post 01 Oct 2010, 16:56
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 01 Oct 2010, 17:18
killasmurf86,

Both manuals explicitly state that only rep prefix (which has the same opcode as repe/repz) can be used with movs. This is understandable: even if source isn't equal to destination before the instruction is executed, it will be after. Wink
Post 01 Oct 2010, 17:18
View user's profile Send private message Reply with quote
killasmurf86



Joined: 29 Sep 2010
Posts: 36
killasmurf86 01 Oct 2010, 17:51
Thanks for clearing my doubt's.... I finally fixed bug, after I posted.....
I just wanted to verify.... cause I was staring at the code for hours, and just couldn't understand why It doesn't work... Very Happy
Post 01 Oct 2010, 17:51
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 05 Oct 2010, 09:25
movs doesn't change flags and both REPE and REPNE is clever enough not to check for them.

Therefore repne movs works the same like rep movs. And rep movs is the same like repe movs in machine code.
Post 05 Oct 2010, 09:25
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 05 Oct 2010, 10:29

100% agree with MazeGen
there is no comparison in "movs.
"REPNE" has no meaning here.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 05 Oct 2010, 10:29
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 05 Oct 2010, 10:34
MazeGen wrote:
movs doesn't change flags and both REPE and REPNE is clever enough not to check for them.
Is this true for ALL CPUs made by all manufacturers? Or just a small subset?
Post 05 Oct 2010, 10:34
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 05 Oct 2010, 11:06
Quote:

Is this true for ALL CPUs made by all manufacturers?
Or just a small subset?
it's a matter of logique (of the code),
not a matter of useless behavior of the processor.

make a comparison after a "mov" is an absurdity,
or then, it's not a "mov", but a "mov_and_cmp".

_________________
I am not young enough to know everything (Oscar Wilde)- Image


Last edited by ouadji on 05 Oct 2010, 11:12; edited 1 time in total
Post 05 Oct 2010, 11:06
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 05 Oct 2010, 11:12
ouadji wrote:
it's a matter of logique (of the code),
not a matter of useless behavior of the processor.
No, it is a matter of reliability and dependability in one's code. If some CPUs don't behave in the expected manner then your code is unreliable.
Post 05 Oct 2010, 11:12
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 05 Oct 2010, 11:24

100% agree with you revolution

that's what I tried to say ... ( Confused , sorry for my bad english)

the code should be logical,
(reliability and dependability in one's code)
and never use any useless behavior (unexpected) of the processor.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 05 Oct 2010, 11:24
View user's profile Send private message Send e-mail Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 05 Oct 2010, 12:05
the best way to have a reliable code for X86 is to code with 386 instruction set only Very Happy
the best way to have a fast code is to code with X86 RISC instructions, and better, code with single byte, parallelisable in Pentium, and low latency, instructions only.
Post 05 Oct 2010, 12:05
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 05 Oct 2010, 12:38
It seems that I accidentally deleted the disclamer part: "undocumented, you should't rely on it".

However, the difference between REP and REPE is made by the repeated instruction: if the instruction changes flags, REP/REPE tests them, otherwise it doesn't test them at all. It is very likely that the same behaviour is hardwired in REPNE prefix.
Post 05 Oct 2010, 12:38
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 05 Oct 2010, 18:38
from HELPPC:

REP repeat a string instruction unti CX=0

REPE/REPZ repeat until CX=0 and Zero flag is set

REPNE/REPNZ repeat until CX=0 and Zero flag is clear


http://docs.huihoo.com/help-pc/asm-rep.html
Post 05 Oct 2010, 18:38
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.