Author: Anonymous Language: text
Description: No description Timestamp: 2008-05-05 00:25:50 -0400
View raw paste Reply
  1. #include <stdio.h>
  2. #include <string.h>
  3. void lowerascii(char *str1, char *str2, char *returnstring)
  4. {
  5.   //find the size of the string
  6.   int stringsize = -1;
  7.   int sizecounter = 100;
  8.  
  9.   printf("The entered string is: %s\n", str1);
  10.   printf("The entered string is: %s\n", str2);
  11.   __asm__(
  12.   "movl $100, %%ecx\n\t"  //used as a counter to find the string size
  13.   "movl %1, %%edi\n\t"
  14.   "movl $0, %%eax\n\t"
  15.   "repne scasb\n\t"
  16.   "cld\n\t"
  17.   "subl %3, %%ecx\n\t"
  18.   "not %%ecx\n\t"
  19.   "movl %%ecx, %0\n\t"
  20.   :"=r" (stringsize)
  21.   :"r" (str1), "r" (str2), "b" (sizecounter)
  22.   );
  23.   printf("The length of the lists are: %i\n", stringsize);
  24.  
  25.   int result1 = 0;
  26.   int result2 = 0;
  27.   //int result3 = 0;
  28.   //get new string
  29.   __asm__(
  30.  
  31.   "movq (%1), %%mm0\n\t"
  32.   "movq (%1), %%mm1\n\t"
  33.   "movq (%1), %%mm2\n\t"
  34.   "movq (%1), %%mm3\n\t"
  35.   "movq (%2), %%mm4\n\t"
  36.   "movq (%2), %%mm5\n\t"
  37.   "movq (%2), %%mm6\n\t"
  38.   "movq (%2), %%mm7\n\t"
  39.  
  40.   "begin:\n\t"
  41.   "cmpl $0, %%eax\n\t"
  42.   "je end\n\t"
  43.   //comparions for the string
  44.   "pcmpeqb %%mm0, %%mm4\n\t"
  45.   "movd %%mm4, %%ebx\n\t"
  46.   "pand %%mm0, %%mm4\n\t"
  47.   "cmpl $0, %%ebx\n\t"
  48.   "jne addtostring1\n\t"
  49.  
  50.   "pcmpgtb %%mm0, %%mm5\n\t"
  51.   "movd %%mm5, %%ebx\n\t"
  52.   "pand %%mm0, %%mm5\n\t"
  53.   "cmpl $0, %%ebx\n\t"
  54.   "jne addtostring2\n\t"
  55.  
  56.   "pcmpgtb %%mm6, %%mm0\n\t"
  57.   "movd %%mm6, %%ebx\n\t"
  58.   "pand %%mm6, %%mm0\n\t"
  59.   "cmpl $0, %%ebx\n\t"
  60.   "jne addtostring3\n\t"
  61.  
  62.   //add to the new string
  63.   "addtostring1:\n\t"
  64.   "movq %%mm4, (%0)\n\t"
  65.   "dec %%eax\n\t"
  66.   "jmp begin\n\t"
  67.  
  68.   "addtostring2:\n\t"
  69.   "movq %%mm5, (%0)\n\t"
  70.   "dec %%eax\n\t"
  71.   "jmp begin\n\t"
  72.  
  73.   "addtostring3:\n\t"
  74.   "movq %%mm0, (%0)\n\t"
  75.   "dec %%eax\n\t"
  76.   "jmp begin\n\t"
  77.  
  78.   "end:\n\t"
  79.   :"=r" (returnstring)
  80.   :"r" (str1), "r" (str2), "a" (stringsize)
  81.   //"emms\n\t"
  82.   );
  83.   printf("The new string is: %s\n", returnstring);
  84.   printf("\n");
  85. }
  86.  
  87. #include <stdio.h>
  88. #include <string.h>
  89. void lowerascii(char *str1, char *str2, char *returnstring);
  90. int main()
  91. {
  92.   //char string1[50] = "HellO";
  93.   //char string2[50] = "hElLO";
  94.   //char newstring[50];
  95.   char string1[100] = "HellO";
  96.   char string2[100] = "HElLo";
  97.   char newstring[100]= "aaaaa";
  98.   lowerascii(string1, string2, newstring);
  99.   //printf("The newstring is: ");
  100.   //printf("%s\n",newstring);
  101.   return 0;
  102. }
  103.  
  104.  
View raw paste Reply