Greetings all,
a beginner is here ! :)
I want to know what's the difference between using :
1- lea dx,string
2- mov dx,offset string
I'm confused! as I think both of them gets 'string' address in memory
and puts it in dx
thanks for help!
regards,
amr
|
|
0
|
|
|
|
Reply
|
amrgo
|
1/19/2004 6:55:56 PM |
|
That's right, both LEA and MOV can load a register with the offset to a
variable for instance.
MOV can also transfer the content of a memory place to a register, LEA
can't.
Both LEA & MOV can calculate "effective offsets" which can be used to do
math much more effective
lookup_table db '0'
db '1'
db '2'
db '3'
db '4'
db '5'
db '6'
db '7'
db '8'
db '9'
db 'A'
db 'B'
db 'C'
db 'D'
db 'E'
db 'F'
code_start:
;Assumes EAX contains a integer between 0-15
mov al,byte[lookup_table+eax]
;EAX will now contain the ASCII character for the earlier
EAX.
ret
This was an example were MOV was used to calculate the effective address and
load the content of the address to itself...
Insted of:
mov al,byte[lookup_table+eax]
you could use:
mov eax, lookup_table+eax
Which would load the offset to the character pointed out by EAX.
Stronger math can be used however.
//Spike
----- Original Message -----
From: "Amr Mostafa" <amrgo@hotmail.com>
Newsgroups: comp.lang.asm.x86
Sent: Monday, January 19, 2004 7:55 PM
Subject: what's the differ between lea and mov offset ?
> Greetings all,
>
> a beginner is here ! :)
>
> I want to know what's the difference between using :
>
> 1- lea dx,string
> 2- mov dx,offset string
>
>
> I'm confused! as I think both of them gets 'string' address in memory
> and puts it in dx
>
> thanks for help!
>
> regards,
> amr
>
|
|
0
|
|
|
|
Reply
|
Spike
|
1/19/2004 8:16:26 PM
|
|
"Amr Mostafa" <amrgo@hotmail.com> wrote in message
news:6db7e405.0401190512.d3ebf2@posting.google.com...
> Greetings all,
>
> a beginner is here ! :)
>
> I want to know what's the difference between using :
>
> 1- lea dx,string
> 2- mov dx,offset string
>
>
> I'm confused! as I think both of them gets 'string' address in memory
> and puts it in dx
Yes, but to be clear it fetches nothing from main memory. The lea
instruction computes the address (in this case a constant: offset string)
and stores the result in dx. The mov instruction in this case is identical,
but it encodes into a shorter instruction, and it makes more sense too.
-Matt
|
|
0
|
|
|
|
Reply
|
Matt
|
1/19/2004 9:22:08 PM
|
|
amrgo@hotmail.com (Amr Mostafa) wrote in message news:<6db7e405.0401190512.d3ebf2@posting.google.com>...
> Greetings all,
>
> a beginner is here ! :)
>
> I want to know what's the difference between using :
>
> 1- lea dx,string
> 2- mov dx,offset string
>
>
> I'm confused! as I think both of them gets 'string' address in memory
> and puts it in dx
>
> thanks for help!
>
> regards,
> amr
The offset is evaluated statically by the assembler when you use the
MOV alternative, hence the offset must be available for computation at
assembly time. If the offset is not known at assembly time then you
cannot use the MOV alternative; the LEA alternative must be used since
in this case the offset is evaluated at run time.
|
|
0
|
|
|
|
Reply
|
x_b_y
|
1/20/2004 2:07:26 PM
|
|
Amr Mostafa wrote:
> Greetings all,
>
> a beginner is here ! :)
>
> I want to know what's the difference between using :
>
> 1- lea dx,string
> 2- mov dx,offset string
>
>
> I'm confused! as I think both of them gets 'string' address in memory
> and puts it in dx
>
> thanks for help!
>
> regards,
> amr
>
LEA is longer, on older processor could be slower, but I'm not sure
LEA is normally used for many optimalization tricks, because it can add
and load : lea eax,[esi+edi+4] for example
Adrian
|
|
0
|
|
|
|
Reply
|
Adrian
|
1/20/2004 6:11:15 PM
|
|
"xby" <x_b_y@my-deja.com> wrote in message
news:7d9d52e1.0401200556.63cc1e32@posting.google.com...
> amrgo@hotmail.com (Amr Mostafa) wrote in message
news:<6db7e405.0401190512.d3ebf2@posting.google.com>...
> > Greetings all,
> >
> > a beginner is here ! :)
> >
> > I want to know what's the difference between using :
> >
> > 1- lea dx,string
> > 2- mov dx,offset string
> >
> >
> > I'm confused! as I think both of them gets 'string' address in memory
> > and puts it in dx
> >
> > thanks for help!
> >
> > regards,
> > amr
>
>
> The offset is evaluated statically by the assembler when you use the
> MOV alternative, hence the offset must be available for computation at
> assembly time. If the offset is not known at assembly time then you
> cannot use the MOV alternative; the LEA alternative must be used since
> in this case the offset is evaluated at run time.
>
Eh? Both LEA and MOV can be used as in the example above (assembly time)
_and_ for values only known at load time (not run time, which is later). The
only difference is possibly variance in performance from one chipset to
another. You're confusing something like
lea dx,string[ax]
which is using a value in ax as a base to which to add the offset. That's at
runtime. The _offset_ is never calculated at runtime; it's fixed once the
program is loaded.
--
Regards
Alex McDonald
|
|
0
|
|
|
|
Reply
|
Alex
|
1/20/2004 10:51:11 PM
|
|
then I think they are the same and mov offset is faster than lea..
so I have to use mov. but If the offset is not known at assembly time
I have to use lea.. please correct me if I'm wrong
thaaaaanks a lot !
you help is very great and helpful
thank you
( i'm using google to post here so it may take some extra time to be
posted, I tried to use xnews and outlook but I alwayes get 441 you are
not allowed to post in comp.lang.asm.x86 - any one know why ? )
|
|
0
|
|
|
|
Reply
|
amrgo
|
1/20/2004 10:54:19 PM
|
|
Adrian wrote:
> LEA is longer, on older processor could be slower, but I'm not sure
> LEA is normally used for many optimalization tricks, because it can add
> and load : lea eax,[esi+edi+4] for example
>
> Adrian
>
lea can also be the fastest way to multiply a register's contents by a
fixed number. Say, multiply eax by 5 the obfuscated way. ;)
lea eax, [eax+eax*4]
There: fewer clocks (almost certainly), more bytes (probably), but edx
doesn't get smashed. Intel apparently didn't `design' their chips so
much as hack away at mask designs until they got something Microsoft
would develop for, but smart coders know how to use what they've been
handed. ;)
--
My address is yvoregnevna gjragl-guerr gjb-gubhfnaq guerr ng lnubb qbg pbz
Note: Rot13 and convert spelled-out numbers to numerical equivalents.
|
|
0
|
|
|
|
Reply
|
August
|
1/20/2004 10:55:05 PM
|
|
Amr Mostafa <amrgo@hotmail.com> schreef in berichtnieuws
6db7e405.0401201131.6b0e7e29@posting.google.com...
Hello Amr,
> then I think they are the same and mov offset is faster than lea..
> so I have to use mov. but If the offset is not known at assembly time
> I have to use lea.. please correct me if I'm wrong
You are hereby corrected :-)
LEA can do what OFFSET does, but it can do more. In the case of "lea
{reg},{address}" and "mov {reg},offset {address}" you are quite right, "mov
offset..." wil be faster (and shorter).
But imagine loading a register with the start of a table + an index. Assume
you want the result in AX, the index is in BX, and the name of / label to
the table is "Table"
In 'straight" code you would probably write :
mov ax,offset Table
add ax,bx
Using LEA this would be :
lea ax, [Table+bx]
It would even look better if you have a sub-table,pointed to by SI, at an
address in which you want to addres an element pointed to by BX
In "straight" code you would write :
mov ax,offset Table
add ax,si
add ax,bx
Using LEA this would be :
lea eax,[Table+si+bx]
Ofcourse, just a small combination of registers is permitted with LEA.
> thaaaaanks a lot !
> you help is very great and helpful
> thank you
You're welcome :-)
> ( i'm using google to post here so it may take some extra time to be
> posted, I tried to use xnews and outlook but I alwayes get 441 you are
> not allowed to post in comp.lang.asm.x86 - any one know why ? )
Maybe because the Newsgroup-server does not know who you are ?
Probably Google accepts your post because you have authenticated yourself to
it, and a newsgroup-server does not, because you have not authenticated
yourself to it. Ask your ISP for more details on the matter.
Regards,
Rudy Wieser
|
|
0
|
|
|
|
Reply
|
R
|
1/21/2004 2:17:09 AM
|
|
"Alex McDonald" <alex_mcd@btopenworld.com> wrote in message news:<bukajo$elm$1@hercules.btinternet.com>...
> "xby" <x_b_y@my-deja.com> wrote in message
> news:7d9d52e1.0401200556.63cc1e32@posting.google.com...
> > amrgo@hotmail.com (Amr Mostafa) wrote in message
> news:<6db7e405.0401190512.d3ebf2@posting.google.com>...
> > > Greetings all,
> > >
> > > a beginner is here ! :)
> > >
> > > I want to know what's the difference between using :
> > >
> > > 1- lea dx,string
> > > 2- mov dx,offset string
> > >
> > >
> > > I'm confused! as I think both of them gets 'string' address in memory
> > > and puts it in dx
> > >
> > > thanks for help!
> > >
> > > regards,
> > > amr
> >
> >
> > The offset is evaluated statically by the assembler when you use the
> > MOV alternative, hence the offset must be available for computation at
> > assembly time. If the offset is not known at assembly time then you
> > cannot use the MOV alternative; the LEA alternative must be used since
> > in this case the offset is evaluated at run time.
> >
>
> Eh? Both LEA and MOV can be used as in the example above (assembly time)
> _and_ for values only known at load time (not run time, which is later). The
> only difference is possibly variance in performance from one chipset to
> another. You're confusing something like
>
> lea dx,string[ax]
>
> which is using a value in ax as a base to which to add the offset. That's at
> runtime. The _offset_ is never calculated at runtime; it's fixed once the
> program is loaded.
First of all, I was explaining the difference between the MOV and LEA
alternatives in general, without referring to the specific examples
brought up by the OP. Hence, there is no confusion on my part.
Second, your example "lea dx,string[ax]" is not valid. In 16 bit
assembly (as the notations AX and DX indicate) one can code
LEA DX,STRING[BX], or
LEA DX,STRING[SI], or
LEA DX,STRING[DI]
since only BX, SI, and DI are valid inside the square brackets.
|
|
0
|
|
|
|
Reply
|
x_b_y
|
1/21/2004 1:42:09 PM
|
|
x_b_y@my-deja.com (xby) wrote in message news:<7d9d52e1.0401210535.65098e82@posting.google.com>...
> "Alex McDonald" <alex_mcd@btopenworld.com> wrote in message news:<bukajo$elm$1@hercules.btinternet.com>...
> > "xby" <x_b_y@my-deja.com> wrote in message
> > news:7d9d52e1.0401200556.63cc1e32@posting.google.com...
> > > amrgo@hotmail.com (Amr Mostafa) wrote in message
> news:<6db7e405.0401190512.d3ebf2@posting.google.com>...
> > > > Greetings all,
> > > >
> > > > a beginner is here ! :)
> > > >
> > > > I want to know what's the difference between using :
> > > >
> > > > 1- lea dx,string
> > > > 2- mov dx,offset string
> > > >
> > > >
> > > > I'm confused! as I think both of them gets 'string' address in memory
> > > > and puts it in dx
> > > >
> > > > thanks for help!
> > > >
> > > > regards,
> > > > amr
> > >
> > >
> > > The offset is evaluated statically by the assembler when you use the
> > > MOV alternative, hence the offset must be available for computation at
> > > assembly time. If the offset is not known at assembly time then you
> > > cannot use the MOV alternative; the LEA alternative must be used since
> > > in this case the offset is evaluated at run time.
> > >
> >
> > Eh? Both LEA and MOV can be used as in the example above (assembly time)
> > _and_ for values only known at load time (not run time, which is later). The
> > only difference is possibly variance in performance from one chipset to
> > another. You're confusing something like
> >
> > lea dx,string[ax]
> >
> > which is using a value in ax as a base to which to add the offset. That's at
> > runtime. The _offset_ is never calculated at runtime; it's fixed once the
> > program is loaded.
>
>
> First of all, I was explaining the difference between the MOV and LEA
> alternatives in general, without referring to the specific examples
> brought up by the OP. Hence, there is no confusion on my part.
OK, so you're saying you can't have MOV if the offset is unknown at
assembly time, but you can use LEA? That's not so. There's no
difference (except possible speed) between MOV reg, const and LEA reg,
const. Regardless of whether the assembler knows the value as in
"MOV/LEA AX,10" or has to leave to the linker /loader the value as in
"MOV/LEA AX,external_address". 16 bit, 32 bit, doesn't make any
difference either.
>
> Second, your example "lea dx,string[ax]" is not valid. In 16 bit
> assembly (as the notations AX and DX indicate) one can code
> LEA DX,STRING[BX], or
> LEA DX,STRING[SI], or
> LEA DX,STRING[DI]
> since only BX, SI, and DI are valid inside the square brackets.
I stand corrected. The principle still applies.
--
Regards
Alex McDonald
|
|
0
|
|
|
|
Reply
|
alex_mcd
|
1/22/2004 6:19:56 PM
|
|
thanks a lot !
that was very useful
while I didn't understand everything said here, but I saved this for
later view after going a little forward with my guide ( by Ralph )
but about my question.. it's extra answered! ;)
regards,
amr
|
|
0
|
|
|
|
Reply
|
amrgo
|
1/22/2004 8:17:31 PM
|
|
alex_mcd@btopenworld.com (Alex McDonald) wrote:
>
>x_b_y@my-deja.com (xby) wrote :
>>
>> First of all, I was explaining the difference between the MOV and LEA
>> alternatives in general, without referring to the specific examples
>> brought up by the OP. Hence, there is no confusion on my part.
>
>OK, so you're saying you can't have MOV if the offset is unknown at
>assembly time, but you can use LEA? That's not so. There's no
>difference (except possible speed) between MOV reg, const and LEA reg,
>const.
I suspect/hope he was referring to cases like
lea eax, [ebp+4]
That is an example that cannot be done using MOV.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
Tim
|
1/23/2004 7:15:40 PM
|
|
Tim Roberts <timr@probo.com> wrote in message news:<fjs210t63v2lcrglgkqohouu7n8kggbogl@4ax.com>...
>
> I suspect/hope he was referring to cases like
> lea eax, [ebp+4]
> That is an example that cannot be done using MOV.
Yes, this is an example of what I mean. Whenever one or two registers
is/are coded between square brackets, the offset referred to is known
at run time but not at assembly time. In such cases MOV cannot be
used, but LEA can be used.
|
|
0
|
|
|
|
Reply
|
x_b_y
|
1/26/2004 3:16:06 PM
|
|
|
13 Replies
764 Views
(page loaded in 0.141 seconds)
Similiar Articles: what's the differ between lea and mov offset ? - comp.lang.asm.x86 ...Greetings all, a beginner is here ! :) I want to know what's the difference between using : 1- lea dx,string 2- mov dx,offset string I'm confused... Re: LEA instruction - comp.lang.asm.x86what's the differ between lea and mov offset ? - comp.lang.asm.x86 ... The mov instruction in this case is identical, but it encodes into a ... You're confusing something ... assembly for boot sectors - comp.lang.asm.x86what's the differ between lea and mov offset ? - comp.lang.asm.x86 ... assembly for boot sectors - comp.lang.asm.x86 what's the differ between lea and mov offset ? - comp ... What's the difference? - comp.databases.btrievewhat's the differ between lea and mov offset ? - comp.lang.asm.x86 ... Greetings all, a beginner is here ! :) I want to know what's the difference between using : 1- lea ... About instruction lea - comp.lang.asm.x86what's the differ between lea and mov offset ? - comp.lang.asm.x86 ... The lea instruction computes the address (in this case a constant: offset string) and stores the ... What does it mean for a folder with "@" in front of the name ...A lot of packages I download from web includes folders that have "@" in front of their names. What does it mean? Thanks. ... The difference between return and exit()? - comp.unix.programmer ...what's the differ between lea and mov offset ? - comp.lang.asm.x86 ...:) I want to know what's the difference between using : 1- lea dx,string 2- mov dx,offset ... of ... Calculating member offset at runtime - comp.lang.c++.moderated ...what's the differ between lea and mov offset ? - comp.lang.asm.x86 ... Calculating member offset at runtime - comp.lang.c++.moderated ... How to calculate effective ... Difference between QUIT and RUN - comp.soft-sys.saswhat's the differ between lea and mov offset ? - comp.lang.asm.x86 ...:) I want to know what's the difference between using ... only known at load time (not run time ... What is Difference between const int i and int const i - comp.lang ...what's the differ between lea and mov offset ? - comp.lang.asm.x86 ..... what's the difference between using : 1 ... EAX contains a integer between ... what is the difference between reboot and init6 - comp.unix ...Difference between Interactive and Non Interactive user id's ... what is the difference between reboot and init6 - comp.unix ... Difference between Interactive and Non ... RE: [ntp:questions] Re: Frequency and leapseconds! - comp ...Is it any difference between phase error and offset error? This phase = correction ... what's the differ between lea and mov offset ? - comp.lang.asm.x86 ... RE: [ntp ... looping through array in gas - comp.lang.asm.x86There it says that the expression is: > base_address(offset_addres ... can be performed quickly with any need for push/pop or mov's. I haven't actually used lea that ... improve strlen - comp.lang.asm.x86... pop esi ret 0 $LN6@xstrlen: mov eax, OFFSET $SG-28 npad 6 $LL4@xstrlen: mov edx, DWORD PTR [eax] lea ... Well, maybe that's the difference between us. You see, I've got ... "TYPEDEF PTR with STRUCT" masm32 - comp.lang.asm.x86> LEA EDX,OFFSET yourstruc > push eax > push ebx > mov eax, [EDX.myStrc.ABC] > mov ebx ... Difference between const int i and int const i - comp.lang ... what's the differ between lea and mov offset ? - comp.lang.asm.x86 ...Greetings all, a beginner is here ! :) I want to know what's the difference between using : 1- lea dx,string 2- mov dx,offset string I'm confused... The Difference between LEA and MOV OFFSET | KernelTrapThe Difference between LEA and MOV OFFSET ... of using DOS ISR 21h, I stumbled upon the use of LEA dx, var and MOV dx, OFFSET var. 7/25/2012 11:42:24 AM
|