assembly code using GCC

how is it possible to compile programs using embedded assembly language with the "asm" keyword on the linux platform using gcc.
i tried the following options:
1) gcc -x assembler-with-cpp file.cpp
2) gcc -w file.cpp
3) gcc -asm file.cpp

none of these work.
without any switches, it gives a parse error after every function. with the above switches, it fails to recognise the references assigned to the registers using mov .

LVL 1
effectstudiosAsked:
Who is Participating?
 
superschlonzConnect With a Mentor Commented:
0
 
garbouaCommented:
if you file extension ends with an ".s" or .S, gcc will know that it is an assembly and produce your binary.  no "swithches"
0
 
effectstudiosAuthor Commented:
you mean to say that i should rename the same file as:
file.s
???
Won't the compiler complain about a missing .cpp extension then?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
garbouaCommented:
OH NO,
the compiler will accept a preProcessed file, an object file, an assembly file, or a source code.
so ".o" ".i" ".s, .S" ".c" ".cpp" are all acceptable, BUT interperted as they mean.  so when the compiler sees the file.s, it knows it is an assembly lang file.
0
 
newmangCommented:
When you posted your question are you referring to C code with embedded asm statements or are you referring to pure assembly code?
0
 
effectstudiosAuthor Commented:
i am refering to a c program with some assmebly code embedded in it using the "asm" keyword
 
0
 
jmcgOwnerCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: superschlonz {http:#6287898}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.