|
Latest post 03-08-2007 7:35 PM by modchip. 9 replies.
-
03-07-2007 12:29 AM
|
|
-
modchip


- Joined on 02-09-2006
- Ivalice
- Posts 710
- Points 10,110
|
Hi all! I was just wondering, is there a big difference between LEA and MOV? Also, I did some test; lea eax, buffer invoke SetDlgItemText, hWin, IDC_EDIT_OUTPUT, eax and mov eax, offset buffer invoke SetDlgItemText, hWin, IDC_EDIT_OUTPUT, eax Same results. What's the difference? Thanks in advance peeps! Chao!
|
|
-
-
cruizer


- Joined on 12-14-2005
- Singapore
- Posts 944
- Points 22,590
|
the "OFFSET" (in the MOV) is not really a part of assembly language. it will just be replaced by the actual address of "buffer" upon assembly/compilation by the assembler. so parang macro sya since may substitution, but I'm sure it's not called a macro on the other hand, LEA is a real assembly language instruction. I think the benefit to using LEA is that you can do sort of pointer/index arithmetic on it, like LEA eax, buffer+SI...if I remember it right  but certainly, the MOV ... OFFSET in my opinion is better. ganyan talaga pag complex instruction set (CISC), maraming redundancy sa mga instructions. yan ang isa sa mga nagpapabagal ng CPUs natin ngayon, yun legacy baggage
http://devpinoy.org/blogs/cruizer
Naglalayong buksan at palayain ang kamalayan ng Pinoy .NET developer
|
|
-
-
modchip


- Joined on 02-09-2006
- Ivalice
- Posts 710
- Points 10,110
|
Aha! The gave me some "enlightenment"! Thanks. Time for more tests! Thanks again!
|
|
-
-
cvega


- Joined on 11-25-2005
- Posts 497
- Points 8,455
|
cruizer:the "OFFSET" (in the MOV) is not really a part of assembly language. it will just be replaced by the actual address of "buffer" upon assembly/compilation by the assembler. so parang macro sya since may substitution, but I'm sure it's not called a macro
It is mov eax, offset variableis the same as: lea eax, variableThe only difference is that OFFSET is resolved during assemble, while LEA is during run-time, hence MOV ..., OFFSET ... can't resolve forward references. .code
mov eax, offset forward_var ; looks valid, but will cause assemble error ret 0
forward_var dd 0 cruizer:on the other hand, LEA is a real assembly language instruction. I think the benefit to using LEA is that you can do sort of pointer/index arithmetic on it, like LEA eax, buffer+SI...if I remember it right 
Yes, because LEA resolve effective address during the runtime. The ADDR special MASM keyword is actually a LEA. cruizer:but certainly, the MOV ... OFFSET in my opinion is better. ganyan talaga pag complex instruction set (CISC), maraming redundancy sa mga instructions. yan ang isa sa mga nagpapabagal ng CPUs natin ngayon, yun legacy baggage 
MOV...OFFSET is not a legacy baggage, and it's commonly used most of the time. Whichever you prefer, both of these are only using 1 clock cycle  Cheers, -chris
Chris Vega
This posting is provided "AS IS" with no warranties, and confers no rights
My Weblog| Visit MSDN Community
|
|
-
-
cvega


- Joined on 11-25-2005
- Posts 497
- Points 8,455
|
Re: LEA & MOV Stuff
Answer
modchip:Hi all! I was just wondering, is there a big difference between LEA and MOV?
Depending on what you want to use the command for, but most safe answer is, these two commands are equivalent in both clock cycle and functionality. It's only for preference, actually. However, sometimes you may find OFFSET handy in some places, like calculating the OFFSET of a member in a stuct: my_struc struct memberA dd 0 memberB dd 0 my_struc ends
my_var my_struc <0, 0>
.code
push ebx mov ebx, offset my_var assume ebx: my_struct
; to reference memberA mov eax, [ebx].memberACheers, -chris
Chris Vega
This posting is provided "AS IS" with no warranties, and confers no rights
My Weblog| Visit MSDN Community
|
|
-
-
modchip


- Joined on 02-09-2006
- Ivalice
- Posts 710
- Points 10,110
|
Thanks, now it's more clear. Funny, cause you actually read my mind, I was hoping to ask about that struct stuff too that I see in other major asm sites. my_struc struct memberA dd 0 memberB dd 0 my_struc ends
my_var my_struc <0, 0>
Is this like sort of an array? What are some practical uses for this? Thanks again! Regards, m0ds
|
|
-
-
cruizer


- Joined on 12-14-2005
- Singapore
- Posts 944
- Points 22,590
|
syntactic sugar lang yan, to allow you to treat structured blocks of memory as a whole (rather than referring to it using the first item in the structure/memory block)
http://devpinoy.org/blogs/cruizer
Naglalayong buksan at palayain ang kamalayan ng Pinoy .NET developer
|
|
-
-
modchip


- Joined on 02-09-2006
- Ivalice
- Posts 710
- Points 10,110
|
Hmmmm... can you please elaborate on that, or maybe a simple example could do the trick. It's not really that clear to me. :D
|
|
-
-
cvega


- Joined on 11-25-2005
- Posts 497
- Points 8,455
|
Re: LEA & MOV Stuff
Answer
modchip:Is this like sort of an array? What are some practical uses for this?
Nope, structures are usually used to "give meaning" to block of memory. And to elliminate to problem of little-endian, big-endian notation. Meaning, it's all about "looking up" to the memory. Let's say we point EBX to some memory: mov ebx, offset some_memory_addressInitially, you don't know what's in the memory, because that's only a set of binary data! So, you'll need structure to give meaning to it: assume ebx: my_structureThat gives assembler an idea that EBX is working as my_structure block, rather than just a pointer. Hence, when you get a member from the structure, the assembler automatically can calculate the OFFSET: mov eax, [ebx].LastMemberIs similar to: lea eax, some_memory_address + my_structure.LastMemberHowever, since LEA is resolved at runtime, it's usually larger than MOV..OFFSET. Hope this helps, -chris
Chris Vega
This posting is provided "AS IS" with no warranties, and confers no rights
My Weblog| Visit MSDN Community
|
|
-
-
modchip


- Joined on 02-09-2006
- Ivalice
- Posts 710
- Points 10,110
|
Thanks Chris & cruizer, your answers really help. :D Now it's time to apply my newly received knowledge! Thanks again dude!
|
|
Page 1 of 1 (10 items)
|
|
|