線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1642
推到 Plurk!
推到 Facebook!

BCB 內加入 Assembly

 
stnovel
一般會員


發表:4
回覆:4
積分:1
註冊:2007-01-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-03-13 15:52:32 IP:61.229.xxx.xxx 訂閱
看到很多人在問如何在BCB 內加入 Assembly ?
所以寫了一個小 Sample 給大家參考一下.




<textarea class="cpp" rows="10" cols="60" name="code"> //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; char* StrRemoveAsciiC(char *str1,int ascii) { char tmp[2]={0}; char str2[512]={0}; tmp[1]='\0'; for (int i = 0; i <= strlen(str1); i ) { if(str1[i] != ascii) { tmp[0]=str1[i]; lstrcat(str2,tmp); } } return str2; } char* StrRemoveAsciiM(char *str1,int ascii) { int len=strlen(str1); BYTE abyte=ascii; _asm { std mov edi,str1 //String mov al,abyte //Remove ASCII mov ecx,len //String Length sub ebx,ebx mov dword ptr [ebp-04h],0h //Set a Template Index = 0 mLoop: or ecx,ecx jle mLoopEnd dec ecx cmp byte ptr [edi ebx],al //Compare String Index with AL je mCompare mov dl,byte ptr [edi ebx] //Save char to DL push ebx //Push ebx mov ebx,dword ptr [ebp-04h] //Set ebx to Template Index mov byte ptr [edi ebx],dl //Replace char as DL inc dword ptr [ebp-04h] pop ebx //Release ebx mCompare: inc ebx jmp mLoop mLoopEnd: mov ebx,dword ptr [ebp-04h] mov byte ptr [edi ebx],0h cld } return str1; } char* StrReplaceAsciiM(char *str1,int ascii,int replace) { int len=strlen(str1) -1; BYTE abyte=ascii; BYTE bbyte=replace; _asm{ std mov edi,str1 //String mov al,abyte //Be Replace ASCII mov dl,bbyte //Replace ASCII mov ecx,len //String Length sub ebx,ebx //Initinal string index mLoop: or ecx,ecx jle mLoopEnd dec ecx cmp BYTE PTR [edi ebx],al //Compare String Index with AL jne mCompare: mov BYTE PTR [edi ebx],dl //Replace AL to be DL mCompare: inc ebx //Increase Index jmp mLoop mLoopEnd: cld } return str1; } //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { char *aa; char *rtn; aa="abc de f gh ijk lm n op"; rtn=StrRemoveAsciiC(aa,32); ShowMessage(rtn); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { char *aa; char *rtn; aa="abc de f gh ijk lm n op"; rtn=StrRemoveAsciiM(aa,32); ShowMessage(rtn); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { char *aa; char *rtn; aa="abc de f gh ijk lm n op"; rtn = StrReplaceAsciiM(aa,32,45); ShowMessage(rtn); } //--------------------------------------------------------------------------- </textarea>
stnovel
一般會員


發表:4
回覆:4
積分:1
註冊:2007-01-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-03-14 08:31:00 IP:61.229.xxx.xxx 訂閱
char* StrRemoveAsciiC(char *str1,int ascii)
這是VC 的寫法,Function 是用來將字串中不要的字元去除掉
str1: 是字串指標
ascii : 要去除掉的字元的 ASCII 碼

char* StrRemoveAsciiM(char *str1,int ascii)
這是 Assembly 的寫法,Function 是用來將字串中不要的字元去除掉
str1: 是字串指標
ascii : 要去除掉的字元的 ASCII 碼

char* StrReplaceAsciiM(char *str1,int ascii,int replace)
這是 Assembly 的寫法,Function 是用來取代字串中的某些字元
str1: 是字串指標
ascii : 被取代的字元的 ASCII 碼
replace : 要去取代的字元的 ASCII 碼
系統時間:2024-04-30 19:49:38
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!