GNU arm 汇编伪指令详解

电子说

1.3w人已加入

描述

所有的伪指令都是以 . 开头命令,然后剩下的命名通常是小写字母,比如 .section   .type

.section

格式:.section name [, "flags "[, %type [,flag_specific_arguments ]]]

flags: 

The optional flags argument is a quoted string which may contain any combination of the following characters:

a section is allocatable
w section is writable
x section is executable
M section is mergeable
S section contains zero terminated strings
G section is a member of a section group
T section is used for thread-local-storage

type:

The optional type argument may contain one of the following constants:

progbits: section contains data

nobits: section does not contain data (i.e., section only occupies space)

note: section contains data which is used by things other than the program

init_array: section contains an array of pointers to init functions

fini_array: section contains an array of pointers to finish functions

preinit_array: section contains an array of pointers to pre-init functions

 

实例:

.section .stack, "aw", %nobits /* 命名一个”.stack"段, 该段具有可分配和可写属性,该段不包含数据,该段用于保存堆栈值 */

.size

格式: .size name , expression

This directive sets the size associated with a symbol name. The size in bytes is computed from expression which can make use of label arithmetic. This directive is typically used to set the size of function symbols.

.type

This directive is used to set the type of a symbol.

格式有多种形式,如下:

.type   STT_
.type   ,#
.type  ,@
.type  ,@
.type ,%
.type ,""

The types supported are:

STT_FUNC

function

Mark the symbol as being a function name.

STT_GNU_IFUNC

gnu_indirect_function 

Mark the symbol as an indirect function when evaluated during reloc processing.
(This is only supported on Linux targeted assemblers).

STT_OBJECT

object

Mark the symbol as being a data object.

STT_TLS

tls_object

Mark the symbol as being a thead-local data object.

STT_COMMON

common

Mark the symbol as being a common data object.

STT_NOTYPE

notype

Does not mark the symbol in any way. It is supported just for completeness.

例子1

.section  .text.Reset_Handler
.type  Reset_Handler, %function Reset_Handler:  

  ldr   sp, =_estack     /* set stack pointer */

  bl  entry

  bx  lr   

  .size  Reset_Handler, .-Reset_Handler

例子2

.section  .text.Reset_Handler
.type  Reset_Handler, STT_FUNC Reset_Handler:  

ldr   sp, =_estack     /* set stack pointer */  

bl  entry

bx  lr    

.size  Reset_Handler, .-Reset_Handler

例子3

.global  g_pfnVectors .section

.isr_vector,"a",%progbits

.type  g_pfnVectors, %object    ;声明一个 object 对象

.size  g_pfnVectors, .-g_pfnVectors        

g_pfnVectors:  .word  _estack  

                       .word  Reset_Handler  

                       .word  NMI_Handler  

                       .word  HardFault_Handler  

                       .word  MemManage_Handler  

                       .word  BusFault_Handler  

                       .word  UsageFault_Handler

.global

.global makes the symbol visible to ld. If you define symbol in your partial program, its value is made available to other partial programs that are linked with it. Otherwise, symbol takes its attributes from a symbol of the same name from another file linked into the same program.

.global 用于声明全局变量,是其让ld可见。

.word

在当前地址放一个 32bit 的值

g_pfnVectors:  .word  _estack

                       .word  Reset_Handler  

                       .word  NMI_Handler  

                       .word  HardFault_Handler

上面的代码表示,在连续相连的地址上,依次放各中断服务函数指针

审核编辑:符乾江

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
评论(0)
发评论
罗煜正 04-23
0 回复 举报
例子3里为啥.size可以写在中断向量表上面 收起回复
罗煜正 04-23
0 回复 举报
例子3中的.size为什么能放在中断向量表是上面 收起回复

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分