linux-assembly.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Plantz <plantz@sonoma.edu>
To: Kenton Brede <kbrede@gmail.com>
Cc: linux-assembly@vger.kernel.org
Subject: Re: suffix or operands invalid for
Date: Fri, 22 Dec 2006 08:16:21 -0800	[thread overview]
Message-ID: <1166804181.4573.20.camel@localhost> (raw)
In-Reply-To: <d5418ffc0612220618ra72b5dfpcca0312c356b45ce@mail.gmail.com>

On Fri, 2006-12-22 at 08:18 -0600, Kenton Brede wrote:
> On 12/22/06, Frank Kotler <fbkotler@verizon.net> wrote:
> 
> At any rate I tried:
> 
> $ as --32 power.s -o power.o
> 
> $ ld power.o -o power
> 

First, at this point, if you do
    gcc -m32 power.o -o power
gcc will go directly to the ld phase (since it can tell that power.o is
already compiled/assembled). But the big advantage is that gcc will
automatically link in any C libraries needed to run your code. That is,
it links in all the set up stuff so you can start your programs with a
"main" function.

Then "main" functions will need to do:
           .globl  main
main:      pushl   %ebp        # save caller's base pointer
           movl    %esp, %ebp  # establish our base pointer
        # add to %esp for local vars here
        # save registers used in this function
        # now your code goes here
        # restore registers
           movl    $0, %eax    # return 0; for our shell
           movl    %ebp, %esp  # get rid of local var space on stack
           popl    %ebp        # for our caller
           ret
You can see how gcc does this by writing a main function in C, then
doing
       gcc -m32 -S foo.c
The "-S" (yes, that's upper case S) produces foo.s, which is gcc's
assembly language version of foo.c. You will lots of messing around with
the stack pointer beyond what I've shown above. I think that's to keep
the stack pointer on "nice" addressing boundaries. But what I've shown
above gets the job done while learning this stuff.

Next, I don't know what distro you're running. I run both Ubuntu Edgy
and Debian Etch. On these distros I needed to install the libc6-dev-i386
package. I also have ia32-libs and libc6-i386 installed.

Before I installed libc6-dev-i386, the error message I got when I
invoked the link stage (using gcc as above) was
   bob@debian:~$ gcc -m32 yes_no2.o -o yes_noxx
   /usr/bin/ld: skipping incompatible /usr/bin/../lib/libc.so when
searching for -lc
   /usr/bin/ld: skipping incompatible /usr/bin/../lib/libc.a when
searching for -lc/usr/bin/ld: skipping incompatible /usr/lib/libc.so
when searching for -lc
   /usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for
-lc
   /usr/bin/ld: cannot find -lc
   collect2: ld returned 1 exit status
   bob@debian:~$ gcc -m32 yes_no2.o -o yes_noxx

(Sorry for the word wrapping here; hope you can read it.)


On earlier Unbuntu releases, I think the required things were in
different packages, but I'm not sure.

Bob




  reply	other threads:[~2006-12-22 16:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-22  2:39 suffix or operands invalid for Kenton Brede
2006-12-22 12:51 ` Frank Kotler
2006-12-22 14:18   ` Kenton Brede
2006-12-22 16:16     ` Robert Plantz [this message]
2006-12-22 16:55       ` Robert Plantz
2006-12-22 19:05         ` Kenton Brede
2006-12-22 19:15           ` Robert Plantz
2006-12-31 18:06     ` Hendrik Visage

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1166804181.4573.20.camel@localhost \
    --to=plantz@sonoma.edu \
    --cc=kbrede@gmail.com \
    --cc=linux-assembly@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).