How to use constraints "m" in gcc inline assembly when I pass a string ?
In this program
Code:
char get_fs_byte(char * s) this Code:
char get_fs_byte(char * s) Code:
"m"(*s) Code:
"m"(s) |
Are you absolutely sure you want to do this? Your program will be dependent on one single platform and one single compiler.
|
Quote:
|
Then, I suppose, you have learned these by heart:
http://www.ibiblio.org/gferg/ldp/GCC...bly-HOWTO.html https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html |
Quote:
when I use "m"(*s). I am confused . Is "%1" a pointer to a string or the first characters of a string ? |
And how did you try to debug it?
|
Quote:
|
Quote:
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. |
Quote:
Code:
"m"(*s) "m"(s) |
Quote:
I write another program. Code:
#include<stdio.h> and in the next code Code:
#include<stdio.h> Note:tmp==s Besides,in the next code Code:
#include<stdio.h> 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?:D Thanks all the people! |
Quote:
Quote:
Quote:
Quote:
|
Quote:
Code:
movb %%ds:%1,%0 Code:
movb %ds:(%eax),%edx |
Quote:
%eax is s (%eax) is *s %1 is the whole expression (%eax) not just the register %eax The only difference vs. the earlier *s example that you seem to understand is the %ds: but that makes no actual difference. |
Quote:
Code:
movb %%ds:%1,%0 Code:
movb %ds:a,%0 |
Quote:
|
All times are GMT -5. The time now is 08:31 PM. |