如何将TBB指令(Cortex-M3)与GNU汇编器一起使用?



Arm通用用户指南(第 172 页(的第 3.10.4 节给出了使用 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 语句之后定义分支表。

.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

也许是这样的东西。 标签上需要冒号。 ;可悲的是不再是评论@是,在标签数学上很幸运。

最新更新