How do I do inline assembly on the IPhone?

前端 未结 4 440
不思量自难忘°
不思量自难忘° 2020-12-02 11:01

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

4条回答
  •  猫巷女王i
    2020-12-02 11:13

    I write quite a bit of ARM Cortex-A8 assembly-code. The CPU on the iPhone is an ARM11 (afaik) so the core instruction set is the same.

    What exactly are you looking for? I could give you some examples if you want.


    EDIT:

    I just found out that on the iPhone you have to use the llvm-gcc compiler. As far as I know it should understand the inline assembler syntax from GCC. If so all the ARM inline assembler tutorials will work on the iPhone as well.

    Here is a very minimal inline assembler function (in C). Could you please tell me if it compiles and works on the iphone? If it works I can rant a bit how to do usefull stuff in ARM inline assembler, especially for the ARMv6 architecture and the DSP extensions.

    inline int saturate_to_255 (int a)
    {
      int y;
      asm ("usat %0, #8, %1\n\t" : "=r"(y) : "r"(a));
      return y;
    }
    

    should be equivalent to:

    inline int saturate_to_255 (int a)
    {
      if (a < 0) a =0;
      if (a > 255) a = 255;
      return a;
    }
    

提交回复
热议问题