Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   help with my programming assignment (http://www.go4expert.com/forums/help-programming-assignment-t10392/)

dave321 5May2008 10:00

help with my programming assignment
 
I am having some trouble with my programming assignment. I can show you my code and how far I have gotten (and my logic). My assignment is to use inline assembly and mmx to compare two strings that are the same length and output a string that has the lower ascii values of the two strings. ex) Hello vs HelLO. It needs to look at each index of both of the strings, compare the ascii value, put the lower ascii value into a new string, and look at the next character of the string. The problem I am having is that I do not know how to look at the second letter of each of the string. (Right now I am getting a segmentation fault) I can show you my code here:
Code:

#include <stdio.h>
#include <string.h>
void lowerascii(char *str1, char *str2, char *returnstring)
{
  //find the size of the string
  int stringsize = -1;
  int sizecounter = 100;
 
  printf("The entered string is: %s\n", str1);
  printf("The entered string is: %s\n", str2);
  __asm__(
  "movl $100, %%ecx\n\t"  //used as a counter to find the string size
  "movl %1, %%edi\n\t"
  "movl $0, %%eax\n\t"
  "repne scasb\n\t"
  "cld\n\t"
  "subl %3, %%ecx\n\t"
  "not %%ecx\n\t"
  "movl %%ecx, %0\n\t"
  :"=r" (stringsize)
  :"r" (str1), "r" (str2), "b" (sizecounter)
  );
  printf("The length of the lists are: %i\n", stringsize);
 
  int result1 = 0;
  int result2 = 0;
  //int result3 = 0;
  //get new string
  __asm__(
 
  "movq (%1), %%mm0\n\t"
  "movq (%1), %%mm1\n\t"
  "movq (%1), %%mm2\n\t"
  "movq (%1), %%mm3\n\t"
  "movq (%2), %%mm4\n\t"
  "movq (%2), %%mm5\n\t"
  "movq (%2), %%mm6\n\t"
  "movq (%2), %%mm7\n\t"
 
  "begin:\n\t"
  "cmpl $0, %%eax\n\t"
  "je end\n\t"
  //comparions for the string
  "pcmpeqb %%mm0, %%mm4\n\t"
  "movd %%mm4, %%ebx\n\t"
  "pand %%mm0, %%mm4\n\t"
  "cmpl $0, %%ebx\n\t"
  "jne addtostring1\n\t"
 
  "pcmpgtb %%mm0, %%mm5\n\t"
  "movd %%mm5, %%ebx\n\t"
  "pand %%mm0, %%mm5\n\t"
  "cmpl $0, %%ebx\n\t"
  "jne addtostring2\n\t"
 
  "pcmpgtb %%mm6, %%mm0\n\t"
  "movd %%mm6, %%ebx\n\t"
  "pand %%mm6, %%mm0\n\t"
  "cmpl $0, %%ebx\n\t"
  "jne addtostring3\n\t"
 
  //add to the new string
  "addtostring1:\n\t"
  "movq %%mm4, (%0)\n\t"
  "dec %%eax\n\t"
  "jmp begin\n\t"
 
  "addtostring2:\n\t"
  "movq %%mm5, (%0)\n\t"
  "dec %%eax\n\t"
  "jmp begin\n\t"
 
  "addtostring3:\n\t"
  "movq %%mm0, (%0)\n\t"
  "dec %%eax\n\t"
  "jmp begin\n\t"
 
  "end:\n\t"
  :"=r" (returnstring)
  :"r" (str1), "r" (str2), "a" (stringsize)
  //"emms\n\t"
  );
  printf("The new string is: %s\n", returnstring);
  printf("\n");
}
 
#include <stdio.h>
#include <string.h>
void lowerascii(char *str1, char *str2, char *returnstring);
int main()
{
  //char string1[50] = "HellO";
  //char string2[50] = "hElLO";
  //char newstring[50];
  char string1[100] = "HellO";
  char string2[100] = "HElLo";
  char newstring[100]= "aaaaa";
  lowerascii(string1, string2, newstring);
  //printf("The newstring is: ");
  //printf("%s\n",newstring);
  return 0;
}

(website for it is http://slexy.org/view/s20sDkV56R if that works..)
So my first file is the mmx code where I found the size of the string (first part of project) now I am trying to use mmx to get a new string. My logic is to put the strings into the mm registers and compare them. the first comparision is the equal one, so if they are the same character then mm4 will contain all 1's. I then do a padd mm0 with mm4 so that mm4 will have the right ascii value of the character. I jump to addtonewstring and there it is suppose to place the letter into the new string. After that I decrement the size of the string and jump back up to begin. At begin I check to see if the size of equal to zero, if it is then I know I am done, if not then I need to check the next index of the 2 strings and the program will jump to just one of the addtostring. My problem is I get a segmentation fault and do not see why. Also I am not so sure how the program is suppose to get the next index of the two strings. Could anyone please help me I would really appreciate it.
Thank you!!


All times are GMT +5.5. The time now is 13:12.