宏定义用一个单个的有意义的名字来来代替一个代码块,避免重复一个代码块好多次
MACRO
$label TestAndBranch $dest, $reg, $cc
$label CMP $reg, #0
B$cc $dest
MEND
在MACRO伪指令之后是一个宏的原型语句,宏的原型语句定义了你用来调用宏的名字:TestAndBranch,它还定义了参数
label,dest,reg,cc,当调用这个宏的时候必须给参数赋值
当调用
test TestAndBranch NonZero,r0,NE
..
..
NonZero
宏替换之后
test CMP r0,#0
BNE NonZero
....
...
NonZero
MACRO
$HandlerLabel HANDLER $HandleLabel
$HandlerLabel
1: sub sp,sp,#4 ;decrement sp(to store jump address)
2: stmfd sp!,{r0} ;PUSH the work register to stack(lr does not push because it return to original address)
3: ldr r0,=$HandleLabel;load the address of HandleXXX to r0
4: ldr r0,[r0] ;load the contents(service routine start address) of HandleXXX
5: str r0,[sp,#4] ;store the contents(ISR) of HandleXXX to stack
6:ldmfd sp!,{r0,pc} ;POP the work register and pc(jump to ISR)
MEND
这个宏是init.s中一个加载中断服务程序的一段宏
=》sub sp,sp,#4 ;sp减4
stmfd sp!,{r0} stmfd相当于stmdb相当于在把数据压栈前先讲sp减4
0:sp
1:sp 5:服务程序首地址存于此
2:sp {r0} 把ro压入这个位置 6:r0复原,pc地址为中断服务地址
3:服务程序的标号到r0
4:标号内容就是服务程序开始地址加载
本文介绍了ARM汇编语言中的宏定义,通过宏可以避免代码重复,提高效率。文中给出了TestAndBranch宏的示例,用于条件跳转,并详细解释了其工作原理。此外,还展示了用于加载中断服务程序的宏,阐述了如何存储和恢复寄存器,以及跳转到服务程序的流程。

1345

被折叠的 条评论
为什么被折叠?



