flat assembler
Message board for the users of flat assembler.

 Index > Windows > [Beginner] Instruction LEA
Author
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.
03 Dec 2004, 13:37
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
03 Dec 2004, 19:44
vbVeryBeginner

Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 03 Dec 2004, 19:51
which is equal to
mov eax,test1
03 Dec 2004, 19:51
scientica
Retired moderator

Joined: 16 Jun 2003
Posts: 689
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

03 Dec 2004, 21:17

Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
I know another use for LEA
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
```
03 Dec 2004, 22:04
Nikolay Petrov

Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 05 Dec 2004, 15:09
05 Dec 2004, 15:09
Linasm

Joined: 13 Nov 2004
Posts: 2
Linasm 07 Dec 2004, 02:55
Thanks for help-me.
07 Dec 2004, 02:55
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum