x86 GAS语法代码疑难解答

时间:2017-02-08 02:33:17

标签: assembly x86 gas

我编译此函数时遇到错误,特别是在Func主体中,我试图将int指针乘以3并将其加载回指针。 (即* i = 3 *(* i))

//Author Matthew Cabrera

#define FSIZE 8

// Prologue
.text
.global istr
istr:
   subl $FSIZE, %esp   //frame space
//Load Paramaters
   movl FSIZE+4(%esp), %eax   //1st param
   movl FSIZE+8(%esp), %edx   //2nd param
   movl FSIZE+12(%esp), %ecx  //3rd param
//Func body 
   leal (%ecx, %ecx, 2), %ecx //*i = 3 * (*i)
   subl %edx, %eax  //This is the 1st param - 2nd param. No errors here.
//Epilogue
   add  $FSIZE, %esp    //restore stack ptr
   ret

实际上,c函数看起来像

int istr(int a, int b, int *i){
    *i = 3 * (*i);
    return (a-b);
}     

0 个答案:

没有答案