[SOLVED] How to use constraints "m" in gcc inline assembly when I pass a string ?
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.
The point of such a constraint is that usually it makes no difference in the generated code, but in some complicated situations (typically when the function containing it is inlined into a caller) it affects some transformation that the optimizer makes to a related piece of code.
I don't know those syntax details myself. I rarely use asm, and only for large enough chunks that grossly suppressing optimization of the bordering C++ code is easier and makes sense (compared to fine tuning the constraints).
For your suggestion to make sense, one would need to first have a very good understanding of the optimizer and then construct a much more complicated example in which the correct vs. incorrect syntax for the constraint makes a difference in the optimization of surrounding code (with the incorrect syntax either allowing an incorrect optimization or preventing a correct optimization).
Understanding the syntax specification would be better than such experimentation. I expect someone in this forum does understand those syntax details. I don't.
So,in addition to passing information in registers, gcc can understand references to raw memory. This will expand to some more complex addressing mode within the asm string.See this http://locklessinc.com/articles/gcc_asm/
What the "%1" represent is not important, because it changes all the time relying on the addressing mode.
Am I right?
Thanks all the people!
Last edited by mirage1993; 10-07-2014 at 10:16 AM.
No, you can't apply memory segments like that. If (%eax) is 'a' then %ds:(%eax) is also 'a' (because current OSes setup the memory segments to have no effect (except for the %fs is used for thread local variables, I think)). But regardless, the segment applies to the address not the value located at the address.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.