Question: / / Comparison test 1: two equal strings / Load NameAddr / Store CmpStringAddr1 / Load NameAddr / Store CmpStringAddr2 / JnS CmpString / Load

/ / Comparison test 1: two equal strings
/ Load NameAddr / Store CmpStringAddr1 / Load NameAddr / Store CmpStringAddr2 / JnS CmpString / Load CmpStringResult / Output
CmpStringAddr1, HEX 0 / address of first string to compare CmpStringAddr2, HEX 0 / address of second string to compare CmpStringResult, DEC 0 / the result of the comparison (-1: less, 0: equal, 1: greater) CmpString, HEX 0 / the label of the subroutine /
/ 2.4 String comparison (15 points) Now we are going to implement a string comparison subroutine. We will use lexicoaraphic ordering, i.e., the ordering you would use e.g. when sorting names alphabetically. The subroutine takes two (addresses of) strings as arguments and returns -1 if the first string is lexicographically smaller than the second, 0 if they are equal, and 1 if the first string is lexicographically greater than the second string. For example, ABCD is smaller than BCDEF (because the first character is smaller), ABC is smaller than ABCDE (because it is a proper prefix), and BCDF is greater than BCDE (because the first character that is different, the F, is greater The subroutine will communicate the result back to the caller (the code that called JnS in the address with the label CmpStringResult, i.e., after returning from the subroutine. CmpStringResult will be equal to -1 if the first string is smaller, 0 if the strings are equal and 1 if the first string is greater
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
