Stupid GCC inline assembler doesn't even support local variable
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.
1. I happened to use g++ (not gcc per se). G++ v4.1.2. The latest/greatest with CentOS 5.4:
Quote:
g++ --version
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2. Yes, Gnu C/C++ inline assembler can access C/C++ local variables by name:
% g++ --version ~/tmp
g++ (Debian 4.4.4-5) 4.4.4
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% cat asm.cc ~/tmp
int myfunc(float f){
int x;
float fa[8];
asm (
"mov x,%eax\n"
"movss f,%xmm1\n"
"flds (fa+4)\n"
);
}
int main() { return 0; }
% g++ -Wall -Wextra asm.cc -o asm ~/tmp
asm.cc: In function int myfunc(float):
asm.cc:2: warning: unused variable x
asm.cc:3: warning: unused variable fa
asm.cc:9: warning: no return statement in function returning non-void
asm.cc: At global scope:
asm.cc:1: warning: unused parameter f
/tmp/ccOA2oSl.o: In function `myfunc(float)':
asm.cc:(.text+0xc): undefined reference to `x'
asm.cc:(.text+0x15): undefined reference to `f'
asm.cc:(.text+0x1c): undefined reference to `fa'
collect2: ld returned 1 exit status
I just wanted to say that I've known ASM since I was 12, and I *still* haven't learned C, because I can't stomach the concept of pointers, but - does anyone else think that C is sort of like, a high-level ASM?
Does anyone want to have a discussion, without hijacking the thread, about the *Science* of this?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.