问题描述
只是为了教育目的,我想一个功能添加到现有的iPhone应用程序,用ARM汇编。我不需要在ARM汇编教程一般,因为我已经看过太多了。我只是不知道如何实际运行code!
Just for educational purposes, I would like to add a function to an existing iPhone app, written in ARM assembly. I don't need a tutorial on ARM assembly in general, because I already read too many of them. I just don't know how to actually run the code!
我想要做的是一样的东西:
What I would like to do is something like:
useless.h:
useless.h:
void useless();
useless.s:
useless.s:
useless:
bx lr
如果这也适用于模拟器将被罚款......在模拟器中,.s文件不会编译,所以也许我应该这样做:
If this also works on the simulator it would be fine... On the simulator, the .s file would not compile, so I should maybe do something like:
useless.s:
useless.s:
#if I_AM_ARM
useless:
bx lr
#endif
useless.c:
useless.c:
#if !I_AM_ARM
void useless()
{
}
#endif
我知道我用的语法是坏了,但我怎样写正确? (上只是因为我想尝试一些内联汇编没有选项模拟器打破一个应用程序...)
I know the syntax I use is broken, but how do I write it correctly? (Breaking an app on the simulator just because I want to try some inline assembly is no option...)
第二最好的办法是使用内联汇编,但我强烈preFER非内联汇编。
The second-best option would be to use inline assembly, but I would strongly prefer non-inline assembly.
谢谢!
编辑:我想学习ARM汇编,所以我想找到一种方法来编译ARM汇编code,以及执行ARM汇编code
推荐答案
我终于找到了自己的答案。这其实并不难。我只解决它虽然32位ARM版本。
I finally found the answer myself. It's actually not that hard. I only solved it for the 32-bit ARM version though.
useless.h:
useless.h:
void useless();
useless.s:
useless.s:
#ifdef __arm__
.syntax unified
.globl _useless
.align 2
.code 16
.thumb_func _useless
_useless:
//.cfi_startproc
bx lr
//.cfi_endproc
// CFI means Call Frame Information
// Optionally. Use for better debug-ability.
#endif
useless.c:
useless.c:
#ifndef __arm__
void useless()
{
}
#endif
注:
铛ARM汇编语法是从你例子看到所有在网上有点不同。注释以 //
和 / *多行注释* /
也支持。它也懂得了标准C preprocessor。该功能已被定义为一个拇指的功能,如果你指定一个手臂功能( code 32
)程序将崩溃。行 .thumb_func _useless
可ommited和它的作品依然。我不知道这意味着什么。如果省略 code 16
行,程序崩溃。
The CLANG ARM Assembler syntax is a bit different from what you see in example all over the web. Comments start with //
and /* multiline comments */
are also supported. It also understands the standard C preprocessor. The function has to be defined as a Thumb function, if you specify an arm function (.code 32
) the program will just crash. The line .thumb_func _useless
can be ommited and it works still. I have no Idea what it means. If you omit the .code 16
line, the program crashes.
有关 #IFDEF
。对ARMv7, __ __手臂
定义。对于ARMv8,即在iPhone 5S的64位变体, __手臂__
没有定义,但 __ arm64 __
定义来代替。以上code没有为64位,ARM的版本。相反,从的实施useless.c
将被使用。 (我没有忘记ARMv7s,我只是没有在目前我手里的弓的装置,所以我无法测试。)
about the #ifdef
. For ARMv7, __arm__
is defined. For ARMv8, i.e. the 64bit-variant on the iPhone 5S, __arm__
is not defined, but __arm64__
is defined instead. The above code does not work for the 64bit-ARM-version. Instead, the implementation from useless.c
will be used. (I didn't forget ARMv7s, I just don't have a device with that arch in my hands currently, so I cannot test.)
这篇关于我如何使用在X code中的ARM汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!