Question: For this programming assignment you will develop three assembly language procedures that will be called from C. The C module is given to you. You

For this programming assignment you will develop three assembly language procedures that will be called from C. The C module is given to you. You will provide the assembly module containing the three procedures.

You will create and use a structure called BookNode that can be used to create a linked list of nodes. The BookNode structure should contain the following fields:

StockNum - A 32-bit integer initialized to zero, sequentially initialized starting at 1001

Title - A string pointer initialized to a constant value of NULL (0)

ISBN10 - A string pointer initialized to a constant value of NULL (0)

Year - A 32-bit integer containing the year, uninitialized

Month - A 32-bit integer containing the month, uninitialized

Day - A 32-bit integer containing the day, uninitialized

NextPtr - A pointer to the next node initialized to a constant value of NULL (0)

The following shows an equivalent C structure:

struct BookNode {  int stockNum;  char* bookTitle;  char *isbn10;  int year;  int month;  int day;  struct BookNode* nextPtr; }; 
 

Your assembly version of the structure should be compatible with the above such that te member variables can be accessed either from C or assembly.

Use a REPEAT block to create 30 BookNode structures in memory in your assembly module. This should go into the .data section of the module.

The C prototype for the first assembly procedure is shown below.

int newBook(int stockNum, char* title, char* isbn, int year, int month, int day);

newBook will find the node in the list with the given stock number, then set the member values to those values that were passed to the procedure.

The newBook procedure should use a macro called mNewBook that sets the associated values for the node corresponding to the designated stock number. mNewBook should perform the search for the node containing the designated stock number, then set the members accordingly.

Use conditional-assembly directives within the mNewBook macro to verify that none of the parameters are blank.

The newBook procedure should return a -1 if the node could not be found and 0 if it was successfully found.

The C prototype for the second procedure is shown below.

struct BookNode* getBook(int stockNum);

getBook will return a pointer to the node containing the stock number. The getBook procedure should return NULL (0) if the node could not be found.

Create a macro called mGetBook that finds the node with the designated stock number and returns a pointer to the node needed for the procedure.

The C prototype for the third procedure is shown below.

int deleteBook(int stockNum);

The deleteBook procedure should remove the node containing the stock number from the list. Of course the deleted node cannot be removed from memory since that was defined in static memory (the data segment). The removal can be done by setting the pointer for the previous node to point to the node following the one being deleted. A macro called mDeleteBook should be invoked to do the work of removing the node from the linked list. C code that removes an item looks something like the following:

// prev and current are pointers to nodes prev = current; current = current->next; prev->next = current->next; 
You may not use the Microsoft directives PROTO and INVOKE for this assignment. 

#include

// The matching C version of the structure struct BookNode { int stockNum; char* bookTitle; char *isbn10; int year; int month; int day; struct BookNode* nextPtr; };

// C prototypes for the functions written in assembly language // newBook will cause new information to be added to the linked list for the node having the specified stockNum int newBook(int stockNum, char* title, char* isbn, int year, int month, int day); // getBook will find the node having the specified stock number and return a pointer to it struct BookNode* getBook(int stockNum); // deleteBook will delete the node having the specified stock number from the linked list int deleteBook(int stockNum);

// Main ------------------------------------------------------------------- int main() { int ret; struct BookNode* bookNodePtr;

// Add a book to the linked list ret = newBook(1005, "Assembly Language for x86 Processors (7th Edition)", "0133769402", 2017, 5, 8); if (ret < 0) { printf("Could not add the new book for stock number %d ", 1005); return -1; }

// Now get a pointer to the node bookNodePtr = getBook(1005);

// Exit if the node was not found if (bookNodePtr == NULL) { printf("Could not find the book for stock number %d ", 1005); return -1; }

// Show the member values printf("Book title: %s ", bookNodePtr->bookTitle); printf("ISBN: %s ", bookNodePtr->isbn10); printf("Date: %d/%d/%d ", bookNodePtr->month, bookNodePtr->day, bookNodePtr->year);

// Delete the book we added ret = deleteBook(1005); if (ret < 0) { printf("Could not delete the book for stock number %d ", 1005); return -1; }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!