java strcat_strcat strcpy函数源码

page    ,132title   strcat - concatenate (append) one string to another;***;strcat.asm - contains strcat() and strcpy() routines;

;Copyright (c) Microsoft Corporation. All rights reserved.;

;Purpose:;STRCAT concatenates (appends) a copy of the source string to the;end of the destination string, returning the destination string.;

;*******************************************************************************.xlist

include cruntime.inc.list

page;***;char *strcat(dst, src) - concatenate (append) one string to another;

;Purpose:;Concatenates src onto the end of dest.  Assumes enough;space in dest.;

;Algorithm:;char * strcat (char * dst, char * src);{;char * cp = dst;;

;while( *cp );++cp;           /* Find end of dst */;while( *cp++ = *src++ );;               /* Copy src to end of dst */;return( dst );;};

;Entry:;char *dst - string to which "src" is to be appended;const char *src - string to be appended to the end of "dst";

;Exit:;The address of "dst" in EAX;

;Uses:;EAX, ECX;

;Exceptions:;

;*******************************************************************************page;***;char *strcpy(dst, src) - copy one string over another;

;Purpose:;Copies the string src into the spot specified by;dest; assumes enough room.;

;Algorithm:;char * strcpy (char * dst, char * src);{;char * cp = dst;;

;while( *cp++ = *src++ );;               /* Copy src over dst */;return( dst );;};

;Entry:;char * dst - string over which "src" is to be copied;const char * src - string to be copied over "dst";

;Exit:;The address of "dst" in EAX;

;Uses:;EAX, ECX;

;Exceptions:;*******************************************************************************CODESEG

%       public  strcat, strcpy;make both functions availablestrcpy  proc \dst:ptr byte, \src:ptr byte

OPTIONPROLOGUE:NONE,EPILOGUE:NONEpushedi;preserve edimovedi,[esp+8];edi points to dest stringjmpshort copy_start

strcpy  endp

align16strcat  proc \dst:ptr byte, \src:ptr byte

OPTIONPROLOGUE:NONE,EPILOGUE:NONE

.FPO    (0,2,0,0,0,0)movecx,[esp+4];ecx -> dest stringpushedi;preserve editestecx,3;test if string is aligned on 32 bitsjeshort find_end_of_dest_string_loopdest_misaligned:;simple byte loop until string is alignedmoval,byte ptr [ecx]addecx,1testal,aljeshort start_byte_3testecx,3jneshort dest_misaligned

align4find_end_of_dest_string_loop:moveax,dword ptr [ecx];read 4 bytesmovedx,7efefeffhaddedx,eaxxoreax,-1xoreax,edxaddecx,4testeax,81010100hjeshort find_end_of_dest_string_loop;found zero byte in the loopmoveax,[ecx -4]testal,al;is it byte 0jeshort start_byte_0testah,ah;is it byte 1jeshort start_byte_1testeax,00ff0000h;is it byte 2jeshort start_byte_2testeax,0ff000000h;is it byte 3jeshort start_byte_3jmpshort find_end_of_dest_string_loop;taken if bits 24-30 are clear and bit;31 is setstart_byte_3:leaedi,[ecx -1]jmpshort copy_startstart_byte_2:leaedi,[ecx -2]jmpshort copy_startstart_byte_1:leaedi,[ecx -3]jmpshort copy_startstart_byte_0:leaedi,[ecx -4];jmp     short copy_start;edi points to the end of dest string.copy_start::movecx,[esp+0ch];ecx -> sorc stringtestecx,3;test if string is aligned on 32 bitsjeshort main_loop_entrancesrc_misaligned:;simple byte loop until string is alignedmovdl,byte ptr [ecx]addecx,1testdl,dljeshort byte_0mov[edi],dladdedi,1testecx,3jneshort src_misalignedjmpshort main_loop_entrancemain_loop:;edx contains first dword of sorc stringmov[edi],edx;store one more dwordaddedi,4;kick dest pointermain_loop_entrance:movedx,7efefeffhmoveax,dword ptr [ecx];read 4 bytesaddedx,eaxxoreax,-1xoreax,edxmovedx,[ecx];it's in cache nowaddecx,4;kick dest pointertesteax,81010100hjeshort main_loop;found zero byte in the loop;main_loop_end:testdl,dl;is it byte 0jeshort byte_0testdh,dh;is it byte 1jeshort byte_1testedx,00ff0000h;is it byte 2jeshort byte_2testedx,0ff000000h;is it byte 3jeshort byte_3jmpshort main_loop;taken if bits 24-30 are clear and bit;31 is setbyte_3:mov[edi],edxmoveax,[esp+8];return in eax pointer to dest stringpopediretbyte_2:mov[edi],dxmoveax,[esp+8];return in eax pointer to dest stringmovbyte ptr [edi+2],0popediretbyte_1:mov[edi],dxmoveax,[esp+8];return in eax pointer to dest stringpopediretbyte_0:mov[edi],dlmoveax,[esp+8];return in eax pointer to dest stringpopediretstrcat  endp

end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值