?? asmlearn1.cpp
字號:
// asmlearn1.cpp : 定義控制臺應用程序的入口點。
//
#include "stdafx.h"
#include <iostream>
#include <wchar.h>
#include <tchar.h>
#include "testh2inc.h"
using namespace std;
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;
//或者
/*
#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>
int _tmain(int argc, _TCHAR* argv[])
{
/*
*
測試進程間共享內存
*/
//while(1)
//{
// Sleep(200);
// cout<< g_TestVal++ << endl;
//}
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 * TestInlineAsm(void)//當無參數時可以,或者不能改變寄存器的時候用naked
{
// Naked functions must provide their own prolog
__asm {
push ebp
mov esp, ebp
sub esp, __LOCAL_SIZE
}
_asm
{
mov eax, 0
ret
}
// ... and epilog
__asm {
pop ebp
ret
}
}
char * TestInlineAsm2(int i,char *p,int k)//當有參數時不要用naked
{
__asm
{
// org 500000 不允許
mov eax, 0;
//cupid ;
ret ;
}
}
/*
point struct
x byte ?
y byte ?
point ends
*
mov al,-3
cbw
nop
mov eax,55aah
bswap eax
nop
pushfd
pop eax
nop
mov bx,1
neg bx
nop
mov eax,-23
cdq
mov ecx,4
idiv ecx
mov eax,-23
sar eax,2
mov eax,0aa5555aah
bt eax,4
bt ax,6
nop
btc ax,3
btc ax,3
setc bl
setz cl
seto dl
mov ax,a1
movzx eax,ax
;add eax,a2
;daa
mul a2
aam
jmp ll1
jmp LoadLibraryA
jmp ll3
mov ebx,0401003h
jmp ebx
;jmp ll4
ll1:
nop
ll2:
nop
revsered DB 125 DUP(0AAh)
ll3:
nop
mov ecx,3
mov eax,0
ll5:
add eax,eax
mov i1,2
mov i2,3;
loopz ll5 ;//當ECX!=0,ZF=1時循環
jcxz
jecxz
mov eax,i2;
ret ;//根據過程的調用方式自動正確返回
IF (@VERSION GT 600) @VERSION 不支持
mov eax,600
ENDIF
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -