Apple AS and ARM/Thumb ADDS instruction

爱⌒轻易说出口 提交于 2019-12-04 18:05:17

I'm not very familiar with XCode and Apple's toolchain, but I suspect that it might be expecting the assembly in the old, pre-UAL form. The Thumb-16 encoding of ADD always sets flags (for registers R0-R7), however, in the pre-UAL assembly, the S was not added to the mnemonic. (Most arithmetic operations always update flags in Thumb-16, so S was implied.) So, you should try to either add .syntax_unified at the start of the assembly block, or use the simple ADD mnemonic.

However, you have another issue in your code. Thumb-16 does not support conditional instructions, only conditional branches. So you will have to redo your code using a branch, or use ADC/SBC.

Note that all of the above only applies to the original Thumb ISA (aka Thumb-16). Thumb-2 (aka Thumb-32) can do (almost) anything that ARM can, including using high registers and conditional instructions, but it's not available in ARMv6 targets (which is probably the default in XCode).

Igor suggested ".syntax_unified". However, at least for binutils 2.22, the command is ".sytax unified". The following example compiles fine here:

.align  4
.code   16
.syntax unified

adds r0,r0,r2
adc  r1,r1,r3

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

would be realized using:

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!