如何在 gnu 汇编程序中使用 TBB 指令(Cortex-M3)?
How to use TBB instruction (Cortex-M3) with gnu assembler?
Arm的3.10.4节generic user guide(第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 部分中定义分支 table,或者它是否应该在我的 switch 语句之后.text 部分。
.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
也许是这样的。标签上需要冒号。 ;可悲的是不再是评论@是,在标签数学上很幸运。
Arm的3.10.4节generic user guide(第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 部分中定义分支 table,或者它是否应该在我的 switch 语句之后.text 部分。
.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
也许是这样的。标签上需要冒号。 ;可悲的是不再是评论@是,在标签数学上很幸运。