MaximuS I post too much
Reputation: 3
Joined: 05 Apr 2007 Posts: 3212 Location: ......
|
Posted: Thu Mar 26, 2015 1:12 am Post subject: Assembly creating functions |
|
|
I need to make functions for these problems. I'm a little lost on this section. Please can you help me writing the code and understanding it as well?
a) Write a function, labelHash(), that will verify if a given string is a valid label, and if it is, create a hash from the label name. The hash is created by adding each of the ASCII values for the characters (thus treating the characters as a series of byte integers). For this question, a valid label must start with a letter (upper or lower case), followed by letters (upper or lower case) or numbers (no special symbols), and ending with with a “:” (and no characters after the “:”). The total length (including the “:”) must be ≤ to 255 characters. The function should return the label status (TRUE for valid, and FALSE for invalid). You may assume TRUE and FALSE are already declared as constants. In addition, the function should return (via arguments) the hash value, label length (including the “:”), letter count ('a'-'z', 'A'-'Z') and digit count ('0'-'9'). The hash value is calculated by adding each of the ASCII characters. An example call of the function as follows:
status = labelHash(lblStr, hashValue, lblLen, ltrCnt, digitCnt);
Where lblStr is the address of a NULL terminated string, and hashValue, lblLen, ltrCnt, and digitCnt are addresses for the double-word sized counts. Do not assume the count variables have been initialized to zero. Your procedure must use the standard calling convention. Note, points will be deducted for poor or inefficient solutions.
b) Write a function, printLabel(), that will read a string from a file and determine if the string is a valid label. If the string is not valid, NOSUCCESS should be return to the calling routine. If the string is valid, the string should be displayed to the console, the string (NULL terminated) and string length should be returned via call-by-reference, and SUCCESS returned to the calling routine. The function must open the file, determine if the string is valid by calling the function from the previous question, return the appropriate results, and close the file. If the file can’t be opened or read, or the string is not valid, display an “label error” to the console and return NOSUCCESS. You may assume the standard constants are already defined. An example call for the function as follows:
status = printLabel(fileName, lblStr, lblLen);
Where fileName is the address of the NULL terminated file name string, lblStr is the address of where to store the NULL terminated label string, and lblLen is the address of where to store the string length (double-word). Your function must use the standard calling convention. Show additional data declarations (if any). You may use the printString() function without writting it. Note, points will be deducted for poor or inefficient solutions.
|
|