Question: convert following C program to x86 intel assembly code manually(do not use compiler) #include #include #include int editDist(char* word1, char* word2); int min(int a, int
convert following C program to x86 intel assembly code manually(do not use compiler)
#include
#include
#include
int editDist(char* word1, char* word2);
int min(int a, int b);
void swap(int** a, int** b);
int min(int a, int b){
return a < b ? a:b;
}
void swap(int** a, int** b){
int* temp = *a;
*a = *b;
*b = temp;
}
int editDist(char* word1, char* word2){
int word1_len = strlen(word1);
int word2_len = strlen(word2);
int* oldDist = (int*)malloc((word2_len + 1) * sizeof(int));
int* curDist = (int*)malloc((word2_len + 1) * sizeof(int));
int i,j,dist;
//intialize distances to length of the substrings
for(i = 0; i < word2_len + 1; i++){
oldDist[i] = i;
curDist[i] = i;
}
for(i = 1; i < word1_len + 1; i++){
curDist[0] = i;
for(j = 1; j < word2_len + 1; j++){
if(word1[i-1] == word2[j-1]){
curDist[j] = oldDist[j - 1];
}//the characters in the words are the same
else{
curDist[j] = min(min(oldDist[j], //deletion
curDist[j-1]), //insertion
oldDist[j-1]) + 1; //subtitution
}
}//for each character in the second word
swap(&oldDist, &curDist);
}//for each character in the first word
dist = oldDist[word2_len];//using oldDist instead of curDist because of the last swap
free(oldDist);
free(curDist);
return dist;
}
int main(int argc, char** argv){
if(argc < 3){
printf("Usage: %s word1 word 2 ", argv[0]);
exit(1);
}
printf("The distance between %s and %s is %d. ", argv[1], argv[2], editDist(argv[1], argv[2]));
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
