flat assembler
Message board for the users of flat assembler.
Index
> Main > mov and lea -- difference Goto page 1, 2 Next |
Author |
|
jorido 08 Oct 2017, 11:14
Is there any difference between these 2?
Code: ;................ var1 db "some text here.....", 10, 0 ; 1 lea rdi, [var1] ; 2 mov rdi, var1 |
|||
08 Oct 2017, 11:14 |
|
jorido 08 Oct 2017, 11:57
my question isn't about that
|
|||
08 Oct 2017, 11:57 |
|
Furs 08 Oct 2017, 12:00
I don't get it then. Didn't you ask if there is any difference? Those are some pretty big differences in terms of code size (for x64) and efficiency (lack of relocations).
If you mean in terms of what they do, then no, they are the same. |
|||
08 Oct 2017, 12:00 |
|
revolution 08 Oct 2017, 12:12
Relocations are only relevant for some file formats. The major difference, aside from relocations, is the RIP vs absolute addressing in 64-bit mode, and the number of bytes the instructions use in the code. They might also use different execution ports depending upon the CPU they run on. MOV can load any 64-bit value, LEA cannot address further than +-2G.
|
|||
08 Oct 2017, 12:12 |
|
jorido 08 Oct 2017, 14:00
>> If you mean in terms of what they do, then no, they are the same.
yes, what they do thx |
|||
08 Oct 2017, 14:00 |
|
system error 09 Oct 2017, 02:00
ehemmm!! *_*
@jorido MOV and LEA makes HUGE differences when doing stack LOCALS. They are NOT the same, like some people claimed xD locals var1 db "some text here.....", 10, 0 endl mov rdi var1 will throw you error for the obvious "academic" reasons. Can't calculate address that is not yet called at runtime. lea rdi,[var1] ---> the solution. Address is calculated at runtime when it matters. regardless of 32-bit or 64-bit. Every LEA will translate to an address regardless. Not all MOV translates to an address. That's another HUGH difference. For example, mov rdi,[rbp-16] is NOT THE SAME as lea rdi,[rbp-16] in the case of STOSB where RDI needs to point to a buffer. Edit by revolution: Trolling removed |
|||
09 Oct 2017, 02:00 |
|
revolution 09 Oct 2017, 04:15
Yes, for a locally defined variable mov reg,var will fail to assemble. Because you end up trying to assemble mov reg,rbp+offset. But the error message quickly tells you there is a problem.
|
|||
09 Oct 2017, 04:15 |
|
Furs 09 Oct 2017, 12:11
system error wrote: ehemmm!! *_* Edit by revolution: Trolling removed |
|||
09 Oct 2017, 12:11 |
|
system error 09 Oct 2017, 13:12
Edit by revolution: Trolling removed
|
|||
09 Oct 2017, 13:12 |
|
system error 09 Oct 2017, 13:17
Edit by revolution: Trolling removed
|
|||
09 Oct 2017, 13:17 |
|
system error 09 Oct 2017, 13:26
Furs wrote: If you mean in terms of what they do, then no, they are the same. No! MOV is a transfer instruction. LEA is an address generation instruction. They may result in the same effect , but in terms of "what they do", they are not. Edit by revolution: Trolling removed |
|||
09 Oct 2017, 13:26 |
|
revolution 09 Oct 2017, 13:39
system error wrote: MOV is a transfer instruction. LEA is an address generation instruction. They may result in the same effect , but in terms of "what they do", they are not. |
|||
09 Oct 2017, 13:39 |
|
Furs 09 Oct 2017, 13:48
system error wrote: No! Obviously, all this was already specified in the first post... |
|||
09 Oct 2017, 13:48 |
|
system error 09 Oct 2017, 18:50
Furs wrote: That makes no sense. Which part? LEA doesn't transfer anything. Its sole purpose is to calculate the address at runtime. Some advanced folks use it for complex math. That's all there is. That's a HUGE DIFFERENCE. I can take instructions like XCHG to be of the same "transfer" instructions like MOV. But not LEA. LEA edi,[EBP+16] is NEVER the same in "what they do" against MOV edi, [EBP+16]. Edit by revolution: Trolling removed |
|||
09 Oct 2017, 18:50 |
|
system error 09 Oct 2017, 18:56
Edit by revolution: Trolling removed
|
|||
09 Oct 2017, 18:56 |
|
system error 09 Oct 2017, 19:02
Edit by revolution: Trolling removed
|
|||
09 Oct 2017, 19:02 |
|
system error 09 Oct 2017, 19:07
Furs wrote: For 64-bit, always use lea since it uses rip-relative addressing (FASM does it implicitly). mov, on the other hand, besides having to add a relocation to mov, it also uses an 64-bit address! (rip-relative is only a 32-bit offset) (unless it's an executable with a fixed position when loaded, but is that a thing anymore?). Wrong again. LEA doesn't always translates to RIP-relative. Try this code and see it "relatives" to what... sub rsp,16 lea rdi,[rbp-16] ;?? mov rdi,[rbp-16] ;?? Question: Do you see RIP in there? xD Edit by revolution: Trolling removed |
|||
09 Oct 2017, 19:07 |
|
Furs 09 Oct 2017, 20:43
lol man, again you're derailing, see the opening post. This is his code:
Code: ; 1 lea rdi, [var1] ; 2 mov rdi, var1 But encoded it is RIP-relative, and a disassembly will show that easily. |
|||
09 Oct 2017, 20:43 |
|
system error 09 Oct 2017, 21:40
Edit by revolution: Trolling removed
|
|||
09 Oct 2017, 21:40 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.