gnu assembler最新官方手册和.macro介绍

最新手册 

Top (Using as)Top (Using as)https://sourceware.org/binutils/docs/as/index.html2.38  版本

https://sourceware.org/binutils/docs-2.38/as.pdf


伪指令 .macro 定义,macro可以嵌套,在开源代码中大量使用,需重点关注,官方描述如下

The commands .macro and .endm allow you to define macros that generate assembly output. For example, this definition specifies a macro sum that puts a sequence of numbers into memory:

        .macro  sum from=0, to=5
        .long   \from
        .if     \to-\from
        sum     "(\from+1)",\to
        .endif
        .endm

With that definition, ‘SUM 0,5’ is equivalent to this assembly input:

        .long   0
        .long   1
        .long   2
        .long   3
        .long   4
        .long   5

.macro macname ¶

.macro macname macargs … ¶

Begin the definition of a macro called macname. If your macro definition requires arguments, specify their names after the macro name, separated by commas or spaces. You can qualify the macro argument to indicate whether all invocations must specify a non-blank value (through ‘:req’), or whether it takes all of the remaining arguments (through ‘:vararg’). You can supply a default value for any macro argument by following the name with ‘=deflt’. You cannot define two macros with the same macname unless it has been subject to the .purgem directive (see .purgem name) between the two definitions. For example, these are all valid .macro statements:

.macro comm

Begin the definition of a macro called comm, which takes no arguments.

.macro plus1 p, p1

.macro plus1 p p1

Either statement begins the definition of a macro called plus1, which takes two arguments; within the macro definition, write ‘\p’ or ‘\p1’ to evaluate the arguments.

.macro reserve_str p1=0 p2

Begin the definition of a macro called reserve_str, with two arguments. The first argument has a default value, but not the second. After the definition is complete, you can call the macro either as ‘reserve_str a,b’ (with ‘\p1’ evaluating to a and ‘\p2’ evaluating to b), or as ‘reserve_str ,b’ (with ‘\p1’ evaluating as the default, in this case ‘0’, and ‘\p2’ evaluating to b).

.macro m p1:req, p2=0, p3:vararg

Begin the definition of a macro called m, with at least three arguments. The first argument must always have a value specified, but not the second, which instead has a default value. The third formal will get assigned all remaining arguments specified at invocation time.

When you call a macro, you can specify the argument values either by position, or by keyword. For example, ‘sum 9,17’ is equivalent to ‘sum to=17, from=9’.

Note that since each of the macargs can be an identifier exactly as any other one permitted by the target architecture, there may be occasional problems if the target hand-crafts special meanings to certain characters when they occur in a special position. For example, if the colon (:) is generally permitted to be part of a symbol name, but the architecture specific code special-cases it when occurring as the final character of a symbol (to denote a label), then the macro parameter replacement code will have no way of knowing that and consider the whole construct (including the colon) an identifier, and check only this identifier for being the subject to parameter substitution. So for example this macro definition:

	.macro label l
\l:
	.endm

might not work as expected. Invoking ‘label foo’ might not create a label called ‘foo’ but instead just insert the text ‘\l:’ into the assembler source, probably generating an error about an unrecognised identifier.

Similarly problems might occur with the period character (‘.’) which is often allowed inside opcode names (and hence identifier names). So for example constructing a macro to build an opcode from a base name and a length specifier like this:

	.macro opcode base length
        \base.\length
	.endm

and invoking it as ‘opcode store l’ will not create a ‘store.l’ instruction but instead generate some kind of error as the assembler tries to interpret the text ‘\base.\length’.

There are several possible ways around this problem:

Insert white space

If it is possible to use white space characters then this is the simplest solution. eg:

	.macro label l
\l :
	.endm

Use ‘\()’,The string ‘\()’ can be used to separate the end of a macro argument from the following text. eg:------------开源代码中大量使用,包括固件,内核,出处均来源于此

	.macro opcode base length
        \base\().\length
	.endm

Use the alternate macro syntax mode

In the alternative macro syntax mode the ampersand character (‘&’) can be used as a separator. eg:-----------------&作为分隔符

	.altmacro
	.macro label l
l&:
	.endm

Note: this problem of correctly identifying string parameters to pseudo ops also applies to the identifiers used in .irp (see .irp symbol,values…) and .irpc (see .irpc symbol,values…) as well.

Another issue can occur with the actual arguments passed during macro invocation: Multiple arguments can be separated by blanks or commas. To have arguments actually contain blanks or commas (or potentially other non-alpha- numeric characters), individual arguments will need to be enclosed in either parentheses (), square brackets [], or double quote " characters. The latter may be the only viable option in certain situations, as only double quotes are actually stripped while establishing arguments. It may be important to be aware of two escaping models used when processing such quoted argument strings: For one two adjacent double quotes represent a single double quote in the resulting argument, going along the lines of the stripping of the enclosing quotes. But then double quotes can also be escaped by a backslash \, but this backslash will not be retained in the resulting actual argument as then seen / used while expanding the macro.

