我该怎么做就IPhone内联汇编? [英] How do I do inline assembly on the IPhone?
问题描述
它是如何做的?哪些步骤,我需要采取和什么是陷阱,陷阱有没有考虑?
How is it done? What steps do I need to take and what pitfalls and gotchas are there to consider?
推荐答案
我已经得到这个工作,由于一些内部帮助过的苹果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().
其次,在默认情况下,X code生成编译针对ARM Thumb指令集内联汇编编译目标,所以的 USAT 的无法识别为一个正确的指令。为了解决这个问题,做目标获取信息。向下滚动到节GCC 4.0 - code一代,取消选择编译为Thumb。然后,如果你活动的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\n\t" : "=r"(y) : "r"(a));
return y;
}
当然,现在也不会与IPhone模拟器的工作。但是的 TargetConditionals.h 的有你定义支持#ifdef反对。即* TARGET_OS_IPHONE *和* TARGET_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屋!