What's the difference between lea and mov in assembly?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
When viewing the registers, it seems the first 2 commands are the same, and then 3rd one puts the value of sample into rcx. I understand there is supposed to be some difference between the first 2 commands though.
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150
Rep:
to start you dont say what processor you are using which would help, anyway been a few years since i did any assembly programming but 'lea' stands for 'load efective address' and 'mov' is just short fore move, lea usualy takes an address plus a register and combines them to give the final or 'effective ' address which is where your data will be stored/loaded from, mov just uses a simple address, read up on indexed addressing for a full exxplanation.
lea usualy takes an address plus a register and combines them to give the final or 'effective ' address which is where your data will be stored/loaded from
What do you mean combines them?
Code:
lea rax, [sample]
This is putting the address of sample into rax, no?
My question is how is that different from (besides the fact I'm using rbx instead of rax):
The Assembler-writers don't agree on this. You might want to get the address of a field or the content of a field. The following syntaxes are used (and perhaps more):
#1 (address)
Code:
LEA AX,field
MOV AX,field
MOV AX,OFFSET field
#2 (content)
Code:
MOV AX,field
MOV AX,[field]
It doesn't look very clear; my suggestion is using the very first for the address and the very last for the content.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.