CRT源码

CRT的 源码分为3部分:

  1. c C语言

  2. cpp c++

  3. asm 性能优化汇编版本

strcat

1char * __cdecl strcat ( 2        char * dst, 3        const char * src 4        ) 5{ 6        char * cp = dst; 7 8        while( *cp ) 9                cp++;                   /* find end of dst */ 10 11        while( *cp++ = *src++ ) ;       /* Copy src to end of dst */ 12 13        return( dst );                  /* return dst */ 14 15}

strcmp

1int __cdecl strcmp ( 2        const char * src, 3        const char * dst 4        ) 5{ 6        int ret = 0 ; 7 8        while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) 9                ++src, ++dst; 10 11        if ( ret < 0 ) 12                ret = -1 ; 13        else if ( ret > 0 ) 14                ret = 1 ; 15 16        return( ret ); 17}

strcmp  asm 版本

1        page    ,132 2        title   strcmp.asm - compare two strings 3;*** 4;strcmp.asm - routine to compare two strings (for equal, less, or greater) 5; 6;       Copyright (c) Microsoft Corporation. All rights reserved. 7; 8;Purpose: 9;       STRCMP compares two strings and returns an integer 10;       to indicate whether the first is less than the second, the two are 11;       equal, or whether the first is greater than the second, respectively. 12;       Comparison is done byte by byte on an UNSIGNED basis, which is to 13;       say that Null (0) is less than any other character (1-255). 14; 15;******************************************************************************* 16 17        .xlist 18        include cruntime.inc 19        .list 20 21page 22;*** 23;strcmp - compare two strings, returning less than, equal to, or greater than 24; 25;Purpose: 26;       Compares two string, determining their lexical order.  Unsigned 27;       comparison is used. 28; 29;       Base Algorithm: 30;          int strcmp ( const char *str1, const char *str2 ) 31;          { 32;                  const unsigned char *src1 = (const unsigned char *)str1; 33;                  const unsigned char *src2 = (const unsigned char *)str2; 34;                  int ret = 0 ; 35; 36;                  while( ! (ret = *src1 - *src2) && *src2) 37;                          ++src1, ++src2; 38; 39;                  if ( ret < 0 ) 40;                          ret = -1 ; 41;                  else if ( ret > 0 ) 42;                          ret = 1 ; 43; 44;                  return( ret ); 45;          } 46; 47;Entry: 48;       const char * src1 - string for left-hand side of comparison 49;       const char * src2 - string for right-hand side of comparison 50; 51;Exit: 52;       EAX < 0, 0, or >0, indicating whether the first string is 53;       Less than, Equal to, or Greater than the second string. 54; 55;Uses: 56;       ECX, EDX 57; 58;Exceptions: 59; 60;******************************************************************************* 61 62        CODESEG 63 64        public  strcmp 65strcmp  proc \ 66        str1:ptr byte, \ 67        str2:ptr byte 68 69        OPTION PROLOGUE:NONE, EPILOGUE:NONE 70 71;       .FPO (cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame) 72        .FPO    ( 0, 2, 0, 0, 0, 0 ) 73 74        mov     edx,[esp + 4]   ; edx = src 75        mov     ecx,[esp + 8]   ; ecx = dst 76 77        test    edx,3 78        jnz     short dopartial 79 80        align   4 81dodwords: 82        mov     eax,[edx] 83 84        cmp     al,[ecx] 85        jne     short donene 86        test    al,al 87        jz      short doneeq 88        cmp     ah,[ecx + 1] 89        jne     short donene 90        test    ah,ah 91        jz      short doneeq 92 93        shr     eax,16 94 95        cmp     al,[ecx + 2] 96        jne     short donene 97        test    al,al 98        jz      short doneeq 99        cmp     ah,[ecx + 3] 100        jne     short donene 101        add     ecx,4 102        add     edx,4 103        test    ah,ah 104        jnz     short dodwords 105 106        align   4 107doneeq: 108        xor     eax,eax 109        ret 110 111        align   8 112donene: 113        ; The instructions below should place -1 in eax if src < dst, 114        ; and 1 in eax if src > dst. 115 116        sbb     eax,eax 117        or      eax,1 118        ret 119 120        align   16 121dopartial: 122        test    edx,1 123        jz      short doword 124 125        mov     al,[edx] 126        add     edx,1 127        cmp     al,[ecx] 128        jne     short donene 129        add     ecx,1 130        test    al,al 131        jz      short doneeq 132 133        test    edx,2 134        jz      short dodwords 135 136 137        align   4 138doword: 139        mov     ax,[edx] 140        add     edx,2 141        cmp     al,[ecx] 142        jne     short donene 143        test    al,al 144        jz      short doneeq 145        cmp     ah,[ecx + 1] 146        jne     short donene 147        test    ah,ah 148        jz      short doneeq 149        add     ecx,2 150        jmp     short dodwords 151 152strcmp  endp 153 154        end

strlen

1size_t __cdecl strlen ( 2        const char * str 3        ) 4{ 5        const char *eos = str; 6 7        while( *eos++ ) ; 8 9        return( eos - str - 1 ); 10}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )