汇编语言中的#define #include #ifdef 等问题
2014-05-22 21:04
239 查看
文章寫得很好,我給貼過來了 引用: 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"
相关文章推荐
- 汇编语言中出现#include, #define的问题
- 数据处理的两个基本问题04 - 零基础入门学习汇编语言41
- 汇编语言复习摘要八——数据处理的两个基本问题
- 汇编语言的码制转换小问题--求指教
- IAR C语言嵌入汇编问题
- 汇编语言 王爽 实验十 解决除法溢出问题
- 开始学习汇编语言了,搞定在XP下安装visual PC的问题!(重要转帖)
- 汇编语言的过程调用的几个问题
- stc11f16xe 单片机汇编语言编写遇到的一些问题
- 汇编语言中使用有符号数还是无符号数问题
- 数据处理的两个基本问题02 - 零基础入门学习汇编语言39
- <学习笔记>王爽汇编语言__处理数据的两个基本问题
- 王爽_汇编语言 段中的实际数据大小与占用空间大小问题
- 王爽 汇编语言第二版 问题 7.9
- 数据处理的两个基本问题05 - 零基础入门学习汇编语言42
- 数据处理的两个基本问题01 - 零基础入门学习汇编语言38
- 汇编语言中使用有符号数还是无符号数问题
- 数据处理的两个基本问题03 - 零基础入门学习汇编语言40
- 汇编语言笔记08-数据处理的两个基本问题(阶段总结)
- 汇编语言编程问题