translate eseg label to GNU assembly syntax

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

translate eseg label to GNU assembly syntax

Post by ITchimp »

I was reading this old assembly x86 assembly files... and got a few questions

1. how do I translate the following statement

rep
eseg o16 movs

to gnu assembler Intel style...

I tried

rep
eseg movsw

did not work

eseg
rep movsw
did not work...

What is the right translation?

lea esi, -1(esi)(edx*1)

I think I can translate into

lea esi, [edx*1+esi-1]

Am I correct?
MichaelPetch
Member
Member
Posts: 799
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: translate eseg label to GNU assembly syntax

Post by MichaelPetch »

Misread this the first time. I guess you are using GNU Assembler and its Intel syntax.It would look like:

Code: Select all

data16 rep es movsb
es = eseg
ds = dseg
etc

data16 = o16
data32 = o32
addr16 = a16
addr32 = a32
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

Re: translate eseg label to GNU assembly syntax

Post by ITchimp »

my question

o16 rep movsb

is it equivalent to

rep movsw?

If not, what is the difference?
MichaelPetch
Member
Member
Posts: 799
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: translate eseg label to GNU assembly syntax

Post by MichaelPetch »

You originally asked about

Code: Select all

rep
eseg o16 movs
. In that particular old assembler movs is the same as movsb. Movsb moves a byte at a time. Movsw moves words (2 bytes at a time), and Movsd words 4 bytes at a time. By default in 32-bit code data would be moved from DS:ESI to ES:EDI. The ESEG (or ES) segment override changes the default source segment from DS to ES. That results in ES:ESI to ES:EDI. The REP prefix does the move the specified number of times in ECX. Each iteration ESI and EDI would be increased by 1 with Movsb (incremented by 2 each time for movsw, and 4 for movsd - movsd not available in 16-bit). If the direction flag is set (with STD) then ESI and EDI are decremented instead of incremented.

Edit: I mistakenly said this previously "The o16 (or data16) forces the operation to be done with 16-bit registers so DS:SI to ES:DI". I don't believe `o16` does anything at all and is superfluous and can be removed *in this case*. What is true is "a16 (or addr16) forces the operation to be done with 16-bit address registers so DS:SI to ES:DI" and if using REP, then CX will be used for counting instead of ECX.

Edit2: The only situation where o16 might do something is if you are using movsd. The result may be that it would be interpreted as movsw. I haven't tested this to see if this is true.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: translate eseg label to GNU assembly syntax

Post by Combuster »

movsw and movsd are the same opcode, where the combination of execution mode and presence/absence of the operand-size prefix (o16 or o32 are the same opcodes too!) determines which of the two it is. movsb is a distinct opcode and needs no size prefixes. In addition, the original manuals listed movs as an alternative notation where the source and destination are to be added explicitly. As such, movs without those arguments is therefore assembler-specific dialect and should be treated with caution to its real meaning.

Assemblers that use "plain" movs don't have the operand size stored in the name itself and thus need extra information to determine if the programmer wanted movsb/movsw/movsd. Using the -bwd prefixes dictates the size on the spot, and the assembler will add the correct o16 or o32 if and where it is needed. Adding o16 to movsb is effectively a conflicting statement and I have no idea how each assembler out there would try to interpret that (adding the illegal prefix to movsb, dropping the prefix altogether, promote to movsw, or perhaps just erroring).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply