flat assembler
Message board for the users of flat assembler.

Index > Windows > [Beginner] Instruction LEA

Author
Thread Post new topic Reply to topic
Linasm



Joined: 13 Nov 2004
Posts: 2
Linasm 03 Dec 2004, 13:37
How I use instruction LEA? I would like a very simple example for fasm.
Post 03 Dec 2004, 13:37
View user's profile Send private message MSN Messenger Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 03 Dec 2004, 19:44
test1 db 'this is string',0

lea eax,[test1]

store the address of test1 into eax
Post 03 Dec 2004, 19:44
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 03 Dec 2004, 19:51
which is equal to
mov eax,test1
Post 03 Dec 2004, 19:51
View user's profile Send private message Visit poster's website Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 03 Dec 2004, 21:17
another usage is to calculate the address of an element in an array:
Code:
lea eax, [ebx+ecx*4]    

where ebx is the "base address" (first element)
ecx the index, the 4 is because the array in this example is made up of dwords

lea means "load effective address"
Post 03 Dec 2004, 21:17
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 03 Dec 2004, 22:04
I know another use for LEA Very Happy
Code:
mov eax,15 ;eax=15
lea eax,[eax*4+eax] ; eax=75
lea eax,[eax*8+eax] ; eax=675
...
;or edi=esi<<3-edx
lea edi,[esi*8-edx]
...
;or eax=4*ebx+ecx-24
lea eax,[4*ebx+ecx-24]
;USE your imagination, but caution - this instruction
;is long and penalty might occur
    
Post 03 Dec 2004, 22:04
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 05 Dec 2004, 15:09
Madis is a good simple Smile
Post 05 Dec 2004, 15:09
View user's profile Send private message Reply with quote
Linasm



Joined: 13 Nov 2004
Posts: 2
Linasm 07 Dec 2004, 02:55
Thanks for help-me. Very Happy
Post 07 Dec 2004, 02:55
View user's profile Send private message MSN Messenger 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.