Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes between Version 6 and Version 7 of FindingFirstLetterWithAsmExample

Show
Ignore:
Author:
Andrej08 (IP: 78.2.39.16)
Timestamp:
09/07/10 02:36:48 (11 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FindingFirstLetterWithAsmExample

    v6 v7  
    1010 
    1111== Example == 
    12 === D1.x === 
    1312{{{ 
    1413#!d 
    7170} 
    7271}}} 
    73 === D2.x === 
    74  
    75 {{{ 
    76 #!d 
    77 /* 
    78  *  Copyright (C) 2004 by Digital Mars, www.digitalmars.com 
    79  *  Written by Lynn Allan 
    80  *  This software is provided 'as-is' by a rusty asm-486 programmer. 
    81  *  Released to public domain. 
    82  * 
    83  * Compile with: dmd test.d (uses dmd ver 2.046) 
    84  */ 
    85  
    86 import std.stdio; 
    87 import std.string; 
    88  
    89 void main () 
    90 { 
    91   string searchString = "The quick brown fox jumped over the lazy dog."; 
    92   //                     00000000001111111111222222222233333333334444 
    93   //                     01234567890123456789012345678901234567890123 
    94   immutable(char)* pss = &searchString[0]; // searchString[0]; 
    95   uint foundOffset = indexOf(searchString, 'z'); 
    96   uint zCode = 'z'; 
    97   uint len = searchString.length; 
    98   writefln("z found at: %s", foundOffset); 
    99   uint xCode = 'x'; 
    100   foundOffset = indexOf(searchString, 'x'); 
    101   len = searchString.length; 
    102   writefln("x found at: %s", foundOffset); 
    103  
    104   asm { 
    105     cld; 
    106     mov   ECX,len; 
    107     mov   EAX,zCode; 
    108     mov   EDI,pss; 
    109     repne; 
    110     scasb; 
    111     mov   EBX,len; 
    112     sub   EBX,ECX; 
    113     dec   EBX; 
    114     mov   foundOffset,EBX; 
    115   } 
    116   writefln("z found at: %s", foundOffset); 
    117   assert(foundOffset==38); 
    118  
    119   asm { 
    120     cld; 
    121     mov   ECX,len; 
    122     mov   EAX,xCode; 
    123     mov   EDI,pss; 
    124     repne; 
    125     scasb; 
    126     mov   EBX,len; 
    127     sub   EBX,ECX; 
    128     dec   EBX; 
    129     mov   foundOffset,EBX; 
    130   } 
    131   writefln("x found at: %s", foundOffset); 
    132   assert(foundOffset==18); 
    133 } 
    134 }}}