0
我目前正在修改在MS VS IDE中創建的代碼,我需要做的一項更改是從__declspec (naked)
更改爲__attribute__ ((naked))
。__declspec(naked)的g ++等效參數如何傳遞?
然而,我做了這個改變後,程序不能正確訪問和更改參數。
參數是否通過不同使用__attribute__ ((naked))
?
下面是代碼:
//Main file
#include <stdlib.h>
#include <stdio.h>
extern void test(int * arrayToSort, int size);
int main(int argc, char ** argv) {
int * a = (int*) malloc (sizeof(int) * 10);
int j;
for (j=0; j<10; j++)
{
printf("a[%d]=",j);
scanf("%d",a+j);
printf("\n");
}
test(a, 10);
for (j=0; j<10; j++)
{
printf("%d ", a[j]);
}
printf("\n");
}
//test code file
void test(int * array, int size)
{
_asm {
push edx
push ecx
push ebx
push eax
mov eax, dword ptr[esp+20] //*array
mov ebx, dword ptr[esp+24] //size
mov dword ptr[eax], 25 //array[0] = 25
mov dword ptr[eax+4], ebx //array[1] = size
pop eax
pop ebx
pop ecx
pop edx
}
}
任何幫助深表感謝。
系統規格:
的MacBook Pro 2009年末英特爾酷睿雙核2.66 GHz的運行OS X Lion的
當前編譯指令:
g++ -fomit-frame-pointer -m32 -fasm-blocks -o QS Test.cpp Main.cpp