Question: Note: Use comments. Also do not use code that is already published online in sites such as quora, stackoverflow, etc.. Write an assembly program called

Note: Use comments. Also do not use code that is already published online in sites such as quora, stackoverflow, etc..

Write an assembly program called editDist.s that calculates the edit distance between 2 strings. An explanation of what edit distance is can be found here while accompanying pseudo code can be found here.

1. The label for the first string should be string1 and the label for the second string should be string2.

2. The edit distance between string1 and string2 should be placed in EAX.

3. For each string please allocate space for 100 bytes.

1. While you must allocate space for 100 bytes in your final submission you will likely find it easier to work with the .string directive for testing and debugging.

4. AFTER the last line of code that you wish to be executed in your program please place the label done.

1. Make sure that there is an instruction after the done line and a new line after that instruction. If you don't your output won't match mine.

5. I have included a C implementation of the edit distance program. I highly recommend translating this solution into assembly as it will make your life much easier.

6. I have included a Makefile that will compile your program. Your program must be able to be compiled by this Makefile when you submit it

7. IT IS OF VITAL IMPORTANCE THAT YOU NAME YOUR LABELS AS SPECIFIED AND MAKE THE APPROPRIATE AMOUNT OF SPACE FOR EACH VARIABLE! I will be using gdb to test your code and if your labels do not match then the tests will fail. You must also make sure to include the done label AFTER the last line of code you want executed in your program so that I know where to set break points.

The following is the c code for it:

#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 thelast 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!