6

Hi I am trying to compile simple C programs in my computer and I get the similar msgs from under the terminal [see images] when compiling, stating some sort of assembly error. I dont know if this is a computer memory/stack issue (although I have restarted my computer) or anything else, but what I know for sure is that I have been compiling C programs these past days in the same manner.

Code:

   #include <stdio.h>
   main(){
      printf("hello");
   }

Output:

/tmp/cconajAc.s: Assembler messages: /tmp/cconajAc.s:9: Error: suffix or operands invalid for `push'

Please tell me how to fix this!

EDITED: I have just changed from workstation from another computer lab room and it works alright with no assembly errors whatsoever. My guess would be an error in the development tools installed in those computers in the other lab room. I guess for now this works for me although it would be interesting to know the source of the problem that I had in the other computer.

Ini
  • 61
  • 4
  • 1
    What is your command line for compiling? – William Morris Nov 04 '12 at 22:22
  • 1
    Try `gcc -m32 -o test test.c` – Anirudh Ramanathan Nov 04 '12 at 22:24
  • 1
    Done, exact same error happens :( – Ini Nov 04 '12 at 22:24
  • 1
    From what I am reading, it appears that you were able to compile and run simple C language programs a day or two ago and now suddenly when you try to compile and run simple C language programs, you are now getting this error? What has changed between then and now? – Richard Chambers Nov 04 '12 at 22:27
  • 1
    whats the output of `uname -a` and `gcc -v`. Please add this (output of these commands) to your question above. – rubber boots Nov 04 '12 at 22:28
  • What happens if you do: `gcc -c -o test.o test.c` and then `gcc -o test test.o` – William Morris Nov 04 '12 at 22:28
  • I am using another computer that runs the same version of linux, running on the same network, also tried in a third computer with same properties and different user id's (these computers are on a lab of a university).. – Ini Nov 04 '12 at 22:30
  • gcc -c -o test.o test.c gives the same as gcc -o test test.o and the same as gcc -m32 -o test test.c which is: /tmp/ccENf6XV.s: Assembler messages: /tmp/ccENf6XV.s:9: Error: suffix or operands invalid for `push' – Ini Nov 04 '12 at 22:33
  • This is not relevant to your problem, but `main()` should be `int main(void)`. – Keith Thompson Aug 20 '14 at 00:50

5 Answers5

1

The error seems strange but try adding a return type to your main(): int main().

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85
1

Write in vi editor and save the file as "hello.c":

 #include <stdio.h>
 int main() {   printf("hello");   return 0; }

Check if you have the 32-bit glibc headers installed.
Try this in ubuntu to install:
# apt-get install gcc-multilib

Then try:
# gcc -m32 -o hello hello.c

# gcc Wa,--32 else

# gcc -m32 --32

askmish
  • 6,464
  • 23
  • 42
0

In case it helps anyone else, for me, this appears to be caused by mismatched toolchain components -- I sometimes have to source external dotfiles that modify my PATH (in order to satisfy a convoluted build system, sigh). The assembler was /usr/bin/as, but gcc was some ancient version.

jjlin
  • 4,462
  • 1
  • 30
  • 23
0

Error: suffix or operands invalid for `push'

Check your sys's architecture:

# arch
x86_64   

# arch
i386

Or use this:

#uname -m 
x86_64

In assembly: 32bit(i386):

pushl instruction  ;notice the suffix is l

64bit(x86_64):

pushq instruction  ;notice the suffix is q

I wonder your sys's arch is x86_64, It will raise this error when you use 32bit's instruction. To solve this problem:

#gcc -m32 -o test test.c

Refer to When should -m32 option of gcc be used?

Community
  • 1
  • 1
sinceq
  • 844
  • 8
  • 12
0

which shell are you in while running gcc ?

Try switching to tcsh/csh. i was getting same error in bash and switched shell to tcsh.

aks
  • 304
  • 3
  • 8