从臂组装功能返回浮动到objective-c [英] return floats to objective-c from arm assembly function

查看:178
本文介绍了从臂组装功能返回浮动到objective-c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个在iPhone 4(32位代码)以及iPhone 6s(64位代码)上运行良好的汇编函数。我从objective-c中的调用函数传入四个浮点数。

I've written an assembly function that runs fine on an iPhone 4 (32-bit code) as well as on an iPhone 6s (64-bit code). I pass in four floating point numbers from a calling function in objective-c.

这是我用于4个浮点数的结构,下面是原型函数 - 在我的objective-c代码的顶部找到。

Here is the structure I use for the 4 floating point numbers and below that is the prototype for the function - as found at the top of my objective-c code.

struct myValues{    // This is a structure.  It is used to conveniently group multiple data items logically.
    float A;        // I am using it here because i want to return multiple float values from my ASM code
    float B;        // They get passed in via S0, S1, S2 etc. and they come back out that way too
    float number;
    float divisor;  //gonna be 2.0
}myValues;

struct myValues my_asm(float e, float f, float g, float h);  //  Prototype for the ASM function

在我的objective-c代码中调用我的汇编函数就像这样:

Down in my objective-c code I call my assembly function like this:

myValues = my_asm(myValues.A, myValues.B, myValues.number,myValues.divisor);   // ASM function

当针对iPhone 6S运行时,代码像冠军一样运行(64位代码)。 4个浮点值通过ARM单浮点寄存器S0-S4从objective-c代码传递到汇编代码。返回的结果也通过S0-S4传递。

When running against the iPhone 6S the code runs like a champ (64-bit code). The 4 floating point values are passed from the objective-c code to the assembly code via the ARM single float registers S0-S4. The results returned are also passed via S0-S4.

当针对iPhone 4运行时,代码运行正常(32位代码)。 4个浮点值通过ARM单浮点寄存器S0,S2,S4和S6从obj-c代码传递到汇编代码(不确定为什么跳过奇数寄存器)。代码运行正常,但返回到我的obj-c结构的值是垃圾。

When running against the iPhone 4 the code runs fine as well (32-bit code). The 4 floating point values are passed from the obj-c code to the assembly code via the ARM single float registers S0, S2, S4, and S6 (not sure why skips odd registers). The code runs fine but the values that get returned to my obj-c structure are garbage.

我在哪里/如何从ARM 32位代码传递浮点值,以便它们返回obj-c结构?

Where/how do i pass floating point values from the ARM 32-bit code so they arrive back in the obj-c structure?

谢谢,
relayman357

thanks, relayman357

ps下面是我的Xcode S文件中的汇编代码。

p.s. Below is my assembly code from my Xcode S file.

.ios_version_min 9, 0
.globl  _my_asm
.align  2

#ifdef __arm__
.thumb_func _my_asm
.syntax unified
.code 16

_my_asm:                   // 32 bit code
// S0 = A, S2 = B, S4 = Number, S6 = 2.0   - parameters passed in when called by the function
vadd.f32 s0, s0, s2 
vdiv.f32 s0, s0, s6   
vdiv.f32 s1, s4, s0   
vcvt.u32.f32 r0,s0
bx lr
//ret

#else
_my_asm:                  // 64 bit code
//add W0, W0, W1
; S0 = A, S1 = B, S2 = Number, S3 = 2.0  parameters passed in when called by the function
fadd s0, s0, s1  
fdiv s0, s0, s3  
fdiv s1, s2, s0  
ret

#endif


推荐答案

您的任何一个函数都没有正确返回结构。您需要了解ARM ABI。您可以先阅读Apple的 iOS ABI函数调用指南。如果在研究ABI后你不明白问一个新的问题,显示你曾经尝试过的。

Neither of your functions are correctly returning a structure. You need to understand the ARM ABI. You can start by reading Apple's iOS ABI Function Call Guide. If after studying the ABI you do not understand ask a new question showing what you've tried.

HTH

这篇关于从臂组装功能返回浮动到objective-c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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