Page 1 of 1

C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 4:01 am
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:

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 4:25 am
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.

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 4:31 am
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.

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 4:51 am
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?

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 4:55 am
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.

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 4:59 am
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)

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 5:47 am
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.

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 7:33 am
by Owen
...Until you want to place said assembly in a C++ name mangled function, or template member function.

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 7:44 am
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...

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 2:06 pm
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.

Re: C/C++ with inline nasm?

Posted: Thu Jul 07, 2011 3:04 pm
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.

Re: C/C++ with inline nasm?

Posted: Mon Jul 11, 2011 10:54 am
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.