苹果作为和的ARM / Thumb ADDS指令 [英] Apple AS and ARM/Thumb ADDS instruction

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

问题描述

我工作的一个iPhone / iPad的项目,我想更新过程中的一些状态寄存器(不是全部)的算术运算。默认情况下,X code使用编译为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内联汇编code正常工作搀扶下,但会导致拇指下的编译错误:'指令Thumb16模式不支持 - 增加了R6,R4,R5'。问题就出在状态寄存器更新。 (我也知道, movcs strcs 将需要改变)。

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).

拇指是否有一个ADD指令用于设置溢出(V)或携带(C)在CPSR?如果不是,是否有特定的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的应用程序二进制接口(ABI)ARM体系结构

推荐答案

据该的的Thumb-16快速参考指南,在添加指令应该可用。这似乎是在汇编中的错误(如被@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).

我发现我可以解决它通过发出指令pre-CN $ c。使用汇编指令$ CD。例如:

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'
  ...
);

如果我想补充R2,R2,R1 中,code应该发出 .inst.w 0x1852

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

编辑:code最近更新由于手臂thumb2 LDR.W语法? Binutils的邮件列表上。

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

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

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