I am learning MIPS recently, can someone help me to convert the count vowels C code to MIPS? I could not find the similar count vowels MIPS code from Google or SO.
char myName[9] = "stevecurry";
int main()
{
int low,high;
int vowels;
low=0;
high=6;
vowels=countvowels(low,high); //count the vowels using recursion
return 0;
}
int countvowels(int low, int high)
{
int middle;
int count1,count2,count;
if (low==high) { //only one element
if(isVowel(low))
return 1;
else
return 0;
}
else { //divide and conquer
middle=(low+high)/2;
count1=countvowels(low, middle); //recursive call
count2=countvowels(middle+1, high);
count = count1+count2;
return count; //return sum of two sub-sets
}
}
int isVowel(int low) // whether the indexed character is a vowel
{
if(myName[low]=='a' ||myName[low]=='e' || myName[low]=='i' || myName[low]=='o' ||myName[low]=='u')
return 1;
else
return 0;
}
Comments
Post a Comment