如何在 iPhone 上进行内联汇编?

编程入门 行业动态 更新时间:2024-10-28 16:25:22
本文介绍了如何在 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_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 上进行内联汇编?

本文发布于:2023-10-05 07:57:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467333.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内联   如何在   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!