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
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
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
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
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: 2140
Location: Estonia
Madis731
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
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
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.