首页 > 解决方案 > 如何在 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 语句之后。

标签: armgnu-assemblercortex-m3armasm

解决方案


.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

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


推荐阅读