Apple AS 和 ARM/Thumb ADDS 指令 [英] Apple AS and ARM/Thumb ADDS instruction

查看:22
本文介绍了Apple AS 和 ARM/Thumb ADDS 指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个 iPhone/iPad 项目,我想在一些(不是全部)算术运算中更新状态寄存器.默认情况下,Xcode 使用Compile for Thumb",我不想更改它.

I'm working on an iPhone/iPad project, and I want to update the status register during some (not all) arithmetic operations. By default, Xcode uses 'Compile for Thumb' and I don't want to change it.

以下 GCC 内联汇编代码在 ARM 下运行良好,但在 Thumb 下导致编译错误:Thumb16 模式不支持指令 - 添加 r6、r4、r5".问题在于状态寄存器更新.(我也知道 movcsstrcs 需要更改).

The following GCC inline assembly code works fine under ARM, but results in a compile error under Thumb: 'instruction not supported in Thumb16 mode - adds r6,r4,r5'. The problem lies in the status register update. (I'm also aware that movcs and strcs will need to be changed).

Thumb 是否有在 CPSR 中设置溢出 (V) 或进位 (C) 的 ADD 指令?如果没有,是否有特定于 Thumb 的程序集级别的解决方法来测试溢出和进位?

Does Thumb have an ADD instruction which sets Overflow (V) or Carry (C) in the CPSR? If not, are there Thumb-specific assembly level workarounds to test for overflows and carries?

uint32_t result, a, b;
int no_carry = 1;
...

__asm__
(
  "ldr  r4, %[xa]   ;"  // R4 = a
  "ldr  r5, %[xb]   ;"  // R5 = b
  "adds r6, r4, r5  ;"  // R6 = R4 + R5, set status
  "movcs    r4, #0      ;"  // set overflow (if carry set)
  "strcs    r4, %[xc]   ;"  // store it (if carry set)
  "str  r6, %[xr]   ;"  // result = R6
  : [xr] "=m" (result), [xc] "=m" (no_carry)
  : [xa] "m" (a), [xb] "m" (b)
  : "r4", "r5", "r6"
);

...

还需要移动寄存器以利用 ARM 架构的应用程序二进制接口 (ABI) 上的 ARM ABI.

Registers also need to be moved around to take advantage of the ARM ABI at Application Binary Interface (ABI) for the ARM Architecture.

推荐答案

根据Thumb-16 快速参考指南ADDS 指令应该可用.这似乎是汇编程序中的一个错误(@dwelch 已确认).

According to the Thumb-16 Quick Reference Guide, the ADDS instruction should be available. This appears to be a bug in the assembler (as was confirmed by @dwelch).

我发现我可以通过发布使用汇编指令预先编码的指令来解决这个问题.例如:

I found I could work around it by issuing instructions pre-encoded using assembler directives. For example:

__asm__
(
  "ldr  r0, %[xa]   ;"  // R0 = a
  "ldr  r1, %[xb]   ;"  // R1 = b
  "adds r1, r1, r0  ;"  // R1 = a + b
  ...
);

将使用:

__asm__
(
  "ldr  r0, %[xa]   ;"  // R0 = a
  "ldr  r1, %[xb]   ;"  // R1 = b
  ".inst.w 0x1809   ;"  // Issue 'adds r1, r1, r0'
  ...
);

如果我想要 adds r2, r2, r1,代码应该发出 .inst.w 0x1852,依此类推.

If I wanted adds r2, r2, r1, the code should emit .inst.w 0x1852, and so on.

最近由于 arm thumb2 ldr.w 语法而更新了代码? 在 Binutils 邮件列表中.

Code recently updated due to arm thumb2 ldr.w syntax? on the Binutils mailing list.

这篇关于Apple AS 和 ARM/Thumb ADDS 指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