// asmlearn1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
using namespace std;
#include "testh2inc.h"
extern "C" int __stdcall Test1(int val);
extern "C" char g_fileName[]; //变量声明时也要用extern "C"
extern "C" char g_pfileName[]; //label 指示的标识符不能指定指针
//extern "C" *char g_fileName; //本句与上句不同,
//上边的g_fileName代表串本身的地址,而本句中的g_fileName表示一个变量,他的内容是串的地址,
extern "C" H2INC2 testh2inc2;
extern "C" g_Version;
extern "C" char g_Data[];
extern "C" char g_Time[];
extern "C" g_Cpu;
//extern "C" char g_Environ[];
extern "C" char g_Interface[];
extern "C" g_Line;
int power2( int num, int power );
char * TestInlineAsm(int i,char *p,int k);
//声明一个共享段
#pragma section("myShareData",read,write,shared)
//在一个段内声明一个变量
__declspec(allocate("myShareData")) int g_TestVal = 0; //这条语句在VC6.0下有问题
//或者
/*
#pragma data_seg("shared")
HHOOK g_hProc = NULL; // 窗口过程钩子句柄
HHOOK g_hKey = NULL; // 键盘钩子句柄
HWND g_hRich = NULL; // 文本框句柄
#pragma data_seg()
#pragma comment(linker, "/section:shared,rws")
*/
#include <windows.h>
string testReturnVal(COMPLEXF_SLIB &f1)
{
//return COMPLEXF_SLIB(3,4,7,8);
COMPLEXF_SLIB f2;
f2.real=2.3;
f2.image=5.6;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
f2.real = f1.real * f2.image;
f2.image = f2.image + f2.real * f1.real;
// f2.test3 =f1.image+f1.real;
// return f2;
return string ("asldkj");
}
int _tmain(int argc, _TCHAR* argv[])
{
/*
*
测试进程间共享内存
*/
//while(1)
//{
// Sleep(200);
// cout<< g_TestVal++ << endl;
//}
//__m128d a=3.5;
//__m128d b=6.8;
//__m128d ret=_mm_add_sd(a, b);
//complex<int>f4(23,16);
//complex<int>f5(23,16);
//cout<< (f4*f5) << endl;
//float f2=23.32;
//complex<float>f1(f2,23.4);
//complex<float>f3(23.4,f2);
//cout<< (f1*f3) << endl;
//cout<< sin(f2) << endl;
//return 1;
cout<< "long double=" << sizeof(long double) ;
COMPLEXF_SLIB complex1[400];
cout<< testReturnVal(complex1[3]) << endl;
for(int k = 0; k< 400; k++)
{
complex1[k].image=0.345;
complex1[k].real=0.789;
}
cout<< TestFloat1(1.2, 2.3, 3.4, complex1, 5);
return 1;
cout<<Test1(4) << endl;
// cout<<(char *)Test1(4) << endl;
cout << g_fileName <<endl;
cout << "g_Version: " << g_Version <<endl;;
cout << "g_Data: " << g_Data <<endl;;
cout << "g_Time: " << g_Time <<endl;;
cout << "g_Cpu: " << g_Cpu <<endl;;
//cout << "g_Environ: " << char g_Environ[] <<endl;;
cout << "g_Interface: " << g_Interface <<endl;;
cout << "g_Line: " << g_Line <<endl;;
cout << g_pfileName;
cout<< testh2inc2.k;
int i=33;
int j,k;
testproc1(i, (int)&j, (int)&k);
ll4:
return 0;
}
/*
*
#pragma alloc_text( "textsection", function1, ... )
textsection为要把指定得函数放到test段得哪一个sections里边,一般来说比较常用得是init和page。
init节中得函数在函数初始化之后就会从内存在清除(当然,虚地址还是保留得),比较适合一些初始化得函数,这样可以节省内存空间。
page是将函数放在内存得分页区(相对来说,windows下得未分页区是比较宝贵得资源)
*/
/*
*
Each assembly-language statement can contain only one C or C++ symbol. Multiple symbols can appear in the same assembly instruction only with LENGTH, TYPE, and SIZE expressions.
Functions referenced in an __asm block must be declared (prototyped) earlier in the program. Otherwise, the compiler cannot distinguish between function names and labels in the __asm block.
An __asm block cannot use any C or C++ symbols with the same spelling as MASM reserved words (regardless of case). MASM reserved words include instruction names such as PUSH and register names such as SI.
Structure and union tags are not recognized in __asm blocks.
typedef names, generally used with operators such as PTR and TYPE or to specify structure or union members
*/
/*
*
struct first_type hal;
struct second_type oat;
__asm
{
// mov ebx, OFFSET hal
mov ecx, [ebx]hal.same_name ; Must use 'hal'
mov esi, [ebx].weasel ; Can omit 'hal'
}
*/
/*
*
#define randasm __asm _emit 0x4A __asm _emit 0x43 __asm _emit 0x4B
.
.
.
__asm {
randasm
}
You must refer to segments by register rather than by name (the segment name _TEXT is invalid, for instance). Segment overrides must use the register explicitly, as in ES:[BX].
__asm C Size
LENGTH arr sizeof(arr)/sizeof(arr[0]) 8
SIZE arr sizeof(arr) 32
TYPE arr sizeof(arr[0]) 4
When using __asm to write assembly language in C/C++ functions, you don't need to preserve the EAX, EBX, ECX, EDX, ESI, or EDI registers.
Note If your inline assembly code changes the direction flag using the STD or CLD instructions, you must restore the flag to its original value
An __asm block can call only global C++ functions that are not overloaded. If you call an overloaded global C++ function or a C++ member function, the compiler issues an error
*/
/*
*
C macros offer a convenient way to insert assembly code into your source code, but they demand extra care because a macro expands into a single logical line. To create trouble-free macros, follow these rules:
Enclose the __asm block in braces.
Put the __asm keyword in front of each assembly instruction.
//Use old-style C comments ( /* comment *///) instead of assembly-style comments ( ; comment) or single-line C comments ( // comment).
/*To illustrate, the following example defines a simple macro:
#define PORTIO __asm \
/* Port output //可以这样注释\
{ \
__asm mov al, 2 \
__asm mov dx, 0xD007 \
__asm out dx, al \
}
*/
void func( void )
{
goto C_Dest; /* Legal: correct case */
//goto c_dest; /* Error: incorrect case */
goto A_Dest; /* Legal: correct case */
//goto a_dest; /* Legal: incorrect case */
__asm
{
jmp C_Dest ; Legal: correct case
//jmp c_dest ; Legal: incorrect case
jmp A_Dest ; Legal: correct case
//jmp a_dest ; Legal: incorrect case
a_dest: ; __asm label
}
C_Dest: /* C label */
return;
}
int power2( int num, int power )
{
__asm
{
mov eax, num ; Get first argument
mov ecx, power ; Get second argument
shl eax, cl ; EAX = EAX * ( 2 to the power of CL )
}
/* Return with result in EAX */
}
__declspec (naked) char * Tes
没有合适的资源?快使用搜索试试~ 我知道了~
c语言内嵌汇编_asm
共18个文件
cpp:5个
h:4个
asm:3个
需积分: 49 21 下载量 200 浏览量
2013-11-06
20:57:39
上传
评论
收藏 21KB RAR 举报
温馨提示
c语言与汇编混合编程,用_asm关键字可以实现此功能,在c++编程环境里一样适用,主要用于嵌入式开发。
资源推荐
资源详情
资源评论
收起资源包目录
902717cpp_asm混合.rar (18个子文件)
www.pudn.com.txt 218B
asmlearn1
testh2inc.h 988B
asmlearn1.suo 12KB
asm2.asm 2KB
stdafx.h 293B
asmlearn1.vcproj 5KB
asmlearn1.cpp 10KB
asmlearn1.sln 907B
stdafx.cpp 213B
asm1.asm 8KB
vc6_asm
testh2inc.h 707B
testml1.dsw 537B
asmlearn1.cpp 7KB
testml1.dsp 5KB
testml1.cpp 102B
asm1.asm 5KB
StdAfx.cpp 294B
StdAfx.h 769B
共 18 条
- 1
资源评论
diawenxin
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功