Take the 2-minute tour ×

I have this c++ code:

#include <iostream>
using namespace std;

int main () {

  char chr[] = "111111111111";
  int pop = 9999;
  cout << chr << (pop+1) << endl;


when I do in the shell (64 bit linux) g++ -S hello.cpp I get assembly code :

when I use on it nasm hello.s it says it contains a lot of errors such as:

instruction needed
expression syntax error
symbol `popq' redefined

maybe it is because it is 64bit? how can I compile the .s I created with the g++?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

The assembler generated by GCC is using what is known as AT&T syntax, which differs from the Intel-syntax used by nasm. You have to use the GCC assembler (as) to compile GCC generated assembler files.

See e.g. http://en.wikipedia.org/wiki/GNU_Assembler#Criticism.

For more information about the GNU assembler syntax, see http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax.

share|improve this answer
add comment

There are several assembler syntaxes for x86. In particular, nasm and gas (the assembler inside binutils) have different syntaxes.

Very often, GCC is configured to emit assembly code using gas syntax. You could find out what GCC is doing with eg g++ -O -v -c yourcode.cc and you can learn how GCC was configured with gcc -v or g++ -v alone.

And you might invoke GCC as g++ -S -fverbose-asm yourcode.cc to get a more readable yourcode.s

share|improve this answer
add comment

Your Answer


