- 20
- 0
- 约1.38千字
- 约 4页
- 2018-02-15 发布于河南
- 举报
在C语言中调用nasm子过程
在 C语言中调用nasm过程,在nasm中调用C运行时库
作者:Allen
C调用nasm过程
GCC的函数原型声明:int f(int) __attribute__((cdecl)); 可以是cdecl也可以是stdcall,stdcall约定在函数返回前必需将参数出栈,因此不能使用在参数不定的函数调用上,例如scanf和printf_s。
VC/BCB的函数原型声明:int __cdecl f(int);
C语言代码:
// gcc –c filename.c
#include stdio.h
int fact(int) __attribute__((cdecl));
int main(void)
{
int n,sum;
printf(Sum integers up to: );
scanf(%d,n);
sum = fact(n); //,sum);
printf(Sum is %d\n,sum);
return 0;
}
Nasm自过程代码:
; nasm –f coff filename.asm
segment .text
global _fact
_fact:
enter 0,0
mov eax,[ebp+8] ;eax = n
cmp eax,1
原创力文档

文档评论(0)