/************************************************************************/ /* File Name : lc4_memory.c */ /* Purpose : This file implements the linked_list helper functions */ /* to manage the LC4 memory */ /* */ /* Author(s) : tjf and you */ /************************************************************************/ #include #include "lc4_memory.h" /* * adds a new node to a linked list pointed to by head */ int add_to_list (row_of_memory** head, short unsigned int address, short unsigned int contents) { /* check to see if there is already an entry for this address and update the contents. no additional steps required in this case */ /* allocate memory for a single node */ /* populate fields in newly allocated node w/ address&contents, NULL for label and assembly */ /* do not malloc() storage for label and assembly here - do it in parse_file() and reverse_assemble() */ /* if *head is NULL, node created is the new head of the list! */ /* otherwise, insert node into the list in address ascending order */ /* return 0 for success, -1 if malloc fails */ return 0 ; } /* * search linked list by address field, returns node if found */ row_of_memory* search_address (row_of_memory* head, short unsigned int address ) { /* traverse linked list, searching each node for "address" */ /* return pointer to node in the list if item is found */ /* return NULL if list is empty or if "address" isn't found */ return NULL ; } /* * search linked list by opcode field, returns node if found */ row_of_memory* search_opcode (row_of_memory* head, short unsigned int opcode ) { /* opcode parameter is in the least significant 4 bits of the short int and ranges from 0-15 */ /* see assignment instructions for a detailed description */ /* traverse linked list until node is found with matching opcode in the most significant 4 bits AND "assembly" field of node is NULL */ /* return pointer to node in the list if item is found */ /* return NULL if list is empty or if no matching nodes */ return NULL ; } void print_list (row_of_memory* head ) { /* make sure head isn't NULL */ /* print out a header */ /* traverse linked list, print contents of each node */ return ; } /* * delete entire linked list */ int delete_list (row_of_memory** head ) { /* delete entire list node by node */ /* set the list head pointer to NULL upon deletion */ return 0 ; }