vs2005内嵌汇编的使用:标准的c/c++函数的调用和非标准的c/c++函数的调用以及变量的引用
2008-04-03 09:28
330 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <stdio.h>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char *szCaption = "Hello,World";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
......{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char *szformat = "%s %s ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char szMsg[] = "I Love You";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
......{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
_asm......{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
lea eax, szMsg
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mov eax, szCaption ;全部变量为指针的引用
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mov eax, szformat
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mov eax, printf
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
call eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//内联汇编调用c函数必须自己清除堆栈
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//用不使用的ebx寄存器清除堆栈,或add esp, 12
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pop ebx
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pop ebx
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pop ebx
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}catch(CException* e)......{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
char szCaption[] = "Hello,World";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
......{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char *szformat = "%s %s ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char szMsg[] = "I Love You";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
......{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
_asm......{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
lea eax, szMsg
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mov eax, offset szCaption ;全部变量非指针的引用
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mov eax, szformat
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mov eax, printf
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
call eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//内联汇编调用c函数必须自己清除堆栈
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//用不使用的ebx寄存器清除堆栈,或add esp, 12
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pop ebx
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pop ebx
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pop ebx
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}catch(CException* e)......{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <stdio.h>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <windows.h>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char szMsg[] = "I Love You";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char *szCaption = "Hello,World";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
_asm...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push MB_OK or MB_ICONINFORMATION
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mov eax, szCaption ;局部变量为指针类型时可直接用mov
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
lea eax,szMsg ;局部变量用lea
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
push 0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mov eax, dword ptr [MessageBox] ; 获得MessageBox的地址;不能直接call dword ptr [MessageBox] ,因为静态地址不能转换为动态地址,即函数在dll中的地址没有转化为程序运行中的相对地址
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
call eax
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}catch(CException* e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
为什么调用printf的时候不加是call printf 而调用messagebox的时候就是call [messagebox]
回答:
printf 是标准的c/c++函数
messagebox不是标准的c/c++函数, 而是api函数。
由于是系统运行库函数, messageboxa 指向的不是函数,而是存储函数指针的地址,所以为二次指针。 printf 是函数指针。
相关文章推荐
- [笔试题 3][c/c++]main函数自己递归调用main函数以及static变量的使用
- 笔记--ThinkPHP模板的变量使用与运算以及模板函数调用
- 引用变量的类型强转以及InstanceOf方法的使用
- 用类名做方法的返回值类型 在学习Java的初始阶段,很多同学使用基本数据类型定义变量和引用类型定义变量以及使用类名做方法的返回值类型常常不知所以。今天我以自己的解读方式和个人的理解作一个简单的解释,和
- Android调用系统分享功能以及createChooser的使用
- C/C++:函数的编译方式与调用约定以及extern “C”的使用
- 01_JNI是什么,为什么使用,怎么用JNI,Cygwin环境变量配置,NDK案例(使用Java调用C代码),javah命令使用
- 嵌入式Linux ARM汇编(五)——ARM体系结构过程调用标准
- BMForum B-Template 使用 $abcdef 来调用变量
- c++中的引用的使用原理以及使用实例 (1)
- Java中@Deprecated作用、使用以及引用
- 使用jdk自带工具生成heapdump文件以及分析内存中的变量情况
- 使用AIDL,客户端调用和Service回调,以及一些需要注意的细节
- (vs2008链接错误LK200x:xxx在yyy.obj中已定义或xxx在yyy中以被引用):一个全局的变量想在多个cpp文件中使用
- js调用ajax以及JSON.parse()与JSON.stringify()的使用
- C++和C#有关值类型和引用类型,以及对引用类型使用ref的效果
- C++ VS 2008中ATL的创建,使用。并在C++项目以及C#项目中进行调用测试
- c语言里如何调用汇编里的变量?
- 交换两个数的值以及不使用临时变量交换两个数的值
- thymeleaf的初次使用(带参请求以及调用带参js方法)