My omnium-gatherom of scripts and source code.
at main 50 lines 899 B view raw
1/* 2 * Architecture Lab: Part A 3 * 4 * High level specs for the functions that the students will rewrite 5 * in Y86-64 assembly language 6 */ 7 8/* $begin examples */ 9/* linked list element */ 10typedef struct ELE { 11 long val; 12 struct ELE *next; 13} *list_ptr; 14 15/* sum_list - Sum the elements of a linked list */ 16long sum_list(list_ptr ls) 17{ 18 long val = 0; 19 while (ls) { 20 val += ls->val; 21 ls = ls->next; 22 } 23 return val; 24} 25 26/* rsum_list - Recursive version of sum_list */ 27long rsum_list(list_ptr ls) 28{ 29 if (!ls) 30 return 0; 31 else { 32 long val = ls->val; 33 long rest = rsum_list(ls->next); 34 return val + rest; 35 } 36} 37 38/* copy_block - Copy src to dest and return xor checksum of src */ 39long copy_block(long *src, long *dest, long len) 40{ 41 long result = 0; 42 while (len > 0) { 43 long val = *src++; 44 *dest++ = val; 45 result ^= val; 46 len--; 47 } 48 return result; 49} 50/* $end examples */