Re: gcc & assembly coding conventions ??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 10, 2003 at 01:07:25PM -0700, garret.spears wrote:

> Refernce:
> gcc-2.95.3 -m5200 -x assembler led.S

Before you compile an assembly source file, you should decide whether
you want to pass it through the C preprocessor (CPP) or not. If you
decide to use the preprocessor then you should name your source-file
"something.S" (capital "S"); if not, then you should name it
"something.s" (lowcase "s"). Provided that you follow this convention
you don't *have* to specify the source-language explicitly using the
"-x <lang>" option; gcc can figure-it out from the filename
extension. If you don't want to or can't use this naming convention,
then "-x <lang>" is required:

   gcc-2.95.3 -m5200 asmcode.s -o asmcode.o
   gcc-2.95.3 -m5200 -x assembler asmcode.asm -o asmcode.o
   
   
     Compile without passing the source through CPP.

   gcc-2.95.3 -m5200 asmcode1.S -o asmcode1.o
   gcc-2.95.3 -m5200 -x assembler-with-cpp asmcode1.asm -o asmcode1.o

     Pass the source through CPP and then compile.

If you decide to pass your assembly through CPP, then (and only then)
you *can* use all the C preprocessor goodies, like "#define",
"#include", "#ifdef", etc. But remember: these are handled by the
preprocessor *not* the assmebler!

> 
> #DEFINE INIT_SECTION_ASM_OP  // is this a requird line or should ther be
> another?
>

This is neither required nor allowed! First: you're not using
"assembler-with-cpp" so #DEFINE has no sense! Second: Even if you used
it, CPP is CaSe-SeNsItIvE, so it should be "#define" and not "#DEFINE"
 
> // Base addr of internal resources & SIM resources
> MBAR    EQU    0x10000000                // alt I have seen ".set

What you should have said is (observe the dot!):

  MBAR    .EQU    0x10000000 

Which is the same as saying

  #define MBAR 0x10000000

> 
> Should I be using a dot h file for some of this and a dot s file for my
> actual assembly coding?
>

You can use ".h" files (and the respective "#include" directives) only
if you pass your assembly through CPP. You don't *have* to use them,
though!

> Essentially when I did this years
> ago I dedicated a section to defines or equates, a section to data space,
> and a section to code - assembly language.

data section:

 .data

     ... contents of the data-section ...

code section:

 .text

     ... contents of the text-section ...

or if you use an object-format that can support arbitrarily-named
sections:

  .section ".data"

     ... contents of the data-section ...

  .section ".text"

     ... contents of the text-section ...

You don't need a section for the "equ"s since they produce no output!

Hope this helps
/npat

-- 
As for systems that are not like Unix, such as MSDOS, Windows, the
Macintosh, VMS, and MVS, supporting them is usually so much work that
it is better if you don't.
  -- Richard Stallman "GNU Coding Standards"


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux