CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
【经验总结】不能实施并行处理的情况 浅谈并行编程中的任务分解模式
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

求strcmp()的源码

楼主iforem(在咖啡香中醒来)2002-05-09 19:58:49 在 C/C++ / C语言 提问

 
      谢谢 问题点数:20、回复次数:9Top

1 楼iforem(在咖啡香中醒来)回复于 2002-05-09 20:17:13 得分 0

有人知道吗?Top

2 楼cui(蚊子王)回复于 2002-05-09 20:19:45 得分 5

自己写一个不就是了啊:  
  int   strcmp(const   char   *s1,   const   char*s2)  
  {  
      char*   p1;  
      char*   p2;  
      p1=s1;  
      p2=s2;  
      while((*p1)&&(*p2)){  
          if(*p1==*p2)  
          {  
              p1++;p2++  
          }else  
          {  
              return   (*p1-*p2)  
          }  
      }  
      return   (*p1-*p2);  
  }Top

3 楼cui(蚊子王)回复于 2002-05-09 20:21:05 得分 5

少了分号,改正:  
  int   strcmp(const   char   *s1,   const   char*s2)  
  {  
      char*   p1;  
      char*   p2;  
      p1=s1;  
      p2=s2;  
      while((*p1)&&(*p2))  
      {  
          if(*p1==*p2)  
          {  
              p1++;p2++;  
          }else{  
              return   (*p1-*p2);  
          }  
      }  
      return   (*p1-*p2);  
  }  
  Top

4 楼xbeggar(beggar)回复于 2002-05-09 20:33:58 得分 5

看库文件中的就是了,或者自己写一个:  
   
  int   strcmp(const   char   *s1,   const   char*s2)  
  {  
      for(;*s1++==*s2++;)  
      if   (*s1=='\0')  
      break;  
      return   (*s1-*s2);  
  }  
  Top

5 楼davidlxm(davidlxm)回复于 2002-05-10 04:45:49 得分 0

真正strcmp是用汇编写的,如果真想要他的源代码,直接跟踪到strcmp里面,连注解都有:),你就能得到了。Top

6 楼cui(蚊子王)回复于 2002-05-10 08:23:47 得分 0

用汇编,事实上也容易的,不过要分16位和32位来说了。Top

7 楼fangrk(加把油,伙计!)回复于 2002-05-10 08:27:45 得分 0

cui(蚊子王)的代码,p1,p2都应该声明为constTop

8 楼cwanter(亚玛逊河上的渔夫)回复于 2002-05-10 08:41:33 得分 5

以下为strcmp.asm   的内容:  
                  page         ,132  
                  title       strcmp.asm   -   compare   two   strings  
  ;***  
  ;strcmp.asm   -   routine   to   compare   two   strings   (for   equal,   less,   or   greater)  
  ;  
  ;               Copyright   (c)   1985-1997,   Microsoft   Corporation.   All   rights   reserved.  
  ;  
  ;Purpose:  
  ;               STRCMP   compares   two   strings   and   returns   an   integer  
  ;               to   indicate   whether   the   first   is   less   than   the   second,   the   two   are  
  ;               equal,   or   whether   the   first   is   greater   than   the   second,   respectively.  
  ;               Comparison   is   done   byte   by   byte   on   an   UNSIGNED   basis,   which   is   to  
  ;               say   that   Null   (0)   is   less   than   any   other   character   (1-255).  
  ;  
  ;*******************************************************************************  
   
                  .xlist  
                  include   cruntime.inc  
                  .list  
   
  page  
  ;***  
  ;strcmp   -   compare   two   strings,   returning   less   than,   equal   to,   or   greater   than  
  ;  
  ;Purpose:  
  ;               Compares   two   string,   determining   their   lexical   order.     Unsigned  
  ;               comparison   is   used.  
  ;  
  ;               Algorithm:  
  ;                     int   strcmp   (   src   ,   dst   )  
  ;                                     unsigned   char   *src;  
  ;                                     unsigned   char   *dst;  
  ;                     {  
  ;                                     int   ret   =   0   ;  
  ;  
  ;                                     while(   !   (ret   =   *src   -   *dst)   &&   *dst)  
  ;                                                     ++src,   ++dst;  
  ;  
  ;                                     if   (   ret   <   0   )  
  ;                                                     ret   =   -1   ;  
  ;                                     else   if   (   ret   >   0   )  
  ;                                                     ret   =   1   ;  
  ;  
  ;                                     return(   ret   );  
  ;                     }  
  ;  
  ;Entry:  
  ;               const   char   *   src   -   string   for   left-hand   side   of   comparison  
  ;               const   char   *   dst   -   string   for   right-hand   side   of   comparison  
  ;  
  ;Exit:  
  ;               AX   <   0,   0,   or   >0,   indicating   whether   the   first   string   is  
  ;               Less   than,   Equal   to,   or   Greater   than   the   second   string.  
  ;  
  ;Uses:  
  ;               CX,   DX  
  ;  
  ;Exceptions:  
  ;  
  ;*******************************************************************************  
   
                  CODESEG  
   
                  public     strcmp  
  strcmp     proc  
   
                  .FPO         (   0,   2,   0,   0,   0,   0   )  
   
                  mov           edx,[esp   +   4]       ;   edx   =   src  
                  mov           ecx,[esp   +   8]       ;   ecx   =   dst  
   
                  test         edx,3  
                  jnz           short   dopartial  
   
                  align       4  
  dodwords:  
                  mov           eax,[edx]  
   
                  cmp           al,[ecx]  
                  jne           short   donene  
                  or             al,al  
                  jz             short   doneeq  
                  cmp           ah,[ecx   +   1]  
                  jne           short   donene  
                  or             ah,ah  
                  jz             short   doneeq  
   
                  shr           eax,16  
   
                  cmp           al,[ecx   +   2]  
                  jne           short   donene  
                  or             al,al  
                  jz             short   doneeq  
                  cmp           ah,[ecx   +   3]  
                  jne           short   donene  
                  add           ecx,4  
                  add           edx,4  
                  or             ah,ah  
                  jnz           short   dodwords  
   
                  align       4  
  doneeq:  
                  xor           eax,eax  
                  ret  
   
                  align       4  
  donene:  
                  ;   The   instructions   below   should   place   -1   in   eax   if   src   <   dst,  
                  ;   and   1   in   eax   if   src   >   dst.  
   
                  sbb           eax,eax  
                  sal           eax,1  
                  inc           eax  
                  ret  
   
                  align       4  
  dopartial:  
                  test         edx,1  
                  jz             short   doword  
   
                  mov           al,[edx]  
                  inc           edx  
                  cmp           al,[ecx]  
                  jne           short   donene  
                  inc           ecx  
                  or             al,al  
                  jz             short   doneeq  
   
                  test         edx,2  
                  jz             short   dodwords  
   
   
                  align       4  
  doword:  
                  mov           ax,[edx]  
                  add           edx,2  
                  cmp           al,[ecx]  
                  jne           short   donene  
                  or             al,al  
                  jz             short   doneeq  
                  cmp           ah,[ecx   +   1]  
                  jne           short   donene  
                  or             ah,ah  
                  jz             short   doneeq  
                  add           ecx,2  
                  jmp           short   dodwords  
   
  strcmp     endp  
   
                  end  
  其实在C:\Program   Files\Microsoft   Visual   Studio\VC98\CRT\SRC目录下有库函数的源代码。  
  Top

9 楼coolley(☆白雲随风☆)回复于 2002-05-10 19:46:35 得分 0

用汇编怎样看函数原代码呀Top

相关问题

  • &&&&&&&&&&&源码源码,请进...
  • 求Proxy源码
  • Think in java 源码
  • 论坛源码===============》》》》》》》》》》》》》》》》
  • ping源码
  • 源码求教
  • 【源码】FindInvalidChar()
  • 谁有源码
  • 求源码。。。。。
  • gethostbyname的源码

关键词

  • asm
  • strcmp
  • jz short doneeq
  • al
  • dodwords
  • ecx
  • jne short donene
  • ah
  • edx
  • cmp

得分解答快速导航

  • 帖主:iforem
  • cui
  • cui
  • xbeggar
  • cwanter

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
惹火投票。。火热进行中...
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
CSDN网站24小时值班电话:13552009689
Copyright © 2000-2009, CSDN.NET, All Rights Reserved
GongshangLogo