C/C++ with inline nasm?

Programming, for all ages and all languages.
Post Reply
Developer30
Posts: 1
Joined: Thu Jul 07, 2011 3:49 am

C/C++ with inline nasm?

Post by Developer30 »

Hello Community,

at first, sorry for my bad english. As the headline says, I'd like to work with nasm in C/C++ to develop my own os. The reason of this is because I'm a total asm beginner, but I've got some experience in C++, so it would be easier for me to combine C++ with NASM.
Does someone know a C/C++ compiler that supports inline NASM?

I hope for your help [-o< ,

Developer30 :mrgreen:
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: C/C++ with inline nasm?

Post by OSwhatever »

The common C++ compilers support their own native version of inline assembler which are different among most compilers. I've not heard of any that supports NASM specific syntax.

I suggest you read the documentation of your chosen compiler in order to find out about inline assembler.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: C/C++ with inline nasm?

Post by JamesM »

reason of this is because I'm a total asm beginner,
The difference between intel and AT&T syntax isn't huge - I suggest you learn AT&T syntax.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: C/C++ with inline nasm?

Post by OSwhatever »

JamesM wrote:
reason of this is because I'm a total asm beginner,
The difference between intel and AT&T syntax isn't huge - I suggest you learn AT&T syntax.
Isn't there a GCC option where you can change the syntax to Intel?

AT&T syntax should be considered as torture these days. Are we really going to put beginners through that?
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: C/C++ with inline nasm?

Post by XanClic »

Yes, there is an option for gcc, namely “-masm=intel”. It's still slightly different from NASM syntax, but that difference is not too big.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: C/C++ with inline nasm?

Post by Solar »

OSwhatever wrote:AT&T syntax should be considered as torture these days.
Very much depends on when and where you learned ASM. I learned on a C64 assembler, the name of which I have long forgotten (we only called it "sys49152" as that was its start address), and I always found AT&T highly intuitive - and Intel syntax as "bass-ackwards".

Another thing where the "Big Corps" have screwed the perception of the masses... 8)
Every good solution is obvious once you've found it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: C/C++ with inline nasm?

Post by Solar »

berkus wrote:Use out-of-line NASM for start, it is easier.
From a system architecture POV, this is very good advice. Out-of-line assembler is easier to identify, easier to refactor, easier to... everything.
Every good solution is obvious once you've found it.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: C/C++ with inline nasm?

Post by Owen »

...Until you want to place said assembly in a C++ name mangled function, or template member function.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: C/C++ with inline nasm?

Post by Solar »

One, I don't see why you'd want to do that. Two, you can call an extern "C" assembler function from within a C++-mangled or templated function just fine...
Every good solution is obvious once you've found it.
User avatar
Neolander
Member
Member
Posts: 228
Joined: Tue Mar 23, 2010 3:01 pm
Location: Uppsala, Sweden
Contact:

Re: C/C++ with inline nasm?

Post by Neolander »

OSwhatever wrote:AT&T syntax should be considered as torture these days. Are we really going to put beginners through that?
Depends what you're used to, I guess. I've never really grown very proficient with either syntax (every assembly snippet in my OS has been a tiny nightmare on its own), but AT&T sounds more familiar to me, closer to natural language. In everyday life, I talk about moving something from a source to a destination, not to a destination from a source. Maybe it's due to me being French, and a native English speaker would rather use the latter, but to me it just sounds weird to put the end of a journey before its beginning in a sentence, except for intellectual masturbation or poetry purposes.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: C/C++ with inline nasm?

Post by JamesM »

Neolander wrote:
OSwhatever wrote:AT&T syntax should be considered as torture these days. Are we really going to put beginners through that?
Depends what you're used to, I guess. I've never really grown very proficient with either syntax (every assembly snippet in my OS has been a tiny nightmare on its own), but AT&T sounds more familiar to me, closer to natural language. In everyday life, I talk about moving something from a source to a destination, not to a destination from a source. Maybe it's due to me being French, and a native English speaker would rather use the latter, but to me it just sounds weird to put the end of a journey before its beginning in a sentence, except for intellectual masturbation or poetry purposes.
Blah blah blah holy war blah blah.

They're assembler syntaxes. Get over it. It's not like a paradigm shift of C versus Haskell or something.
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: C/C++ with inline nasm?

Post by Ready4Dis »

Neolander wrote:
OSwhatever wrote:AT&T syntax should be considered as torture these days. Are we really going to put beginners through that?
Depends what you're used to, I guess. I've never really grown very proficient with either syntax (every assembly snippet in my OS has been a tiny nightmare on its own), but AT&T sounds more familiar to me, closer to natural language. In everyday life, I talk about moving something from a source to a destination, not to a destination from a source. Maybe it's due to me being French, and a native English speaker would rather use the latter, but to me it just sounds weird to put the end of a journey before its beginning in a sentence, except for intellectual masturbation or poetry purposes.
Natural for some I presume. If you think about it, in C/C++, you do X = Y; X being dest, Y being source. Why does that seem natural in that context, yet backwards in another (asm). It really just depends on the person, nobody is right or wrong, just depends on how you view it.
Post Reply