As a consequence to the first of these escaping mechanisms two string literals intended to be representing separate macro arguments need to be separated by white space (or, better yet, by a comma). To state it differently, such adjacent string literals - even if separated only by a blank - will not be concatenated when determining macro arguments, even if they’re only separated by white space. This is unlike certain other pseudo ops, e.g. .ascii.

.endm 

Mark the end of a macro definition.

.exitm 

Exit early from the current macro definition.

\@ 

as maintains a counter of how many macros it has executed in this pseudo-variable; you can copy that number to your output with ‘\@’, but only within a macro definition.

LOCAL name [ , … ] ¶

Warning: LOCAL is only available if you select “alternate macro syntax” with ‘--alternate’ or .altmacro. See .altmacro.

arm 有用常用伪指令网址介绍

Useful assembler directives and macros for the GNU assembler - Architectures and Processors blog - Arm Community blogs - Arm Community

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GUN make 中文手册 译者:徐海兵 2004-09-11 3.5.6 库文件和搜索目录 .................................................................................................... 36 3.6 Makefile伪目标.............................................................................................................. 37 3.7 强制目标(没有命令或依赖的规则) ............................................................................. 40 3.8 空目标文件..................................................................................................................... 41 3.9 Makefile的特殊目标....................................................................................................... 41 3.10 多目标............................................................................................................................ 44 3.11 多规则目标..................................................................................................................... 44 3.12 静态模式 ........................................................................................................................ 45 3.12.1 静态模式规则的语法 ....................................................................................... 45 3.12.2 静态模式和隐含规则 ....................................................................................... 47 3.13 双冒号规则..................................................................................................................... 48 3.14 自动产生依赖 ................................................................................................................. 49 第四章:规则的命令 .................................................................................................................. 51 4 规则中书写命令 ................................................................................................................... 51 4.1 命令回显 ........................................................................................................................ 51 4.2 命令的执行..................................................................................................................... 52 4.3 并发执行命令 ................................................................................................................. 53 4.4 命令执行的错误.............................................................................................................. 54 4.5 中断make的执行............................................................................................................ 56 4.6 make的递归执行............................................................................................................ 56 4.6.1 变量MAKE ............................................................................................................... 57 4.6.2 变量和递归 ............................................................................................................... 58 4.6.3 命令行选项和递归 .................................................................................................... 61 4.6.4 -w选项...................................................................................................................... 63 4.7 定义命令包..................................................................................................................... 63 4.8 空命令............................................................................................................................ 65 第五章:Makefile中的变量......................................................................................................... 65 5 使用变量 .............................................................................................................................. 65 5.1 变量的引用..................................................................................................................... 66 5.2 两种变量定义(赋值)................................................................................................... 68 5.2.1 递归展开式变量........................................................................................................ 68 5.2.2 直接展开式变量........................................................................................................ 69 5.2.3 如何定义一个空格 .................................................................................................... 70 5.2.4 “?=”操作符 ............................................................................................................. 71 5.3 变量的高级用法.............................................................................................................. 71 5.3.1 变量的替换引用........................................................................................................ 72 5.3.2 变量的套嵌引用........................................................................................................ 72 5.4 变量取值 ........................................................................................................................ 76 5.5 如何设置变量 ................................................................................................................. 76 5.6 追加变量值..................................................................................................................... 77 5.7 override 指示符 ............................................................................................................. 79 5.8 多行定义 ........................................................................................................................ 80 5.9 系统环境变量 ................................................................................................................. 81 5.10 目标指定变量 ................................................................................................................. 83 5.11 模式指定变量 ................................................................................................................. 84 第六章:Makefile的条件执行 ..................................................................................................... 85 6 Makefile的条件判断 ............................................................................................................. 85 6.1 一个例子 ........................................................................................................................ 85 6.2 条件判断的基本语法 ...................................................................................................... 86 2004年9月11日 3GUN make 中文手册 6.3 标记测试的条件语句 ...................................................................................................... 89 第七章:make的内嵌函数.......................................................................................................... 89 7 make的函数 ......................................................................................................................... 89 7.1 函数的调用语法.............................................................................................................. 90 7.2 文本处理函数 ................................................................................................................. 91 7.2.1 $(subst FROM,TO,TEXT) ....................................................................................... 91 7.2.2 $(patsubst PATTERN,REPLACEMENT,TEXT) ..................................................... 91 7.2.3 $(strip STRINT)....................................................................................................... 92 7.2.4 $(findstring FIND,IN) .............................................................................................. 92 7.2.5 $(filter PATTERN...,TEXT) ..................................................................................... 93 7.2.6 $(filter-out PATTERN...,TEXT) ............................................................................... 93 7.2.7 $(sort LIST) ............................................................................................................. 94 7.2.8 $(word N,TEXT) ...................................................................................................... 94 7.2.9 $(wordlist S,E,TEXT).............................................................................................. 94 7.2.10 $(words TEXT) .............................................................................................. 94 7.2.11 $(firstword NAMES...) .................................................................................. 95 7.3 文件名处理函数.............................................................................................................. 95 7.3.1 $(dir NAMES...) ...................................................................................................... 95 7.3.2 $(notdir NAMES...)................................................................................................. 96 7.3.3 $(suffix NAMES...) ................................................................................................. 96 7.3.4 $(basename NAMES...) ......................................................................................... 96 7.3.5 $(addsuffix SUFFIX,NAMES...) ............................................................................. 97 7.3.6 $(addprefix PREFIX,NAMES...) ............................................................................. 97 7.3.7 $(join LIST1,LIST2)................................................................................................. 98 7.3.8 $(wildcard PATTERN) ............................................................................................ 98 7.4 foreach 函数................................................................................................................. 98 7.5 if 函数 ......................................................................................................................... 100 7.6 call函数 ....................................................................................................................... 100 7.7 value函数 .................................................................................................................... 102 7.8 eval函数 ...................................................................................................................... 103 7.9 origin函数 ................................................................................................................... 104 7.10 shell函数 ..................................................................................................................... 106 7.11 make的控制函数.......................................................................................................... 106 7.11.1 $(error TEXT...) ........................................................................................... 107 7.11.2 $(warning TEXT...)...................................................................................... 107 第八章:执行make .................................................................................................................. 108 8 执行make .......................................................................................................................... 108 8.1 指定makefile文件 ........................................................................................................ 108 8.2 指定终极目标 ............................................................................................................... 109 8.3 替代命令的执行............................................................................................................ 111 8.4 防止特定文件重建 ........................................................................................................ 112 8.5 替换变量定义 ............................................................................................................... 113 8.6 使用make进行编译测试............................................................................................... 114 8.7 make的命令行选项 ...................................................................................................... 115 第九章:make的隐含规则........................................................................................................ 119 9 使用隐含规则 ..................................................................................................................... 119 9.1 隐含规则的使用............................................................................................................ 119 9.2 make的隐含规则一览 .................................................................................................. 121 9.3 隐含变量 ...................................................................................................................... 124 9.3.1 代表命令的变量...................................................................................................... 124 9.3.2 命令参数的变量...................................................................................................... 125 9.4 make隐含规则链.......................................................................................................... 126 2004年9月11日 4GUN make 中文手册 9.5 模式规则 ...................................................................................................................... 128 9.5.1 模式规则介绍 ......................................................................................................... 128 9.5.2 模式规则示例 ......................................................................................................... 129 9.5.3 自动化变量 ............................................................................................................. 130 9.5.4 模式的匹配 ............................................................................................................. 133 9.5.5 万用规则 ................................................................................................................ 133 9.5.6 重建内嵌隐含规则 .................................................................................................. 134 9.6 缺省规则 ...................................................................................................................... 135 9.7 后缀规则 ...................................................................................................................... 135 9.8 隐含规则搜索算法 ........................................................................................................ 137 第十章:使用make更新静态库文件 ......................................................................................... 138 10 更新静态库文件............................................................................................................ 138 10.1 库成员作为目标............................................................................................................ 138 ARCHIVE(MEMBER) .............................................................................................................. 138 10.2 静态库的更新 ............................................................................................................... 139 10.2.1 更新静态库的符号索引表 .............................................................................. 140 10.3 make静态库的注意事项............................................................................................... 141 10.4 静态库的后缀规则 ........................................................................................................ 141 第十一章 : GNU make的特点............................................................................................... 142 11 GNU make的一些特点 ................................................................................................. 142 11.1 源自System v的特点 ................................................................................................... 142 11.2 源自其他版本的特点 .................................................................................................... 143 11.3 GNU make自身的特点 ................................................................................................. 143 第十二章 和其它版本的兼容 .................................................................................................... 144 12 不兼容性 ...................................................................................................................... 144 第十三章 Makefile的约定 ........................................................................................................ 146 13 书写约定 ...................................................................................................................... 146 13.1 基本的约定................................................................................................................... 146 13.2 规则命令行的约定 ........................................................................................................ 147 13.3 代表命令变量 ............................................................................................................... 149 13.4 安装目录变量 ............................................................................................................... 150 13.5 Makefile的标准目标名 ................................................................................................. 154 13.6 安装命令分类 ............................................................................................................... 159 第十四章 make的常见错误信息............................................................................................... 161 14 make产生的错误信息 .......................................................................................................... 161 附录1:关键字索引................................................................................................................. 163 GNU make可识别的指示符:.............................................................................................. 163 GNU make函数: ............................................................................................................... 164 GNU make的自动化变量..................................................................................................... 165 GNU make环境变量 ............................................................................................................ 166 后序 ......................................................................................................................................... 166

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值