View previous topic :: View next topic |
Author |
Message |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Thu Jun 07, 2007 1:53 pm Post subject: [Help] LEA |
|
|
What is the LEA function used for? I understand that it puts the offset of one thing into an address, like below.
Now the value of esi is a. But couldn't you just use the mov function to do it? Or does the lea function do something else?
|
|
Back to top |
|
 |
Labyrnth Moderator
Reputation: 9
Joined: 28 Nov 2006 Posts: 6285
|
Posted: Thu Jun 07, 2007 5:06 pm Post subject: Re: [Help] LEA |
|
|
samuri25404 wrote: | What is the LEA function used for? I understand that it puts the offset of one thing into an address, like below.
Now the value of esi is a. But couldn't you just use the mov function to do it? Or does the lea function do something else? |
This loads esi with the address from [eax+a]
_________________
|
|
Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Thu Jun 07, 2007 5:23 pm Post subject: |
|
|
lea = load effective address
the address at the defined source is stored in your destination.
_________________
|
|
Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Thu Jun 07, 2007 6:01 pm Post subject: |
|
|
sponge wrote: | lea = load effective address
the address at the defined source is stored in your destination. |
(I knew it meant load effective address)
So basically the address pointed at by the pointer is stored in esi? How would the mov function handle the same thing, or would that be incorrect syntax? Mov would just add the "eax+a" and store that in esi, wouldn't it?
|
|
Back to top |
|
 |
Labyrnth Moderator
Reputation: 9
Joined: 28 Nov 2006 Posts: 6285
|
Posted: Thu Jun 07, 2007 6:11 pm Post subject: |
|
|
The address calculated from [eax+a] is stored in esi
_________________
|
|
Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Thu Jun 07, 2007 6:12 pm Post subject: |
|
|
Labyrnth wrote: | The address calculated from [eax+a] is stored in esi |
Alright, thanks! =)
|
|
Back to top |
|
 |
Chi-Tur How do I cheat?
Reputation: 0
Joined: 13 Jun 2007 Posts: 1
|
Posted: Wed Jun 13, 2007 5:13 pm Post subject: ... |
|
|
i guess that helped... ty
|
|
Back to top |
|
 |
Programmer Cheater
Reputation: 0
Joined: 02 Sep 2007 Posts: 48
|
Posted: Mon Sep 10, 2007 7:15 pm Post subject: |
|
|
This is a late post, but might help someone?
You can use it to get the address of a variable etc. e.g
Code: |
Variable: db 00
lea edi, Variable |
The EDI register now contains the memory address of your variable.
_________________
|
|
Back to top |
|
 |
TheSorc3r3r I post too much
Reputation: 0
Joined: 06 Sep 2006 Posts: 2404
|
Posted: Tue Sep 11, 2007 4:18 pm Post subject: |
|
|
Programmer wrote: | This is a late post, but might help someone?
You can use it to get the address of a variable etc. e.g
Code: |
Variable: db 00
lea edi, Variable |
The EDI register now contains the memory address of your variable. |
Since the default is the lvalue anyway, wouldn't
mov edi, Variable
do the same thing (assuming you're not using masm which makes the default the rvalue).
_________________
Don't laugh, I'm still learning photoshop! |
|
Back to top |
|
 |
Ksbunker Advanced Cheater
Reputation: 0
Joined: 18 Oct 2006 Posts: 88
|
Posted: Tue Sep 11, 2007 8:16 pm Post subject: re: |
|
|
Take from Art of Assembly (http://webster.cs.ucr.edu/AoA/DOS/ch06/CH06-1.html#HEADING1-136)
Code: | LEA destination, source |
specifically
Code: | lea register, memory |
Of Particular significance;
Quote: | 1. lea ax, [bx]
2. lea bx, 3[bx]
3. lea ax, 3[bx]
4. lea bx, 4[bp+si]
5. lea ax, -123[di] |
The lea ax, [bx] instruction copies the address of the expression [bx] into the ax register. Since the effective address is the value in the bx register, this instruction copies bx's value into the ax register. Again, this instruction isn't very interesting because mov can do the same thing, even faster.
The lea bx,3[bx] instruction copies the effective address of 3[bx] into the bx register. Since this effective address is equal to the current value of bx plus three, this lea instruction effectively adds three to the bx register. There is an add instruction that will let you add three to the bx register, so again, the lea instruction is superfluous for this purpose.
The third lea instruction above shows where lea really begins to shine. lea ax, 3[bx] copies the address of the memory location 3[bx] into the ax register; i.e., it adds three with the value in the bx register and moves the sum into ax. This is an excellent example of how you can use the lea instruction to do a mov operation and an addition with a single instruction.
The final two instructions above, lea bx,4[bp+si] and lea ax,-123[di] provide additional examples of lea instructions that are more efficient than their mov/add counterparts.
|
|
Back to top |
|
 |
|