Arm generic user guide的第3.10.4节(第172页)给出了使用TBB的示例,但该示例使用了Arm汇编程序。我想学习如何在气体中使用TBB,但似乎无法弄清楚。 我应该如何修改指南中的示例,以使用gas而非armasm来实现switch语句?
ADR.W R0, BranchTable_Byte
TBB [R0, R1] ; R1 is the index, R0 is the base address of the
; branch table
Case1
; an instruction sequence follows
Case2
; an instruction sequence follows
Case3
; an instruction sequence follows
BranchTable_Byte
DCB 0 ; Case1 offset calculation
DCB ((Case2-Case1)/2) ; Case2 offset calculation
DCB ((Case3-Case1)/2) ; Case3 offset calculation
我刚开始使用gas,不确定是否应该在汇编器文件开头的.data节中定义分支表,还是应该在.text节的switch语句之后进行。< / p>
答案 0 :(得分:1)
.cpu cortex-m3
.thumb
.syntax unified
ADR.W R0, BranchTable_Byte
TBB [R0, R1] @; R1 is the index, R0 is the base address of the
@; branch table
Case1:
@; an instruction sequence follows
nop
Case2:
@; an instruction sequence follows
nop
nop
Case3:
@; an instruction sequence follows
nop
nop
nop
BranchTable_Byte:
.byte 0 @; Case1 offset calculation
.byte ((Case2-Case1)/2) @; Case2 offset calculation
.byte ((Case3-Case1)/2) @; Case3 offset calculation
也许是这样。在标签上需要冒号。 ;可悲的是,我不再是评论@ @,对标签数学很幸运。