C程序使用不同函数调用约定调用汇编子过程
如转载,请注明出处:http://blog.csdn.net/zhangyang0402/archive/2010/05/01/5549266.aspx
开发工具:VC ++ 6.0 MASM32
一、__cdecl调用方式
1. 在VC中新建Win32 Console Application, TestASM
2. 新建test.c
#include<stdio.h>
extern void swap(int *px, int *py);
int main(void)
{
int a=1, b=2;
printf("before swaping, a=%d, b=%d\n", a, b);
swap(&a, &b);
printf("after swaping, a=%d, b=%d\n", a, b);
return 0;
}
3. 使用UltraEdit编辑汇编程序swap.asm
.386
.MODEL FLAT, C
OPTION CASEMAP:NONE
.CODE
swap PROC a:DWORD, b:DWORD
PUSH ESI
PUSH EDI
MOV ESI, [EBP+8]
MOV EAX, [ESI] ;参数1的值->EAX
MOV EDI, [EBP+12]
XCHG EAX, [EDI]
MOV [ESI], EAX
POP EDI
POP ESI
RET
swap ENDP
END
4. 将swap.asm添加到TestASM工程中
VC->Project->Add to project->Files, 文件类型选择“所有文件”,选中汇编源文件swap.asm并添加到工程
或直接编译swap.asm,将生成的swap.obj拷贝到工程目录下
5. 在VC中设置汇编程序编译选项
在VC的FileView中,右击swap.asm->Settings, 切换到“Custom Build”选项卡,
在“Command”中输入:ml /c /coff $(InputName).asm,
“Output”中输入 :$(InputName).obj
6. 编译链接执行
双击test.c->Compile, 生成test.obj
双击swap.asm->Compile, 生成swap.obj
然后Build, 生成TestASM.exe
最后执行
结果如下:
before swaping, a=1, b=2
after swaping, a=2, b=1
Press any key to continue
二、__stdcall调用方式
1.C源程序
#include<stdio.h>
extern
相关文档:
1.求下面函数的返回值(微软)
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
......
C语言中有几个基本输入函数:
//获取字符系列
int fgetc(FILE *stream);
int getc(FILE *stream);
int getchar(void);
//获取行系列
char *fgets(char * restrict s, int n, FILE * restrict stream);
char *gets(char *s);//可能导致溢出,用fgets代替之。
//格式化输入系列
int fscanf(FILE * r ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<windows.h>
#include<malloc.h>
#include<math.h>
typedef struct worker
{
int num; //编号
char name[15]; //姓名
char zhicheng[15];& ......
曾经碰到过让你迷惑不解、类似于int * (* (*fp1) (int) ) [10];这样的变量声明吗?本文将由易到难,一步一步教会你如何理解这种复杂的C/C++声明。
我们将从每天都能碰到的较简单的声明入手,然后逐步加入const修饰符和typedef,还有函数指针,最后介绍一个能够让你准确地理解任何C/C++声明的“右左法则”。 ......