免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8426 | 回复: 8
打印 上一主题 下一主题

汇编语言中的#define #include #ifdef 等问题 [复制链接]

Caballeroo 该用户已被删除
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-22 22:41 |只看该作者 |倒序浏览
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
2 [报告]
发表于 2008-07-23 08:50 |只看该作者
都是預處理指令,只要編譯器支持就可以了
Caballeroo 该用户已被删除
3 [报告]
发表于 2008-07-23 09:06 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
4 [报告]
发表于 2008-07-23 09:46 |只看该作者

回复 #3 Caballeroo 的帖子

樓主研究的好仔細,我一直都是能編譯可以用就行了的...
Caballeroo 该用户已被删除
5 [报告]
发表于 2008-07-23 12:19 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
Caballeroo 该用户已被删除
6 [报告]
发表于 2008-07-23 16:40 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
7 [报告]
发表于 2008-07-23 18:44 |只看该作者

论坛徽章:
0
8 [报告]
发表于 2008-07-23 22:00 |只看该作者

回复 #7 迷失的人 的帖子

文章寫得很好,我給貼過來了
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"
Caballeroo 该用户已被删除
9 [报告]
发表于 2008-07-23 22:39 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP