如何在 iPhone 上进行内联汇编? [英] How do I do inline assembly on the IPhone?

查看:35
本文介绍了如何在 iPhone 上进行内联汇编?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是怎么做的?我需要采取哪些步骤以及需要考虑哪些陷阱和问题?

How is it done? What steps do I need to take and what pitfalls and gotchas are there to consider?

推荐答案

感谢 Apple Devforums,如果您是专门的 iPhone 开发者,则应该注册.

I've gotten this to work, thanks to some inside help over at the Apple Devforums, you should sign up if you're a dedicated IPhone developer.

首先,它是 __asm__(),而不是普通的 asm().

First thing's first, it's __asm__(), not plain asm().

其次,默认情况下,XCode 会生成一个编译目标,该目标会针对 ARM Thumb 指令集编译内联汇编,因此 usat 未被识别为正确的指令.要解决此问题,请在目标上执行获取信息".向下滚动到GCC 4.0 - 代码生成"部分并取消选中为 Thumb 编译".然后,如果您将 Active SDK 设置为设备"

Secondly, by default, XCode generates a compilation target that compiles inline assembly against the ARM Thumb instruction set, so usat wasn't recognized as a proper instruction. To fix this, do "Get Info" on the Target. Scroll down to the section "GCC 4.0 - Code Generation" and uncheck "Compile for Thumb". Then this following snippet will compile just fine if you set the Active SDK to "Device"

inline int asm_saturate_to_255 (int a) {
  int y;
  __asm__("usat %0, #8, %1
	" : "=r"(y) : "r"(a));
  return y;
}

当然,现在它不适用于 iPhone 模拟器.但是 TargetConditionals.h 已经定义了你可以 #ifdef 反对.即 TARGET_OS_IPHONETARGET_IPHONE_SIMULATOR.

Naturally, now it won't work with the IPhone Simulator. But TargetConditionals.h has defines you can #ifdef against. Namely TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR.

这篇关于如何在 iPhone 上进行内联汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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