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.
I'm going through the NASM x86 assembly. My question is this:
Is it true that the command MOV EAX,[ESP] would be longer than MOV EAX,[EBX] after each is converted to machine language? The reason I believe that it is the case is that the first would have to make use of the SIB byte (since there are restrictions on the ESP register in indirect addressing) while the second does not make use of SIB. I just want to make sure I understand.
It has been a long time since I did this sort of thing, but I don't believe MOV EAX,[ESP] is supported by the x86 instruction set at all... at least, there's nothing listed in the Pentium manual for [ESP] that I can see.
If anything, this would have to be coded as POP EAX, PUSH EAX instead (2 bytes).
Thank you for your comment, CroMagnon. I was able to check the machine code for those statements. MOV EAX,[ESP] translates to 8B 04 24, while MOV EAX,[EBX] translates to the shorter 8B 03.
Sorry, I see my mistake now... you are correct, it does work but needs the SIB byte because the [ESP] addressing isn't supported alone, only in the form [ESP+reg*index]. The 24 byte says that there is no register or index to add on.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.