flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [strange, but not BUG] LODSB and LODS BYTE [GS:SI]

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 11 Jan 2009, 09:27
Code:
lodsb [gs:si]      ; BUG
lods byte [gs:si]  ; Fine
    


FASM core bug or intentional behaviour ?


Last edited by DOS386 on 11 Jan 2009, 14:36; edited 1 time in total
Post 11 Jan 2009, 09:27
View user's profile Send private message Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan 11 Jan 2009, 09:45
i think it's purposely cuz lodsb is a separate 1 byte (w/o REX) command with defined size operand, but lods is a hint to use that command with appropriate segment (if overridden) and size for operand.
Post 11 Jan 2009, 09:45
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 11 Jan 2009, 09:47
error: extra characters on line

lodsb[gs:si]

i think it is normal
as lodsb is a short version of lods, it don't need operand under 1.67.26
Post 11 Jan 2009, 09:47
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 11 Jan 2009, 10:12
Proper syntax would be "lods byte [gs:si]", but I am not sure if that would work
Post 11 Jan 2009, 10:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8360
Location: Kraków, Poland
Tomasz Grysztar 11 Jan 2009, 12:44
You can look it up in Intel manuals - LODSB, LODSW, XLATB, etc. are all the "shortcuts", which do not take any arguments and use the default operands. To specify other than default, you need to use the proper instruction. Like:
Code:
use32

lodsb ; = lods byte [ds:esi]
lods byte [gs:si] ; some different variant

xlatb ; = xlat byte [ds:ebx]
xlat byte [fs:bx] ; some different variant    
Post 11 Jan 2009, 12:44
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 11 Jan 2009, 14:39
Thanks ... Smile

> You can look it up in Intel manuals

Not much in. Sad

vid wrote:

> Proper syntax would be "lods byte [gs:si]", but I am not sure if that would work

Why ? It seems to work.

But since "lodsb" and "lods byte" is the very same instruction it was and still is inobvious to me why only the latter accepts segment prefix.
Post 11 Jan 2009, 14:39
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8360
Location: Kraków, Poland
Tomasz Grysztar 11 Jan 2009, 21:06
DOS386 wrote:
> You can look it up in Intel manuals

Not much in. Sad

This is what my copy of "IA-32 Intel® Architecture Software Developer’s Manual Volume 2A" says. Wink


Description:
Filesize: 47.08 KB
Viewed: 9970 Time(s)

lods_intel.jpg


Post 11 Jan 2009, 21:06
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 12 Jan 2009, 08:42
Tomasz Grysztar wrote:
This is what my copy of "IA-32 Intel® Architecture Software Developer’s Manual Volume 2A" says.


That's what the famous manual you originally learned ASM from says:

Quote:
LODS loads the AL, AX, or EAX register with the memory byte, word,
or doubleword at the location pointed to by the source-index register.
After the transfer is made, the source-index register is automatically
advanced. If the direction flag is 0 (CLD was executed), the source index
increments; if the direction flag is 1 (STD was executed), it decrements.
The increment or decrement is 1 if a byte is loaded, 2 if a word is loaded,
or 4 if a doubleword is loaded.

If the address-size attribute for this instruction is 16 bits, SI is used
for the source-index register; otherwise the address-size attribute is 32
bits, and the ESI register is used. The address of the source data is
determined solely by the contents of ESI/SI. Load the correct index value
into SI before executing the LODS instruction. LODSB, LODSW, LODSD are
synonyms for the byte, word, and doubleword LODS instructions.

LODS can be preceded by the REP prefix; however, LODS is used more typically
within a LOOP construct, because further processing of the data moved into
EAX, AX, or AL is usually necessary.

_________________
Bug Nr.: 12345

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

Status: Closed: NOT a Bug
Post 12 Jan 2009, 08:42
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 12 Jan 2009, 10:16
LODSB/MOVSB/CMPSB/... takes no operands and therefore you can't override default DS: segment.

The manual explains it clearly: there is short form and long form of all string instructions' syntax. Always use the long form if you want to use segment override.
Post 12 Jan 2009, 10:16
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 12 Jan 2009, 10:47
MazeGen wrote:
LODSB/MOVSB/CMPSB/... takes no operands and therefore you can't override default DS: segment. The manual explains it clearly: there is short form and long form of all string instructions' syntax.


NOT the one I quoted from Neutral

Quote:
Always use the long form if you want to use segment override.


OK ... minor thing.
Post 12 Jan 2009, 10:47
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 12 Jan 2009, 11:03
Always use the latest manuals when in doubt.

...
At the assembly-code level, two forms of this instruction are allowed: the “explicit operands”
form and the “no-operands” form. The explicit-operands form (specified
with the LODS mnemonic) allows the source operand to be specified explicitly. Here,
the source operand should be a symbol that indicates the size and location of the
source value.
...
The no-operands form provides “short forms” of the byte, word, and doubleword
versions of the LODS instructions. Here also DS:(E)SI is assumed to be the source
operand and the AL, AX, or EAX register is assumed to be the destination operand.
The size of the source and destination operands is selected with the mnemonic:
LODSB (byte loaded into register AL), LODSW (word loaded into AX), or LODSD
(doubleword loaded into EAX).
Post 12 Jan 2009, 11:03
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20481
Location: In your JS exploiting you and your system
revolution 12 Jan 2009, 11:15
MazeGen wrote:
Always use the latest manuals when in doubt.
Yes, indeed, very true.

Just like the software and hardware, manuals/documentation can also have "bugs". So the latest version is always the best place to start. Perhaps the old adage "if in doubt RTFM" can be slightly modified to "if in doubt RTLFM" where "L" stands for "latest"? Wink
Post 12 Jan 2009, 11:15
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.