flat assembler
Message board for the users of flat assembler.

Index > Main > REPE and CMPS

Author
Thread Post new topic Reply to topic
matias_beretta



Joined: 28 Dec 2007
Posts: 1
matias_beretta 28 Dec 2007, 22:34
Hello, thanks for reading my topic...

I was reading the FASM manual and found this:

repe cmpsb ;COMPARE [ES:DI] and [DS:SI] until CX = 0

but can i use this???????????:

repe cmps byte [ds:si], [ds:di]

bye Smile

_________________
Matías Beretta
Post 28 Dec 2007, 22:34
View user's profile Send private message MSN Messenger Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4324
Location: Now
edfed 28 Dec 2007, 22:37
if you want to know, you have to try...
Post 28 Dec 2007, 22:37
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 28 Dec 2007, 22:42
AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose and System Instructions wrote:
The forms of the CMPSx instruction with explicit operands address the first operand
at seg:[rSI]. The value of seg defaults to the DS segment, but may be overridden by a
segment prefix. These instructions always address the second operand at ES:[rDI]. ES
may not be overridden. The explicit operands serve only to specify the type (size) of
the values being compared and the segment used by the first operand.
The no-operands forms of the instruction use the DS:[rSI] and ES:[rDI] registers to
point to the values to be compared. The mnemonic determines the size of the
operands.


So you can modify the segment register of the destination operand but the source is always ES.

Basicaly, when you override the default (you don't use [DS:SI] as dest), an extra byte is added before the instruction (the segment override prefix).

Code:
rep cmps byte [fs:si], byte[es:di]
; is equivalent to

rep fs cmps byte [ds:si], byte[es:di]

; also equivalent to

rep fs cmpsb
    


You don't need to bother about the last code, is just to show the encoding.
Post 28 Dec 2007, 22:42
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1898
DOS386 29 Dec 2007, 04:19
matias_beretta wrote:
Hello, thanks for reading my topic...
I was reading the FASM manual and found this:
repe cmpsb ;COMPARE [ES:DI] and [DS:SI] until CX = 0


The time has come that you study the Intel 80386 manual:

http://board.flatassembler.net/topic.php?t=3164

Of course you also can look into an 8086 manual, which is even smaller and easier to understand, but don't search stuff like EAX inside Laughing

Quote:

AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose and System Instructions wrote:


Yes, but it's really not for beginners Rolling Eyes

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 29 Dec 2007, 04:19
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 25 Jan 2008, 07:19
Apparently, for string instructions, you can never override the destination's segment (always uses ES).

See here for a bit of info about why FASM doesn't complain.
Post 25 Jan 2008, 07:19
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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.