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 08-02-2005, 03:26 AM   #1
bigapple
LQ Newbie
 
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Rep: Reputation: 15
Assembler Enbedded C Program


hi, all
I have seen some code like this:
Code:
asm volatile (							      \
    LOADARGS_##nr							      \
    "movl %1, %%eax\n\t"						      \
    "int _0x81\n\t"							      \
    RESTOREARGS_##nr							      \
    : "=a" (resultvar)							      \
    : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc");		      \
    if (resultvar >= 0xfffff001)					      \
      {									      \
	errno= (-resultvar);					      \
	resultvar = 0xffffffff;						      \
      }									      \
    (int) resultvar; })
I konw there is some assembler language embedded in this program,and the key words "asm volatile" tell the compiler "following is assembler language", So I want to konw ,if I want to compile such kind of C program, which argument should be add in gcc command.
if anyone have the experience of write/compile such kind of program,please give me a simple demo,and show the procedure of how to compile it and run it. It will be very helpful to me ,thnx a lot. and you can give a link to a web site
 
Old 08-02-2005, 12:08 PM   #2
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
What happens when you just try and run the compiler with default arguments?

gcc -o program program.c
 
Old 08-02-2005, 09:50 PM   #3
bigapple
LQ Newbie
 
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Original Poster
Rep: Reputation: 15
ok ,I see,the reason that I can't compile the program is my gcc version is 2.9. and it can't compile the assembler embedded C program, so I have update the gcc to newest,and I can compile the program successful with the default arguments.
if you want to use the "asm" as a varible in you program ,you should use '-fno-asm' following your gcc command.
 
Old 08-02-2005, 10:41 PM   #4
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
Cool, so did it work?

Code:
gcc -fno-asm -o progam program.c
I'm curious for my own purposes. I'll check out the gcc inline assembly docs when I get time, but I'm just wondering whether that command would work.

- lowpro2k3

Last edited by lowpro2k3; 08-02-2005 at 10:43 PM.
 
Old 08-03-2005, 12:03 AM   #5
bigapple
LQ Newbie
 
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Original Poster
Rep: Reputation: 15
No, you needn't add the argument '-fno-asm' when you compile the program, just simply use "gcc -o program program.c" to compile you program which contians the inline assembly. you gcc compile can recognize the key word "asm",and understand the following Assembler Language.
And if you has define a varible such as "int asm = 4", then you should use the argument "-fno-asm" to force the gcc compiler ignore the key word "asm",just recognize the "asm" as a normal varible. Do you catch my mean?
for more information you can use 'man gcc'
 
  


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
Assembler samjkd General 7 03-14-2005 01:52 PM
Assembler Firari Programming 9 12-10-2004 02:26 PM
assembler usr Programming 2 11-15-2003 05:15 PM
assembler tda Programming 4 08-21-2002 02:54 AM
Need an Assembler ChimpFace9000 Programming 1 07-18-2001 09:36 PM

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

All times are GMT -5. The time now is 11:19 AM.

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