OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 1:46 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: translate eseg label to GNU assembly syntax
PostPosted: Thu Oct 18, 2018 5:43 pm 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
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?


Top
 Profile  
 
 Post subject: Re: translate eseg label to GNU assembly syntax
PostPosted: Thu Oct 18, 2018 7:00 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
Misread this the first time. I guess you are using GNU Assembler and its Intel syntax.It would look like:
Code:
data16 rep es movsb

es = eseg
ds = dseg
etc

data16 = o16
data32 = o32
addr16 = a16
addr32 = a32


Top
 Profile  
 
 Post subject: Re: translate eseg label to GNU assembly syntax
PostPosted: Thu Oct 18, 2018 8:36 pm 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
my question

o16 rep movsb

is it equivalent to

rep movsw?

If not, what is the difference?


Top
 Profile  
 
 Post subject: Re: translate eseg label to GNU assembly syntax
PostPosted: Thu Oct 18, 2018 8:52 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
You originally asked about
Code:
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.


Top
 Profile  
 
 Post subject: Re: translate eseg label to GNU assembly syntax
PostPosted: Sat Oct 27, 2018 9:37 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 625 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group