arm - 如何在 gnu 汇编程序中使用 TBB 指令(Cortex-M3)?
问题描述
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
可能是这样的。标签上需要冒号。; 可悲的是不再是评论@是,在标签数学上很幸运。
推荐阅读
- php - php openssl PKI 加密和解密
- meteor - 在本地流星服务器上运行一个简单的 js 文件
- javascript - 如何禁用调整大小/方向更改的功能?
- c++ - tensorflow c++加载pbtxt
- javascript - Javascript原型比较给出未预期的结果
- python - 如何在mac上降级python3的chromedriver版本?
- c - 调试难以重现的 C 错误。动态断点
- hive - 未找到 Serde hows 类的 XML 摄取到 Hive 表中的问题
- php - 从不同的关系中获取最新的雄辩 laravel
- java - 如何获取特定枚举的 Enum.name() 的所有引用?