|
汇编源程序一般用于系统最基本的初始化:初始化堆栈指针、设置页表、操作 ARM的协处理器等。这些初始化工作完成后就可以跳转到C代码main函数中执行。
1、
l
l
l
l
l
下面定义一个"add"的函数,最终返回两个参数的和:
.section .text,“x”
.global add
add:
@ end ofprogram
注意:
l
l
2、
l
l
Symbol的分类:3类(依据标号的生成方式)。
<1>
<2>
<3>
特别说明:局部标号Symbol
l
l
l
l
l
l
l
l
l
例:使用局部符号的例子,一段循环程序
1:
subs r0, r0, #1@每次循环使r0=r0-1
bne 1F
注意:
l
l
l
3、
<1>
.section<section_name>{,”<flags>”}
Starts a new codeor data section. Sections in GNU are called .text, a code section, .data, aninitialized data section, and .bss, an uninitialized datasection.
These sectionshave default flags, and the linker understands the defaultnames(similar directive to the armasm directive AREA).The followingare allowable .sectionflags for ELF format files:
<Flag>
a
w
x
中文解释:
.sectionsection_name [, "flags"[,%type[,flag_specific_arguments]]]
<标志>
a
w
x
例:定义一个“段”
.section.mysection
.align
strtemp:
<2>
l
l
l
l
l
注意:源程序中.bss段应该在.text段之前。
4、
例:定义入口点
.section .data
.section .bss
.section .text
.globl
_start:
5、
格式如下:
.macro宏名 参数名列表
宏体
.endm
例:宏定义
.macro SHIFTLEFTa, b
.if \b< 0
MOV \a, \a, ASR#-\b
.exitm
.endif
MOV \a, \a, LSL#\b
.endm
6、
<1>
<2>
<3>
<4>
<5>
<6>
<7>
7、
l
l
l
l
l
l
l
l
l
别于GNUAS汇编的通用伪操作,下面是ARM特有的伪操作:
.reg,.unreq ,.code ,.thumb ,.thumb_func ,.thumb_set,.ltorg ,.pool
<1>
l
l
l
l
l
l
.string "abcd", "efgh", "hello!"
.asciz "qwer", "sun", "world!"
.ascii "welcome\0"
l
l
<2>
l
l
a.
b.
c.
d.
<3>
l
l
l
l
<4>
.if有多个变种:
.ifdef symbol
.ifcstring1,string2
.ifeq expression
.ifeqsstring1,string2
.ifgeexpression
.ifgt absoluteexpression @判断expression的值是否大于0
.ifle expression
.iflt absoluteexpression
.ifncstring1,string2
.ifndef symbol,.ifnotdef symbol @判断是否没有定义symbol, 跟.ifdef恰好相反
.ifne expression
.ifnesstring1,string2
<5>
l
l
例:
.globla
.data
.align4
.type a,@object
.size a,4
a:
.long10
例:
.section.text
.type asmfunc,@function
.globlasmfunc
asmfunc:
mov pc,lr
<6>
.title:用来指定汇编列表的标题,例如:
.list:用来输出列表文件.
<7>
l
l
.unreq 寄存器别名
l
.code 表达式
如果表达式的值为16则表明下面的指令为Thumb指令,如果表达式的值为32则表明下面的指令为ARM指令.
l
l
l
l
l
l
l
l
例:
Start:
valueOfStart:
这样程序的开头Start便被存入了内存变量valueOfStart中。
l
8、
<1>
<2>
<3>
<4>
联系客服