This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Using GAS, any tutorials




Robert Floyd wrote:
> 
> > > The tools I have used before always tell you how to begin your
> > > program, what directives need to be there and why, and additional
> > > "configuration" info to embed into the program that really has nothing
> > > to do with the actual code itself.
> >
> > this varies from target to target...  gas was meant to be a drop-in
> > replacement for many system assemblers, and as such it accepts a wide
> > variety of syntaxes.  if you can find a manual for one of them, it'll
> > probably be applicable to gas.  (of course nobody seems to know where to
> > find one...)
> 
> So I can only conclude that there is no other way for me to begin but to
> get a basic example (my target is going to be a Hitachi SH7032), pick it
> apart, attempt to copy the basics for my own chip but create a very
> simple program such as send characters out the serial port, and see if
> it works.  I just find it amazing how anyone ever gets anything done, or
> maybe that is why so many software projects take three times longer than
> management schedules for. ;-)

There are a handful of side-issues you might want to consider.  In
general,
you should limit the amount of assembly language you write anyway. 
There
is no reason to write serial drivers in assembly language.  The better
approach
is to use C and drop to inline assembly when absolutely necessary.

I would bet that like myself, most folks using the GNU tools only use 
assembly language for startup code and other places where they
absolutely
have to.

On embedded CPUs, GAS tends to follow the assembly language as defined
in the CPU manufacturer's programming manual.  For CPUs from the UNIX
world, there is a tendency to use the native UNIX format, even when this
is painful (the x86 comes to mind, since its operands are reversed from
Intel).  

This does not address directives.  They are generally documented in
the GAS manual.  I very seldom look there first.  My first approach
to getting the structure for an assembly file is to compile a simple
C file and look at the produced assembly.  Compiling a file like
this can tell you a lot.

int my_global_var;

int function()
{
  return 0;
}

This will show you the structure of an assembly file, code versus
data sections, how to declare a variable, function declaration, etc.
This is what I have done regardless of toolset -- the compiler
knows more than you do. :)

> I am not sure I understand your statement "if you can find a manual for
> one of them, it'll probably be applicable to gas."  GNU AS I thought
> must have consistent placement of directives and would not vary
> according to the target since it is an assembler with its own oddities.
> I just don't find all the "rules" for GNU AS laid out clearly anywhere.
> It just appears to be the school of hard knocks all the way.  I guess I
> am spoiled by all the commercial assemblers for motorola, intel I have
> bought in the past.

As I said earlier, GNU AS is generally trying to be compatible with the
assembly language as defined in the architecture manual.  Sometimes
this includes compatability with manufacturer assemblers, sometimes it
does not.  There are no 100% consistent rules for pseudo-directives
because of this.  

If you want examples, look at the RTEMS source.  You can probably 
find anything you want in there including full support for the SH7032.
Why bother with that serial driver or startup code? :)
 
> R.Floyd
> 
> "Aaron J. Grier" wrote:
> >
> > On Thu, Oct 19, 2000 at 10:27:58AM -0500, Robert Floyd wrote:
> > > I understand the difference in assembly mnemonic and I have written
> > > numerous assembly language programs for consumer products.  I am lost
> > > however with GNU in that there is no documentation available which
> > > tells one how to set up directives for the assembler.
> >
> > section 7 of the as infopages / manual is full of assembler directives.
> > almost all of them are available on every target.
> >
> > > The tools I have used before always tell you how to begin your
> > > program, what directives need to be there and why, and additional
> > > "configuration" info to embed into the program that really has nothing
> > > to do with the actual code itself.
> >
> > this varies from target to target...  gas was meant to be a drop-in
> > replacement for many system assemblers, and as such it accepts a wide
> > variety of syntaxes.  if you can find a manual for one of them, it'll
> > probably be applicable to gas.  (of course nobody seems to know where to
> > find one...)
> >
> > > Such as all *.s files begin with .file "filename", (do they? The
> > > examples I see do..),
> >
> > not necessary.
> >
> > > immediately after file you put .align "some number", (do you have to
> > > put it there? can I put it later in the program?),
> >
> > not necessary unless your target requires it.  usually the linker
> > handles it.
> >
> > > every file ends with .end (does it?  the example I have does and what
> > > is this .end anyway, GAS does not list .end)
> >
> > not necessary.
> >
> > > These are the types of questions that I have and I don't find
> > > any info available for these types of questions.  Do I need to write
> > > one after basically 6 months of trial and error.
> >
> > something as simple as the following compiles:
> >
> > .text
> > mysubroutine:
> >         addil   #1, somesillyvariable
> >         rts
> >
> > .data
> > somesillyvariable:
> >         .long   0
> >
> > you can get as contorted or keep it as minimal as you like.  relocations
> > and subroutine alignments are handled by the linker.
> >
> > > I understand the principle that "unless it's hard, it can't be good"
> > > Unix mentality, but geezzz!  We can do better in my own humble
> > > opinion.
> >
> > you volunteering to write some docs?  ;)
> >
> > --
> >   Aaron J. Grier   |    Frye Electronics, Tigard, OR   |   aaron@frye.com
> >   "Add [Windows] ME to an old PC with a `mere' 32 MB of memory, and your
> >    hard disk will be busier than a one-armed man juggling knives."
> >     --  Winn L. Rosch
> 
> ------
> Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel@OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]