Homework Assignment 3 CS 340d Unique Number: 50960 Spring, 2019 Given: February 11, 2019 Due: February 20, 2019 This homework assignment involves memory-to-memory copying and using invariants in programs. 1. Consider the following program fragment a specification for copying. char *dst, *src; // Set src and dst pointers *dst++ = *src++; This program fragment copies memory bytes from *src to *dst one byte at a time. Assuming that both *src and *dst are aligned to 8-byte (long word) locations, write a faster copy program (fragment). Can you define an invariant that assures that your faster copy program is functioning properly? Note, in future assignments, we will consider more subtle issues: non-alignment of src memory non-alignment of dst memory size of copy 2. Using C-language code, define an invariant (a predicate) that recognizes a NULL terminated linked list of (C-language long) integers. Use the following structure for a linked-list element: typedef struct node { long val; struct node *next; } node_t; Does your invariant predicate accept a linked list with a loop? 3. Augment the invariant defined in problem 2 (just above) so that the predicate also checks that the ``val'' items in the linked list are ordered by less than. That is, each ``val'' in the linked list should be numerically as large or larger than its previous ``val''. The rest of this homework concerns using the same approach of defining and propagating invariants as the example code for add in the class notes about invariants uses. See the class notes about invariants. 4. Extend (or re-work) the add example from the class notes so that it works for negative `x' and `y' inputs. Remember, you may only use increment (``++'') and decrement (``--'') operations on the data to be added. You will need to include the declaration: #include in your program. 5. Write another program that implements multiplication by repeated addition. In this program, include ``assert'' statements as appropriate. Make sure that your algorithm only uses addition; the use of the ``*'' operator is forbidden in the code. However, the ``*'' operator may be used in assert statements.