/* Implement the following specified functions adhering to the * C/assembly-interface conventions. */ /* In: table - table of short (2 bytes) numbers * n - number of entries in table * Out: maximum value that occurs in table * If n == 0, the return value is undefined (it can be anything). * * Difficulty: easy */ short max(short * table, unsigned short n); /* In: source - table of BCD values in bytes * (so only lower nibble of each byte is used) * dest - table of bytes, half the length of source * n - number of entries in source * Out: -1 - if n is odd * 0 - otherwise (success) * Compresses a table of BCD numbers (one BCD number per byte with * upper nibble all 0s) into a table of two BCD numbers per byte. * * Difficulty: medium * * Bonus exercise: implement compress so that it works for odd n as * well. */ short compress(char * source, char * dest, unsigned short n); /* In: table - table of unsigned short (2 bytes) numbers * n - number of entries in table * rv - pointer to where mean should be written * Out: -1 - if an error occurs (e.g., overflow) or n == 0 * 0 - success * Computes the floor of the mean of a table of short values and * writes it to the address specified in rv. For example, the * floor_mean of the table { 1, 5, 4 } is (1 + 5 + 4) / 3 = 3 (the * mean is 3.333..., and its floor is 3, so the floor_mean is 3). * * Difficulty: medium */ short floor_mean(unsigned short * table, unsigned short n, short * rv); /* In: table - table of unsigned short (2 bytes) numbers * delta - output table of signed shorts * n - number of entries in table and delta * Out: -1 - if an error occurs * 0 - success * Upon return, delta contains for each corresponding entry in table, * the difference between that entry and the floor_mean of table. For * example, if table[] = { 1, 5, 3 }, then upon return, delta = { -2, * 2, 0 } since floor_mean of table is 3, and { 1 - 3 = -2, 5 - 3 = * -2, 3 - 3 = 0 }. * * Difficulty: hard */ short delta(unsigned short * table, short * delta, unsigned short n);