确定装配函数的返回类型 [英] determining the return type of a function in assembly

查看:181
本文介绍了确定装配函数的返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下code是一个家庭作业,实际装配命令我明白了。但是我不能确定(并一直在寻找)如何判断函数的返回类型和多少个参数,如果任何函数使用。教授真的没有过这口井(单调公主任期)去
分配是读取组装code,然后写上装配code C code基地。我再次明白的指示,只是不能找出返回类型或有多少参数code采用

  .filehw5.c
    。文本
    .p2align 4日,15
.globl P1
    .TYPE P1,@function
P1:
.LFB0:
    .cfi_startproc
    addq%RSI,RDI%
    addq%RDI,RDX%
    MOVQ%的RDX,RAX%
    RET
    .cfi_endproc


解决方案

您应该看看为处理器/平台了解低水平执行调用约定。

调用子程序之前,调用者应该保存在指定的来电者保存一定的寄存器的内容。调用者保存的寄存器EAX,ECX,EDX [86]。由于调用的子程序允​​许修改这些寄存器,如果主叫方的子程序返回后,依靠他们的价值观,调用者必须在推动这些寄存器中的值压入堆栈(这样他们可以在子程序返回后恢复。
传递参数给子程序,把它们压入堆栈之前调用。参数应以倒序(即第一个最后一个参数)推。由于堆栈增长下,第一个参数将被存储在最低地址(参数反演这个历史上被用来允许函数传递可变数量的参数)。 [从X86调用约定]

The code below is a homework assignment, the actual assembly commands I understand. However I am unsure (and have been looking) how to determine the return type of the function and how many arguments if any the function takes. Professor really didn't go over this well (Monotone tenure princess) The assignment is to read assembly code and then write c code base on the assembly code. Again I understand the instructions, just cant figure out what the return type is or how many arguments the code takes

    .file   "hw5.c"
    .text
    .p2align 4,,15
.globl p1
    .type   p1, @function
p1:
.LFB0:
    .cfi_startproc
    addq    %rsi, %rdi
    addq    %rdi, %rdx
    movq    %rdx, %rax
    ret
    .cfi_endproc

解决方案

You should look at the calling convention for the processor/platform to understand the low level implementation.

Before calling a subroutine, the caller should save the contents of certain registers that are designated caller-saved. The caller-saved registers are EAX, ECX, EDX[x86]. Since the called subroutine is allowed to modify these registers, if the caller relies on their values after the subroutine returns, the caller must push the values in these registers onto the stack (so they can be restore after the subroutine returns. To pass parameters to the subroutine, push them onto the stack before the call. The parameters should be pushed in inverted order (i.e. last parameter first). Since the stack grows down, the first parameter will be stored at the lowest address (this inversion of parameters was historically used to allow functions to be passed a variable number of parameters). [ from x86 calling convention]

这篇关于确定装配函数的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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