LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-05-2010, 10:42 AM   #16
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled

Hi, guys -

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:

http://www.ibm.com/developerworks/library/l-ia.html

Last edited by paulsm4; 07-05-2010 at 10:43 AM.
 
Old 07-05-2010, 11:54 AM   #17
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by paulsm4 View Post
1. I happened to use g++ (not gcc per se). G++ v4.1.2. The latest/greatest with CentOS 5.4:
Did you link the program and/or turn on warnings?

Quote:
2. Yes, Gnu C/C++ inline assembler can access C/C++ local variables by name:
http://www.ibm.com/developerworks/library/l-ia.html
Yes, but not in the way you showed.

Code:
% 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
 
Old 07-07-2010, 02:20 AM   #18
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
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?
 
Old 07-07-2010, 04:10 AM   #19
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Rep: Reputation: 41
I have read C is a high-level assembly, yes...
A portable assembly.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to give inline comment at variable declaration in Makefile w/o including space..? mayankmehta83 Linux - Newbie 6 12-07-2009 04:33 AM
Gcc Assembler And Link eichmen Programming 4 04-17-2007 07:14 AM
Problem with variable in inline assembler DavidW567 Programming 0 05-17-2005 11:21 AM
Compiling inline assembler DavidW567 Programming 3 03-07-2005 08:59 AM
inline assembly in gcc gursev Programming 2 03-04-2005 02:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration