没有合适的资源?快使用搜索试试~ 我知道了~
首页ARM指令集详解:C语言与汇编应用指南
ARM指令集详解:C语言与汇编应用指南
![](https://csdnimg.cn/release/wenkucmsfe/public/img/star.98a08eaa.png)
ARM指令集是针对ARM架构的编程指南,主要面向刚涉足ARM开发的嵌入式工程师。ARM指令集由阿尔特拉斯半导体有限公司(ARM Limited)提供版权,自1996年至2000年。该章节详细描述了每个ARM指令的语法、用法、适用的ARM架构版本、可能引发的异常情况以及示例代码,以便于理解其工作原理。 在4.1节的"字母表顺序的ARM指令列表"部分,所有ARM指令都被罗列出来。每条指令的描述包括指令编码,即它在二进制中的表示形式;指令语法,如何在程序中正确构造;对应的ARM架构版本,确保代码的兼容性;可能出现的异常处理,提醒开发者注意潜在问题;以及伪代码示例,展示了指令在实际应用中的操作流程。此外,还有通用注意事项,解释了在指令页面上使用的各类信息类型和缩写,如`immed_n`代表n位立即数,`offset_n`指n位偏移量,这些帮助开发者理解和编写更高效、精确的代码。 通过这份文档,嵌入式工程师可以系统地学习和掌握ARM指令集,从而在实际项目中编写出高效且稳定的ARM程序,实现嵌入式设备的功能和性能优化。同时,了解ARM指令集的演变和适用的架构版本变化,有助于保持代码的长期兼容性和适应性。对于初学者来说,这是一份非常重要的参考资料,可以帮助他们快速熟悉并深入理解ARM平台的编程特性。
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/1000201/bg10.jpg)
ARM Instructions
A4-16
Copyright © 1996-2000 ARM Limited. All rights reserved.
ARM DDI 0100E
4.1.8 BLX (1)
This form of the BLX (Branch with Link and Exchange) instruction is used to call a Thumb subroutine from
the ARM instruction set at an address specified in the instruction. This instruction is unconditional (always
causing a change in program flow) and preserves the address of the instruction following the branch in the
link register (R14). Execution of Thumb instructions begins at the target address.
Syntax
BLX <target_addr>
where:
<target_addr> Specifies the address of the Thumb instruction to branch to. The branch target
address is calculated by:
1. Sign-extending the 24-bit signed (two’s complement) immediate to 32 bits
2. Shifting the result left two bits
3. Setting bit[1] of the result of step 2 to the H bit
4. Adding the result of step 3 to the contents of the PC, which contains the
address of the branch instruction plus 8.
The instruction can therefore specify a branch of approximately ±32MB.
Architecture version
Version 5 and above
Exceptions
None
Operation
LR = address of the instruction after the BLX instruction
T Flag = 1
PC = PC + (SignExtend(signed_immed_24) << 2) + (H << 1)
31 30 29 28 27 26 25 24 23 0
1111101H signed_immed_24
![](https://csdnimg.cn/release/download_crawler_static/1000201/bg11.jpg)
ARM Instructions
ARM DDI 0100E
Copyright © 1996-2000 ARM Limited. All rights reserved.
A4-17
Usage
To return from a Thumb subroutine called via BLX to the ARM caller, use the Thumb instruction:
BX R14
as described in BX on page A7-32, or use this instruction on subroutine entry:
PUSH {<registers>,R14}
and this instruction to return:
POP {<registers>,PC}
To calculate the correct value of signed_immed_24, the assembler (or other toolkit component) needs to:
1. Form the base address for this branch instruction. This is the address of the instruction, plus 8. In
other words, this base address is equal to the PC value used by the instruction.
2. Subtract the base address from the target address to form a byte offset. This offset is always even,
because all ARM instructions are word-aligned and all Thumb instructions are halfword-aligned.
3. If the byte offset is outside the range −33554432 to +33554430, use an alternative code-generation
strategy or produce an error as appropriate.
4. Otherwise, set the signed_immed_24 field of the instruction to bits{25:2] of the byte offset, and the
H bit of the instruction to bit[1] of the byte offset.
Notes
Condition Unlike most other ARM instructions, this instruction cannot be executed conditionally.
Bit[24] This bit is used as bit[1] of the target address.
![](https://csdnimg.cn/release/download_crawler_static/1000201/bg12.jpg)
ARM Instructions
A4-18
Copyright © 1996-2000 ARM Limited. All rights reserved.
ARM DDI 0100E
4.1.9 BLX (2)
This form of BLX is used to call an ARM or Thumb subroutine from the ARM instruction set, at an address
specified in a register. The branch target address is the value of register Rm, with its bit[0] forced to zero.
The instruction set to be used at the branch target is chosen by setting the CPSR T bit to bit[0] of Rm.
Register 14 is set to a return address. To return from the subroutine, use a BX R14 instruction, or store R14
on the stack and re-load the stored value into the PC.
Syntax
BLX{<cond>} <Rm>
where:
<cond> Is the condition under which the instruction is executed. The conditions are defined in The
condition field on page A3-5. If <cond> is omitted, the AL (always) condition is used.
<Rm> Is the register containing the address of the target instruction. Bit[0] of Rm is 0 to select a
target ARM instruction, or 1 to select a target Thumb instruction. If R15 is specified for
<Rm>, the results are
UNPREDICTABLE.
Architecture version
Version 5 and above
Exceptions
None
Operation
if ConditionPassed(cond) then
LR = address of instruction after the BLX instruction
T Flag = Rm[0]
PC = Rm AND 0xFFFFFFFE
Notes
ARM/Thumb state transfers
If Rm[1:0] == 0b10, the result is
UNPREDICTABLE, as branches to non word-aligned
addresses are impossible in ARM state.
31302928272625242322212019 1615 1211 876543 0
cond 00010010 SBO SBO SBO 0011 Rm
![](https://csdnimg.cn/release/download_crawler_static/1000201/bg13.jpg)
ARM Instructions
ARM DDI 0100E
Copyright © 1996-2000 ARM Limited. All rights reserved.
A4-19
4.1.10 BX
The BX (Branch and Exchange) instruction branches to an address held in a register Rm, with an optional
switch to Thumb execution. The branch target address is the value of register Rm, with its bit[0] forced to
zero. The instruction set to be used at the branch target is chosen by setting the CPSR T bit to bit[0] of Rm.
Syntax
BX{<cond>} <Rm>
where:
<cond> Is the condition under which the instruction is executed. The conditions are defined in The
condition field on page A3-5. If <cond> is omitted, the AL (always) condition is used.
<Rm> Holds the value of the branch target address. Bit[0] of Rm is 0 to select a target ARM
instruction, or 1 to select a target Thumb instruction.
Architecture version
Version 5 and above, plus T variants of version 4
Exceptions
None
Operation
if ConditionPassed(cond) then
T Flag = Rm[0]
PC = Rm AND 0xFFFFFFFE
Notes
ARM/Thumb state transfers
If Rm[1:0] == 0b10, the result is
UNPREDICTABLE, as branches to non word-aligned
addresses are impossible in ARM state.
Use of R15 Register 15 can be specified for <Rm>, but doing so is discouraged.
In a BX R15 instruction, R15 is read as normal for ARM code, that is, it is the address of
the BX instruction itself plus 8. The result is to branch to the second following word,
executing in ARM state. This is precisely the same effect that would have been obtained if
a B instruction with an offset field of 0 had been executed, or an ADD PC,PC,#0 or MOV
PC,PC instruction. In new code, use these instructions in preference to the more complex
BX PC instruction.
31 28 27 26 25 24 23 22 21 20 19 16 15 12 11 8 7 6 5 4 3 0
cond 00010010 SBO SBO SBO 0001 Rm
![](https://csdnimg.cn/release/download_crawler_static/1000201/bg14.jpg)
ARM Instructions
A4-20
Copyright © 1996-2000 ARM Limited. All rights reserved.
ARM DDI 0100E
4.1.11 CDP
The CDP (Coprocessor Data Processing) instruction tells the coprocessor whose number is cp_num to
perform an operation that is independent of ARM registers and memory. If no coprocessors indicate that
they can execute the instruction, an Undefined Instruction exception is generated.
Syntax
CDP{<cond>} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>, <opcode_2>
CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>, <opcode_2>
where:
<cond> Is the condition under which the instruction is executed. The conditions are defined
in The condition field on page A3-5. If <cond> is omitted, the AL (always)
condition is used.
CDP2 Causes the condition field of the instruction to be set to 0b1111. This provides
additional opcode space for coprocessor designers. The resulting instructions can
only be executed unconditionally.
<coproc> Specifies the name of the coprocessor, and causes the corresponding coprocessor
number to be placed in the cp_num field of the instruction. The standard generic
coprocessor names are p0, p1, ..., p15.
<opcode_1> Specifies (in a coprocessor-specific manner) which coprocessor operation is to be
performed.
<CRd> Specifies the destination coprocessor register for the instruction.
<CRn> Specifies the coprocessor register that contains the first operand for the instruction.
<CRm> Specifies the coprocessor register that contains the second operand for the
instruction.
<opcode_2> Specifies (in a coprocessor-specific manner) which coprocessor operation is to be
performed.
Architecture version
CDP is in Version 2 and above.
CDP2 is in Version 5 and above.
Exceptions
Undefined Instruction
31 28 27 26 25 24 23 20 19 16 15 12 11 8 7 5 4 3 0
cond 1110 opcode_1 CRn CRd cp_num opcode_20 CRm
剩余115页未读,继续阅读
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
CXYHXX
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- 构建智慧路灯大数据平台:物联网与节能解决方案
- 智慧开发区建设:探索创新解决方案
- SQL查询实践:员工、商品与销售数据分析
- 2022智慧酒店解决方案:提升服务效率与体验
- 2022年智慧景区信息化整体解决方案:打造数字化旅游新时代
- 2022智慧景区建设:大数据驱动的5A级管理与服务升级
- 2022智慧教育综合方案:迈向2.0时代的创新路径与实施策略
- 2022智慧教育:构建区域教育云,赋能学习新时代
- 2022智慧教室解决方案:融合技术提升教学新时代
- 构建智慧机场:2022年全面信息化解决方案
- 2022智慧机场建设:大数据与物联网引领的生态转型与客户体验升级
- 智慧机场2022安防解决方案:打造高效指挥与全面监控系统
- 2022智慧化工园区一体化管理与运营解决方案
- 2022智慧河长管理系统:科技助力水环境治理
- 伪随机相位编码雷达仿真及FFT增益分析
- 2022智慧管廊建设:工业化与智能化解决方案
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)